From 48ede93a58a8be2dd08c845f7ba005bbaf121e12 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 24 May 2015 22:30:48 +0100 Subject: [PATCH] WIP Menus: Fixed closing popup on menu item activation when a child menu is open from the popup (#126) --- imgui.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4b4f5b2c..fd2b63f3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3056,14 +3056,15 @@ static void ClosePopup(const char* str_id) // not exposed because 'id' scope is void ImGui::CloseCurrentPopup() { ImGuiState& g = *GImGui; - if (g.CurrentPopupStack.empty() || g.OpenedPopupStack.empty() || g.CurrentPopupStack.back().PopupID != g.OpenedPopupStack.back().PopupID) + int popup_idx = (int)g.CurrentPopupStack.size() - 1; + if (popup_idx < 0 || popup_idx > (int)g.OpenedPopupStack.size() || g.CurrentPopupStack[popup_idx].PopupID != g.OpenedPopupStack[popup_idx].PopupID) return; - if (g.CurrentWindow->PopupID == g.OpenedPopupStack.back().PopupID && g.Windows.size() >= 2) + if (g.CurrentWindow->PopupID == g.OpenedPopupStack[popup_idx].PopupID && g.Windows.size() > 1) FocusWindow(g.Windows[g.Windows.size()-2]); - g.OpenedPopupStack.pop_back(); + g.OpenedPopupStack.resize(popup_idx); } -static void CloseAllPopups() +static void CloseCurrentMenus() { // Close all popups // FIXME-MENUS: invalid for popup->menus with current BeginMenu() scheme @@ -7317,7 +7318,7 @@ static bool SelectableEx(const char* label, bool selected, const ImVec2& size_ar // Automatically close popups if (pressed && (window->Flags & ImGuiWindowFlags_ChildMenu)) - CloseAllPopups(); + CloseCurrentMenus(); else if (pressed && (window->Flags & ImGuiWindowFlags_Popup)) ImGui::CloseCurrentPopup(); return pressed;