From 76e09c4b0faed1c7e12ebb660b667b5abfcc6679 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 8 Feb 2024 17:08:01 +0100 Subject: [PATCH] ClosePopupsOverWindow(): amend to remove _ChildWindow test. Said test seems unnecessary and incorrect as we test hierarchy now. See test "nav_ctrl_tab_popups" in ImGuiTestSuite. --- docs/CHANGELOG.txt | 6 ++++-- imgui.cpp | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 21fd76539..80f7807ec 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -59,11 +59,13 @@ Other changes: - Nav, Menus: Fixed click on a BeginMenu() followed by right-arrow from making the child menu reopen and flicker (using ImGuiPopupFlags_NoReopen). - Nav: ImGuiWindowFlags_NoNavInputs is tested during scoring so NavFlattened windows can use it. -- OpenPopup(): Added ImGuiPopupFlags_NoReopen flag to specifically not close and reopen a popup - when it is already open. (#1497, #1533) +- Popups: OpenPopup(): added ImGuiPopupFlags_NoReopen flag to specifically not close and reopen + a popup when it is already open. (#1497, #1533) (Note that this differs from specific handling we already have in place for the case of calling OpenPopup() repeatedly every frame: we already didn't reopen in that specific situation, otherwise the effect would be very disastrous in term of confusion, as reopening would steal focus). +- Popups: Slight change to popup closing logic (e.g. after focusing another window) which skipped + over popups that are also child windows. - Debug Tools: Metrics: Fixed debug break in SetShortcutRouting() not handling ImGuiMod_Shortcut redirect. - Debug Tools: Debug Log: Added "Input Routing" logging. - Debug Tools: Added "nop" to IM_DEBUG_BREAK macro on GCC to work around GDB bug (#7266) [@Peter0x44] diff --git a/imgui.cpp b/imgui.cpp index 39300f9ca..70de295dc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10819,14 +10819,15 @@ void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to if (!popup.Window) continue; IM_ASSERT((popup.Window->Flags & ImGuiWindowFlags_Popup) != 0); - if (popup.Window->Flags & ImGuiWindowFlags_ChildWindow) - continue; // Trim the stack unless the popup is a direct parent of the reference window (the reference window is often the NavWindow) - // - With this stack of window, clicking/focusing Popup1 will close Popup2 and Popup3: - // Window -> Popup1 -> Popup2 -> Popup3 + // - Clicking/Focusing Window2 won't close Popup1: + // Window -> Popup1 -> Window2(Ref) + // - Clicking/focusing Popup1 will close Popup2 and Popup3: + // Window -> Popup1(Ref) -> Popup2 -> Popup3 // - Each popups may contain child windows, which is why we compare ->RootWindow! // Window -> Popup1 -> Popup1_Child -> Popup2 -> Popup2_Child + // We step through every popup from bottom to top to validate their position relative to reference window. bool ref_window_is_descendent_of_popup = false; for (int n = popup_count_to_keep; n < g.OpenPopupStack.Size; n++) if (ImGuiWindow* popup_window = g.OpenPopupStack[n].Window)