From 057fcae30cec04a55eec6532e0309ea6967950f3 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 23 Jun 2023 16:03:01 +0200 Subject: [PATCH] Docking+Viewports: Fixed extraneous viewport+platform-window recreation. Part 4. Part 4: store reference viewport id from last visible single window stored in node. So Win1 -> Win1|Win2 can reuse viewport on split. Refer to "viewport_owner_change_1" and "viewport_owner_change_2" in ImGuiTestSuite. --- imgui.cpp | 5 +++++ imgui_internal.h | 1 + 2 files changed, 6 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 30cba582e..34461adc9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -15786,6 +15786,7 @@ ImGuiDockNode::ImGuiDockNode(ImGuiID id) LastFocusedNodeId = 0; SelectedTabId = 0; WantCloseTabId = 0; + RefViewportId = 0; AuthorityForPos = AuthorityForSize = ImGuiDataAuthority_DockNode; AuthorityForViewport = ImGuiDataAuthority_Auto; IsVisible = true; @@ -16277,6 +16278,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) single_window->ViewportOwned = true; } } + node->RefViewportId = single_window->ViewportId; } DockNodeHideHostWindow(node); @@ -16366,6 +16368,8 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) // Sync Viewport if (node->AuthorityForViewport == ImGuiDataAuthority_Window && ref_window) SetNextWindowViewport(ref_window->ViewportId); + else if (node->AuthorityForViewport == ImGuiDataAuthority_Window && node->RefViewportId != 0) + SetNextWindowViewport(node->RefViewportId); SetNextWindowClass(&node->WindowClass); @@ -16408,6 +16412,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) if (node->WantMouseMove && node->HostWindow) DockNodeStartMouseMovingWindow(node, node->HostWindow); } + node->RefViewportId = 0; // Clear when we have a host window // Update focused node (the one whose title bar is highlight) within a node tree if (node->IsSplitNode()) diff --git a/imgui_internal.h b/imgui_internal.h index 85fabcf29..14650f56a 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1685,6 +1685,7 @@ struct IMGUI_API ImGuiDockNode ImGuiID LastFocusedNodeId; // [Root node only] Which of our child docking node (any ancestor in the hierarchy) was last focused. ImGuiID SelectedTabId; // [Leaf node only] Which of our tab/window is selected. ImGuiID WantCloseTabId; // [Leaf node only] Set when closing a specific tab/window. + ImGuiID RefViewportId; // Reference viewport ID from visible window when HostWindow == NULL. ImGuiDataAuthority AuthorityForPos :3; ImGuiDataAuthority AuthorityForSize :3; ImGuiDataAuthority AuthorityForViewport :3;