From 4eeba016f620cd2aac3e4a3eab4dc526397597dc Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 26 May 2015 15:01:04 +0100 Subject: [PATCH] WIP Menus: Closing sub-menu when hovering something else in the same parent window (#126) Immediate open/close is error-prone --- imgui.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 94d9b0721..2e284d3da 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7603,15 +7603,17 @@ bool ImGui::BeginMenu(const char* label) bool want_open = false; if (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) - want_open = (!opened && hovered); - else if (opened && pressed && menuset_opened) { - ClosePopup(label); // click again to toggle + if (opened && !hovered && g.HoveredWindow == window && g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrame != id) + ClosePopup(label); + want_open = (!opened && hovered); + } + else if (opened && pressed && menuset_opened) // menu-bar: click open menu to close + { + ClosePopup(label); want_open = opened = false; } - else if (pressed) - want_open = true; - else if (hovered && menuset_opened && !opened) + else if (pressed || (hovered && menuset_opened && !opened)) // menu-bar: first click to open, then hover to open others want_open = true; if (!opened && want_open && g.OpenedPopupStack.size() > g.CurrentPopupStack.size())