MCPcopy Create free account
hub / github.com/cinder/Cinder / MenuItemEx

Method MenuItemEx

src/imgui/imgui_widgets.cpp:9362–9437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9360}
9361
9362bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut, bool selected, bool enabled)
9363{
9364 ImGuiWindow* window = GetCurrentWindow();
9365 if (window->SkipItems)
9366 return false;
9367
9368 ImGuiContext& g = *GImGui;
9369 ImGuiStyle& style = g.Style;
9370 ImVec2 pos = window->DC.CursorPos;
9371 ImVec2 label_size = CalcTextSize(label, NULL, true);
9372
9373 // See BeginMenuEx() for comments about this.
9374 const bool menuset_is_open = IsRootOfOpenMenuSet();
9375 if (menuset_is_open)
9376 PushItemFlag(ImGuiItemFlags_NoWindowHoverableCheck, true);
9377
9378 // We've been using the equivalent of ImGuiSelectableFlags_SetNavIdOnHover on all Selectable() since early Nav system days (commit 43ee5d73),
9379 // but I am unsure whether this should be kept at all. For now moved it to be an opt-in feature used by menus only.
9380 bool pressed;
9381 PushID(label);
9382 if (!enabled)
9383 BeginDisabled();
9384
9385 // We use ImGuiSelectableFlags_NoSetKeyOwner to allow down on one menu item, move, up on another.
9386 const ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_SelectOnRelease | ImGuiSelectableFlags_NoSetKeyOwner | ImGuiSelectableFlags_SetNavIdOnHover;
9387 const ImGuiMenuColumns* offsets = &window->DC.MenuColumns;
9388 if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
9389 {
9390 // Mimic the exact layout spacing of BeginMenu() to allow MenuItem() inside a menu bar, which is a little misleading but may be useful
9391 // Note that in this situation: we don't render the shortcut, we render a highlight instead of the selected tick mark.
9392 float w = label_size.x;
9393 window->DC.CursorPos.x += IM_TRUNC(style.ItemSpacing.x * 0.5f);
9394 ImVec2 text_pos(window->DC.CursorPos.x + offsets->OffsetLabel, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset);
9395 PushStyleVarX(ImGuiStyleVar_ItemSpacing, style.ItemSpacing.x * 2.0f);
9396 pressed = Selectable("", selected, selectable_flags, ImVec2(w, 0.0f));
9397 PopStyleVar();
9398 if (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_Visible)
9399 RenderText(text_pos, label);
9400 window->DC.CursorPos.x += IM_TRUNC(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar().
9401 }
9402 else
9403 {
9404 // Menu item inside a vertical menu
9405 // (In a typical menu window where all items are BeginMenu() or MenuItem() calls, extra_w will always be 0.0f.
9406 // Only when they are other items sticking out we're going to add spacing, yet only register minimum width into the layout system.)
9407 float icon_w = (icon && icon[0]) ? CalcTextSize(icon, NULL).x : 0.0f;
9408 float shortcut_w = (shortcut && shortcut[0]) ? CalcTextSize(shortcut, NULL).x : 0.0f;
9409 float checkmark_w = IM_TRUNC(g.FontSize * 1.20f);
9410 float min_w = window->DC.MenuColumns.DeclColumns(icon_w, label_size.x, shortcut_w, checkmark_w); // Feedback for next frame
9411 float stretch_w = ImMax(0.0f, GetContentRegionAvail().x - min_w);
9412 pressed = Selectable("", false, selectable_flags | ImGuiSelectableFlags_SpanAvailWidth, ImVec2(min_w, label_size.y));
9413 if (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_Visible)
9414 {
9415 RenderText(pos + ImVec2(offsets->OffsetLabel, 0.0f), label);
9416 if (icon_w > 0.0f)
9417 RenderText(pos + ImVec2(offsets->OffsetIcon, 0.0f), icon);
9418 if (shortcut_w > 0.0f)
9419 {

Callers

nothing calls this directly

Calls 5

GetCurrentWindowFunction · 0.85
IsRootOfOpenMenuSetFunction · 0.85
ImVec2Function · 0.85
ImMaxFunction · 0.85
DeclColumnsMethod · 0.80

Tested by

no test coverage detected