mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-24 07:40:22 +01:00
Menus: added internal's BeginMenuEx() matching MenuItemEx() with icon parameter. (amend f8fae022
)
This commit is contained in:
parent
4aea1c5adb
commit
7c4ffe490d
@ -2442,6 +2442,7 @@ namespace ImGui
|
||||
IMGUI_API bool BeginViewportSideBar(const char* name, ImGuiViewport* viewport, ImGuiDir dir, float size, ImGuiWindowFlags window_flags);
|
||||
|
||||
// Menus
|
||||
IMGUI_API bool BeginMenuEx(const char* label, const char* icon, bool enabled = true);
|
||||
IMGUI_API bool MenuItemEx(const char* label, const char* icon, const char* shortcut = NULL, bool selected = false, bool enabled = true);
|
||||
|
||||
// Combos
|
||||
|
@ -6789,7 +6789,7 @@ void ImGui::EndMainMenuBar()
|
||||
End();
|
||||
}
|
||||
|
||||
bool ImGui::BeginMenu(const char* label, bool enabled)
|
||||
bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
@ -6856,13 +6856,15 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
||||
// (In a typical menu window where all items are BeginMenu() or MenuItem() calls, extra_w will always be 0.0f.
|
||||
// Only when they are other items sticking out we're going to add spacing, yet only register minimum width into the layout system.
|
||||
popup_pos = ImVec2(pos.x, pos.y - style.WindowPadding.y);
|
||||
float icon_w = 0.0f; // FIXME: This not currently exposed for BeginMenu() however you can call window->DC.MenuColumns.DeclColumns(w, 0, 0, 0) yourself
|
||||
float icon_w = (icon && icon[0]) ? CalcTextSize(icon, NULL).x : 0.0f;
|
||||
float checkmark_w = IM_FLOOR(g.FontSize * 1.20f);
|
||||
float min_w = window->DC.MenuColumns.DeclColumns(icon_w, label_size.x, 0.0f, checkmark_w); // Feedback to next frame
|
||||
float extra_w = ImMax(0.0f, GetContentRegionAvail().x - min_w);
|
||||
ImVec2 text_pos(window->DC.CursorPos.x + offsets->OffsetLabel, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset);
|
||||
pressed = Selectable("", menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_SpanAvailWidth, ImVec2(min_w, 0.0f));
|
||||
RenderText(text_pos, label);
|
||||
if (icon_w > 0.0f)
|
||||
RenderText(pos + ImVec2(offsets->OffsetIcon, 0.0f), icon);
|
||||
RenderArrow(window->DrawList, pos + ImVec2(offsets->OffsetMark + extra_w + g.FontSize * 0.30f, 0.0f), GetColorU32(ImGuiCol_Text), ImGuiDir_Right);
|
||||
}
|
||||
if (!enabled)
|
||||
@ -6967,6 +6969,11 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
||||
return menu_is_open;
|
||||
}
|
||||
|
||||
bool ImGui::BeginMenu(const char* label, bool enabled)
|
||||
{
|
||||
return BeginMenuEx(label, NULL, enabled);
|
||||
}
|
||||
|
||||
void ImGui::EndMenu()
|
||||
{
|
||||
// Nav: When a left move request _within our child menu_ failed, close ourselves (the _parent_ menu).
|
||||
|
Loading…
Reference in New Issue
Block a user