Skip to content

Commit dfe308b

Browse files
committed
Viewports: fixed an issue inferring Z-order when attempting to merge a viewport back in the the main/hosting viewport. (ocornut#8948)
1 parent 1ad9de5 commit dfe308b

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

docs/CHANGELOG.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Docking+Viewports Branch:
5454
- Nav: fixed a crash that could occur when opening a popup following the processing
5555
of a global shortcut while no windows were focused (the fix done in 1.92.3 was
5656
incomplete for docking branch).
57+
- Viewports: fixed an issue inferring Z-order when attempting to merge a viewport
58+
back in the the main/hosting viewport. (#8948)
59+
Note that for GLFW/SDL2/OSX backends, which do not support honoring ParentViewportID.
60+
setting io.ConfigViewportsNoDefaultParent=true will align imgui's expectation with
61+
what the backend does.
5762
- Viewports: DestroyContext() does not call DestroyPlatformWindows() anymore at
5863
it assumed to be unnecessary as backensd should have done it and we check that
5964
backends have been shutdown since 1.90.4. Changed into asserts. (#7175, #8945)

imgui.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16326,6 +16326,15 @@ static bool ImGui::GetWindowAlwaysWantOwnViewport(ImGuiWindow* window)
1632616326
return false;
1632716327
}
1632816328

16329+
16330+
// Heuristic, see #8948: depends on how backends handle OS-level parenting.
16331+
static bool IsViewportAbove(ImGuiViewportP* potential_above, ImGuiViewportP* potential_below)
16332+
{
16333+
if (potential_above->LastFocusedStampCount > potential_below->LastFocusedStampCount || potential_above->ParentViewportId == potential_below->ID) // FIXME: Should follow the ParentViewportId list.
16334+
return true;
16335+
return false;
16336+
}
16337+
1632916338
static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImGuiViewportP* viewport)
1633016339
{
1633116340
ImGuiContext& g = *GImGui;
@@ -16340,14 +16349,12 @@ static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImG
1634016349
if (GetWindowAlwaysWantOwnViewport(window))
1634116350
return false;
1634216351

16343-
// FIXME: Can't use g.WindowsFocusOrder[] for root windows only as we care about Z order. If we maintained a DisplayOrder along with FocusOrder we could..
16344-
for (ImGuiWindow* window_behind : g.Windows)
16352+
for (ImGuiViewportP* viewport_2 : g.Viewports)
1634516353
{
16346-
if (window_behind == window)
16347-
break;
16348-
if (window_behind->WasActive && window_behind->ViewportOwned && !(window_behind->Flags & ImGuiWindowFlags_ChildWindow))
16349-
if (window_behind->Viewport->GetMainRect().Overlaps(window->Rect()))
16350-
return false;
16354+
if (viewport_2 == viewport || viewport_2 == window->Viewport)
16355+
continue;
16356+
if (IsViewportAbove(viewport_2, viewport) && viewport_2->GetMainRect().Overlaps(window->Rect()))
16357+
return false;
1635116358
}
1635216359

1635316360
// Move to the existing viewport, Move child/hosted windows as well (FIXME-OPT: iterate child)

0 commit comments

Comments
 (0)