mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-28 01:20:55 +01:00
SelectableEx - replaced unnecessary extra size_draw parameter by a flag.
This commit is contained in:
parent
96496ced5f
commit
2bcafc861e
23
imgui.cpp
23
imgui.cpp
@ -988,9 +988,10 @@ enum ImGuiButtonFlags_
|
||||
|
||||
enum ImGuiSelectableFlags_
|
||||
{
|
||||
ImGuiSelectableFlags_MenuItem = (1 << 0),
|
||||
ImGuiSelectableFlags_DontClosePopups = (1 << 1),
|
||||
ImGuiSelectableFlags_Disabled = (1 << 2)
|
||||
ImGuiSelectableFlags_MenuItem = (1 << 0),
|
||||
ImGuiSelectableFlags_DontClosePopups = (1 << 1),
|
||||
ImGuiSelectableFlags_Disabled = (1 << 2),
|
||||
ImGuiSelectableFlags_DrawFillAvailWidth = (1 << 3)
|
||||
};
|
||||
|
||||
|
||||
@ -7406,7 +7407,7 @@ bool ImGui::Combo(const char* label, int* current_item, bool (*items_getter)(voi
|
||||
return value_changed;
|
||||
}
|
||||
|
||||
static bool SelectableEx(const char* label, bool selected, const ImVec2& size_arg, const ImVec2 size_draw_arg, ImGuiSelectableFlags flags)
|
||||
static bool SelectableEx(const char* label, bool selected, const ImVec2& size_arg, ImGuiSelectableFlags flags)
|
||||
{
|
||||
ImGuiState& g = *GImGui;
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
@ -7425,9 +7426,9 @@ static bool SelectableEx(const char* label, bool selected, const ImVec2& size_ar
|
||||
// Fill horizontal space.
|
||||
ImVec2 window_padding = window->WindowPadding();
|
||||
float w_draw = ImMax(label_size.x, window->Pos.x + ImGui::GetContentRegionMax().x - window_padding.x - window->DC.CursorPos.x);
|
||||
ImVec2 size_draw(size_draw_arg.x != 0.0f ? size_draw_arg.x : w_draw, size_draw_arg.y != 0.0f ? size_draw_arg.y : size.y);
|
||||
ImVec2 size_draw((size_arg.x != 0 && !(flags & ImGuiSelectableFlags_DrawFillAvailWidth)) ? size_arg.x : w_draw, size_arg.y != 0.0f ? size_arg.y : size.y);
|
||||
ImRect bb_with_spacing(pos, pos + size_draw);
|
||||
if (size_draw_arg.x == 0.0f)
|
||||
if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_DrawFillAvailWidth))
|
||||
bb_with_spacing.Max.x += window_padding.x;
|
||||
|
||||
// Selectables are tightly packed together, we extend the box to cover spacing between selectable.
|
||||
@ -7467,12 +7468,12 @@ static bool SelectableEx(const char* label, bool selected, const ImVec2& size_ar
|
||||
// But you need to make sure the ID is unique, e.g. enclose calls in PushID/PopID.
|
||||
bool ImGui::Selectable(const char* label, bool selected, const ImVec2& size_arg)
|
||||
{
|
||||
return SelectableEx(label, selected, size_arg, size_arg, 0);
|
||||
return SelectableEx(label, selected, size_arg, 0);
|
||||
}
|
||||
|
||||
bool ImGui::Selectable(const char* label, bool* p_selected, const ImVec2& size_arg)
|
||||
{
|
||||
if (SelectableEx(label, *p_selected, size_arg, size_arg, 0))
|
||||
if (SelectableEx(label, *p_selected, size_arg, 0))
|
||||
{
|
||||
*p_selected = !*p_selected;
|
||||
return true;
|
||||
@ -7588,7 +7589,7 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo
|
||||
float w = window->MenuColumns.DeclColumns(label_size.x, shortcut_size.x, (float)(int)(g.FontSize * 1.20f)); // Feedback for next frame
|
||||
float extra_w = ImMax(0.0f, window->Pos.x + ImGui::GetContentRegionMax().x - pos.x - w);
|
||||
|
||||
bool pressed = SelectableEx(label, false, ImVec2(w, 0.0f), ImVec2(0.0f, 0.0f), ImGuiSelectableFlags_MenuItem | (!enabled ? ImGuiSelectableFlags_Disabled : 0));
|
||||
bool pressed = SelectableEx(label, false, ImVec2(w, 0.0f), ImGuiSelectableFlags_MenuItem | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0));
|
||||
if (shortcut_size.x > 0.0f)
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
|
||||
@ -7701,7 +7702,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
||||
window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing * 2.0f);
|
||||
float w = label_size.x;
|
||||
pressed = SelectableEx(label, opened, ImVec2(w, 0.0f), ImVec2(w, 0.0f), ImGuiSelectableFlags_MenuItem | ImGuiSelectableFlags_DontClosePopups | (!enabled ? ImGuiSelectableFlags_Disabled : 0));
|
||||
pressed = SelectableEx(label, opened, ImVec2(w, 0.0f), ImGuiSelectableFlags_MenuItem | ImGuiSelectableFlags_DontClosePopups | (!enabled ? ImGuiSelectableFlags_Disabled : 0));
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::SameLine();
|
||||
window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f);
|
||||
@ -7711,7 +7712,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
||||
popup_pos = ImVec2(pos.x, pos.y - style.WindowPadding.y);
|
||||
float w = window->MenuColumns.DeclColumns(label_size.x, 0.0f, (float)(int)(g.FontSize * 1.20f)); // Feedback to next frame
|
||||
float extra_w = ImMax(0.0f, window->Pos.x + ImGui::GetContentRegionMax().x - pos.x - w);
|
||||
pressed = SelectableEx(label, opened, ImVec2(w, 0.0f), ImVec2(0.0f, 0.0f), ImGuiSelectableFlags_MenuItem | ImGuiSelectableFlags_DontClosePopups | (!enabled ? ImGuiSelectableFlags_Disabled : 0));
|
||||
pressed = SelectableEx(label, opened, ImVec2(w, 0.0f), ImGuiSelectableFlags_MenuItem | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0));
|
||||
if (!enabled) ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
|
||||
RenderCollapseTriangle(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * 0.20f, 0.0f), false);
|
||||
if (!enabled) ImGui::PopStyleColor();
|
||||
|
Loading…
Reference in New Issue
Block a user