1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-12-01 02:37:24 +01:00

Modals: In the case of nested modal, made sure that focused or appearing windows are moved below the lowest blocking modal (rather than the highest one). (#4317)

Fix FindBlockingkModal() which didn't do what the comments say for the first 2 lines.
This is also fixing a crash in FindBlockingModal() which can only happen with dock node, see "window_popup_nested_interruptions_2" and viewport_platform_focus_4" tests.
The dock-node related crash comes from the fact that automatic dock node and implicit debug window don't share a common ancestor, so ParentWindowInBeginStack ends up NULL before the loop had a chance to find a match.
This commit is contained in:
ocornut 2023-06-14 21:58:28 +02:00
parent eec344cc1e
commit 89d3dabf2e
2 changed files with 11 additions and 10 deletions

View File

@ -41,6 +41,8 @@ Other changes:
- Clipper: Rework inner logic to allow functioning with a zero-clear constructor. - Clipper: Rework inner logic to allow functioning with a zero-clear constructor.
This is order to facilitate usage for language bindings (e.g cimgui or dear_binding) This is order to facilitate usage for language bindings (e.g cimgui or dear_binding)
where user may not be callinga constructor manually. (#5856) where user may not be callinga constructor manually. (#5856)
- Modals: In the case of nested modal, made sure that focused or appearing windows are
moved below the lowest blocking modal (rather than the highest one). (#4317)
- IsItemHovered: Tweaked default value of io.HoverDelayNormal from 0.30 to 0.35 (used when - IsItemHovered: Tweaked default value of io.HoverDelayNormal from 0.30 to 0.35 (used when
using the ImGuiHoveredFlags_DelayNormal flag). (#1485) using the ImGuiHoveredFlags_DelayNormal flag). (#1485)
- Tooltips: Tweak default offset for non-drag and drop tooltips so underlying items - Tooltips: Tweak default offset for non-drag and drop tooltips so underlying items

View File

@ -6093,12 +6093,13 @@ void ImGui::UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags
// When a modal popup is open, newly created windows that want focus (i.e. are not popups and do not specify ImGuiWindowFlags_NoFocusOnAppearing) // When a modal popup is open, newly created windows that want focus (i.e. are not popups and do not specify ImGuiWindowFlags_NoFocusOnAppearing)
// should be positioned behind that modal window, unless the window was created inside the modal begin-stack. // should be positioned behind that modal window, unless the window was created inside the modal begin-stack.
// In case of multiple stacked modals newly created window honors begin stack order and does not go below its own modal parent. // In case of multiple stacked modals newly created window honors begin stack order and does not go below its own modal parent.
// - Window // FindBlockingModal() returns Modal1 // - WindowA // FindBlockingModal() returns Modal1
// - Window // .. returns Modal1 // - WindowB // .. returns Modal1
// - Modal1 // .. returns Modal2 // - Modal1 // .. returns Modal2
// - Window // .. returns Modal2 // - WindowC // .. returns Modal2
// - Window // .. returns Modal2 // - WindowD // .. returns Modal2
// - Modal2 // .. returns Modal2 // - Modal2 // .. returns Modal2
// - WindowE // .. returns NULL
// Notes: // Notes:
// - FindBlockingModal(NULL) == NULL is generally equivalent to GetTopMostPopupModal() == NULL. // - FindBlockingModal(NULL) == NULL is generally equivalent to GetTopMostPopupModal() == NULL.
// Only difference is here we check for ->Active/WasActive but it may be unecessary. // Only difference is here we check for ->Active/WasActive but it may be unecessary.
@ -6109,7 +6110,7 @@ ImGuiWindow* ImGui::FindBlockingModal(ImGuiWindow* window)
return NULL; return NULL;
// Find a modal that has common parent with specified window. Specified window should be positioned behind that modal. // Find a modal that has common parent with specified window. Specified window should be positioned behind that modal.
for (int i = g.OpenPopupStack.Size - 1; i >= 0; i--) for (int i = 0; i < g.OpenPopupStack.Size; i++)
{ {
ImGuiWindow* popup_window = g.OpenPopupStack.Data[i].Window; ImGuiWindow* popup_window = g.OpenPopupStack.Data[i].Window;
if (popup_window == NULL || !(popup_window->Flags & ImGuiWindowFlags_Modal)) if (popup_window == NULL || !(popup_window->Flags & ImGuiWindowFlags_Modal))
@ -6118,11 +6119,9 @@ ImGuiWindow* ImGui::FindBlockingModal(ImGuiWindow* window)
continue; continue;
if (window == NULL) // FindBlockingModal(NULL) test for if FocusWindow(NULL) is naturally possible via a mouse click. if (window == NULL) // FindBlockingModal(NULL) test for if FocusWindow(NULL) is naturally possible via a mouse click.
return popup_window; return popup_window;
if (IsWindowWithinBeginStackOf(window, popup_window)) // Window is rendered over last modal, no render order change needed. if (IsWindowWithinBeginStackOf(window, popup_window)) // Window may be over modal
break; continue;
for (ImGuiWindow* parent = popup_window->ParentWindowInBeginStack->RootWindow; parent != NULL; parent = parent->ParentWindowInBeginStack->RootWindow) return popup_window; // Place window right below first block modal
if (IsWindowWithinBeginStackOf(window, parent))
return popup_window; // Place window above its begin stack parent.
} }
return NULL; return NULL;
} }