MCPcopy Create free account
hub / github.com/Aegel5/SimpleSwitcher / IsRootOfOpenMenuSet

Function IsRootOfOpenMenuSet

imgui_tiny_app/imgui/imgui_widgets.cpp:9212–9234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9210}
9211
9212static bool IsRootOfOpenMenuSet()
9213{
9214 ImGuiContext& g = *GImGui;
9215 ImGuiWindow* window = g.CurrentWindow;
9216 if ((g.OpenPopupStack.Size <= g.BeginPopupStack.Size) || (window->Flags & ImGuiWindowFlags_ChildMenu))
9217 return false;
9218
9219 // Initially we used 'upper_popup->OpenParentId == window->IDStack.back()' to differentiate multiple menu sets from each others
9220 // (e.g. inside menu bar vs loose menu items) based on parent ID.
9221 // This would however prevent the use of e.g. PushID() user code submitting menus.
9222 // Previously this worked between popup and a first child menu because the first child menu always had the _ChildWindow flag,
9223 // making hovering on parent popup possible while first child menu was focused - but this was generally a bug with other side effects.
9224 // Instead we don't treat Popup specifically (in order to consistently support menu features in them), maybe the first child menu of a Popup
9225 // doesn't have the _ChildWindow flag, and we rely on this IsRootOfOpenMenuSet() check to allow hovering between root window/popup and first child menu.
9226 // In the end, lack of ID check made it so we could no longer differentiate between separate menu sets. To compensate for that, we at least check parent window nav layer.
9227 // This fixes the most common case of menu opening on hover when moving between window content and menu bar. Multiple different menu sets in same nav layer would still
9228 // open on hover, but that should be a lesser problem, because if such menus are close in proximity in window content then it won't feel weird and if they are far apart
9229 // it likely won't be a problem anyone runs into.
9230 const ImGuiPopupData* upper_popup = &g.OpenPopupStack[g.BeginPopupStack.Size];
9231 if (window->DC.NavLayerCurrent != upper_popup->ParentNavLayer)
9232 return false;
9233 return upper_popup->Window && (upper_popup->Window->Flags & ImGuiWindowFlags_ChildMenu) && ImGui::IsWindowChildOf(upper_popup->Window, window, true, false);
9234}
9235
9236bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled)
9237{

Callers 2

BeginMenuExMethod · 0.85
MenuItemExMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected