Modals, Popups: fixed an issue preventing to close a popup opened over a modal by clicking over void. (#7654)

This commit is contained in:
ocornut 2024-06-05 15:47:21 +02:00
parent 219c6adc58
commit 0561d708ba
3 changed files with 9 additions and 2 deletions

View File

@ -49,6 +49,8 @@ Other changes:
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

View File

@ -7378,9 +7378,13 @@ void ImGui::FocusWindow(ImGuiWindow* window, ImGuiFocusRequestFlags flags)
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;
}

View File

@ -3875,7 +3875,7 @@ static void ShowDemoWindowPopups()
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 @@ static void ShowDemoWindowPopups()
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();