Modals, Popups: fixed an issue preventing to close a popup opened over a modal by clicking over void. (#7654)
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index 9578f87..6b2f0f0 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -49,6 +49,8 @@
check ownership). (#7657) [@korenkonder]
- Windows: fixed altering FramePadding mid-frame not correctly affecting logic
responsible for honoring io.ConfigWindowsMoveFromTitleBarOnly. (#7576, #899)
+- Popups: fixed an issue preventing to close a popup opened over a modal by clicking
+ over void (it required clicking over the visible part of the modal). (#7654)
- Scrollbar: made scrolling logic more standard: clicking above or below the
grab scrolls by one page, holding mouse button repeats scrolling. (#7328, #150)
- Scrollbar: fixed miscalculation of vertical scrollbar visibility when required
diff --git a/imgui.cpp b/imgui.cpp
index 92ea44c..ffd055a 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -7378,9 +7378,13 @@
if ((flags & ImGuiFocusRequestFlags_UnlessBelowModal) && (g.NavWindow != window)) // Early out in common case.
if (ImGuiWindow* blocking_modal = FindBlockingModal(window))
{
+ // This block would typically be reached in two situations:
+ // - API call to FocusWindow() with a window under a modal and ImGuiFocusRequestFlags_UnlessBelowModal flag.
+ // - User clicking on void or anything behind a modal while a modal is open (window == NULL)
IMGUI_DEBUG_LOG_FOCUS("[focus] FocusWindow(\"%s\", UnlessBelowModal): prevented by \"%s\".\n", window ? window->Name : "<NULL>", blocking_modal->Name);
if (window && window == window->RootWindow && (window->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus) == 0)
- BringWindowToDisplayBehind(window, blocking_modal); // Still bring to right below modal.
+ BringWindowToDisplayBehind(window, blocking_modal); // Still bring right under modal. (FIXME: Could move in focus list too?)
+ ClosePopupsOverWindow(GetTopMostPopupModal(), false); // Note how we need to use GetTopMostPopupModal() aad NOT blocking_modal, to handle nested modals
return;
}
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 8183ee1..de657be 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -3875,7 +3875,7 @@
static int item = 1;
static float color[4] = { 0.4f, 0.7f, 0.0f, 0.5f };
ImGui::Combo("Combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0");
- ImGui::ColorEdit4("color", color);
+ ImGui::ColorEdit4("Color", color);
if (ImGui::Button("Add another modal.."))
ImGui::OpenPopup("Stacked 2");
@@ -3887,6 +3887,7 @@
if (ImGui::BeginPopupModal("Stacked 2", &unused_open))
{
ImGui::Text("Hello from Stacked The Second!");
+ ImGui::ColorEdit4("Color", color); // Allow opening another nested popup
if (ImGui::Button("Close"))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();