From 81937d34a8ff54f6784ebfc6106753518aa3590d Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 15 May 2015 17:29:42 +0100 Subject: [PATCH] Popups: made OpenPopup()/close loops reclaim focus and update popup position. It is generally a mistake but it's now more easy to understand --- imgui.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 75de808a..d93040e7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2981,11 +2981,14 @@ void ImGui::OpenPopup(const char* str_id) ImGuiWindow* window = GetCurrentWindow(); const ImGuiID id = window->GetID(str_id); - // One open popup per level of the popup hierarchy + // One open popup per level of the popup hierarchy (NB: when assigning we reset the Window member of ImGuiPopupRef to NULL) if (g.OpenedPopupStack.size() == g.CurrentPopupStack.size()) g.OpenedPopupStack.push_back(ImGuiPopupRef(id)); else if (g.OpenedPopupStack.size() == g.CurrentPopupStack.size() + 1) - g.OpenedPopupStack.back() = ImGuiPopupRef(id); + { + if (g.OpenedPopupStack.back().PopupID != id) + g.OpenedPopupStack.back() = ImGuiPopupRef(id); + } else IM_ASSERT(0); // Invalid state } @@ -2995,7 +2998,7 @@ void ImGui::CloseCurrentPopup() ImGuiState& g = *GImGui; if (g.CurrentPopupStack.empty() || g.OpenedPopupStack.empty() || g.CurrentPopupStack.back().PopupID != g.OpenedPopupStack.back().PopupID) return; - if (g.Windows.back()->PopupID == g.OpenedPopupStack.back().PopupID && g.Windows.size() >= 2) + if (g.CurrentWindow->PopupID == g.OpenedPopupStack.back().PopupID && g.Windows.size() >= 2) FocusWindow(g.Windows[g.Windows.size()-2]); g.OpenedPopupStack.pop_back(); } @@ -3301,6 +3304,7 @@ bool ImGui::Begin(const char* name, bool* p_opened, const ImVec2& size_on_first_ { ImGuiPopupRef& popup_ref = g.OpenedPopupStack[g.CurrentPopupStack.size()]; window_was_visible &= (window->PopupID == popup_ref.PopupID); + window_was_visible &= (window == popup_ref.Window); popup_ref.Window = window; g.CurrentPopupStack.push_back(popup_ref); window->PopupID = popup_ref.PopupID;