From 0cdd050cd79e7ca96886b7c1f4cbbdce55fcd1e9 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 18 May 2015 21:26:46 +0100 Subject: [PATCH] WIP Menus: fixed recycling menu level during the same frame (#126) We could also enforce "clearing" the window and recycle immediate which sort of work, but it would be a less tested code path. --- imgui.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 79d33ff14..8d9123b66 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7536,16 +7536,23 @@ bool ImGui::BeginMenu(const char* label) bool want_open = false; if (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) want_open = (!opened && hovered); - else if (pressed && menuset_opened) + else if (opened && pressed && menuset_opened) { ClosePopup(label); // click again to toggle want_open = opened = false; } else if (pressed) want_open = true; - else if (hovered && menuset_opened) + else if (hovered && menuset_opened && !opened) want_open = true; + if (!opened && want_open && g.OpenedPopupStack.size() > g.CurrentPopupStack.size()) + { + // Don't recycle same menu level in the same frame, first close the other menu and yield for a frame. + ImGui::OpenPopup(label); + return false; + } + opened |= want_open; if (want_open) ImGui::OpenPopup(label);