From 6f8d34768da2c5bf16c67e1385158fcf76ce1598 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 22 Jul 2019 10:54:17 -0700 Subject: [PATCH] Docking: Removed seemingly unnecessary test in TabItemEx() for undocking tab leading to window move. Added ImGuiDockNode::IsFloatingNode() helper to clarify code intent in various places. --- imgui.cpp | 9 +++++---- imgui.h | 2 +- imgui_internal.h | 1 + imgui_widgets.cpp | 4 +--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 65f11a85..c1d5a351 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11216,7 +11216,7 @@ void ImGui::DockContextUpdateDocking(ImGuiContext* ctx) // We can have NULL pointers when we delete nodes, but because ID are recycled this should amortize nicely (and our node count will never be very high) for (int n = 0; n < dc->Nodes.Data.Size; n++) if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p) - if (node->IsRootNode() && !node->IsDockSpace()) + if (node->IsFloatingNode()) DockNodeUpdate(node); } @@ -11702,7 +11702,7 @@ static void ImGui::DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window, b // When reactivating a node with one or two loose window, the window pos/size/viewport are authoritative over the node storage. // In particular it is important we init the viewport from the first window so we don't create two viewports and drop one. - if (node->HostWindow == NULL && !node->IsDockSpace() && node->IsRootNode()) + if (node->HostWindow == NULL && node->IsFloatingNode()) { if (node->AuthorityForPos == ImGuiDataAuthority_Auto) node->AuthorityForPos = ImGuiDataAuthority_Window; @@ -12026,7 +12026,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) DockNodeRemoveTabBar(node); // Early out for hidden root dock nodes (when all DockId references are in inactive windows, or there is only 1 floating window holding on the DockId) - if (node->Windows.Size <= 1 && node->IsRootNode() && node->IsLeafNode() && !node->IsDockSpace() && !g.IO.ConfigDockingTabBarOnSingleWindows) + if (node->Windows.Size <= 1 && node->IsFloatingNode() && node->IsLeafNode() && !g.IO.ConfigDockingTabBarOnSingleWindows) { if (node->Windows.Size == 1) { @@ -13219,6 +13219,7 @@ ImGuiDockNode* ImGui::DockNodeTreeFindNodeByPos(ImGuiDockNode* node, ImVec2 pos) // Docking: Public Functions (SetWindowDock, DockSpace, DockSpaceOverViewport) //----------------------------------------------------------------------------- +// [Internal] Called via SetNextWindowDockID() void ImGui::SetWindowDock(ImGuiWindow* window, ImGuiID dock_id, ImGuiCond cond) { // Test condition (NB: bit 0 is always true) and clear flags for next time @@ -14156,7 +14157,7 @@ static void ImGui::DockSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettings if (ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_settings->ID)) { buf->appendf("%*s", ImMax(2, (line_start_pos + 92) - buf->size()), ""); // Align everything - if (node->IsDockSpace && node->HostWindow && node->HostWindow->ParentWindow) + if (node->IsDockSpace() && node->HostWindow && node->HostWindow->ParentWindow) buf->appendf(" ; in '%s'", node->HostWindow->ParentWindow->Name); int contains_window = 0; for (int window_n = 0; window_n < ctx->SettingsWindows.Size; window_n++) diff --git a/imgui.h b/imgui.h index 3a74d7c1..6d488ff3 100644 --- a/imgui.h +++ b/imgui.h @@ -1612,7 +1612,7 @@ struct ImGuiWindowClass ImGuiID ParentViewportId; // Hint for the platform back-end. If non-zero, the platform back-end can create a parent<>child relationship between the platform windows. Not conforming back-ends are free to e.g. parent every viewport to the main viewport or not. ImGuiViewportFlags ViewportFlagsOverrideMask; // Viewport flags to override when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis. ImGuiViewportFlags ViewportFlagsOverrideValue; // Viewport flags values to override when a window of this class owns a viewport. - bool DockingAllowUnclassed; // true = can be docked/merged with an unclassed window + bool DockingAllowUnclassed; // Set to true to allow windows of this class to be docked/merged with an unclassed window. ImGuiWindowClass() { ClassId = 0; ParentViewportId = 0; ViewportFlagsOverrideMask = ViewportFlagsOverrideValue = 0x00; DockingAllowUnclassed = true; } }; diff --git a/imgui_internal.h b/imgui_internal.h index da83467d..bd1f9aad 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -963,6 +963,7 @@ struct ImGuiDockNode ~ImGuiDockNode(); bool IsRootNode() const { return ParentNode == NULL; } bool IsDockSpace() const { return (LocalFlags & ImGuiDockNodeFlags_DockSpace) != 0; } + bool IsFloatingNode() const { return ParentNode == NULL && (LocalFlags & ImGuiDockNodeFlags_DockSpace) == 0; } bool IsCentralNode() const { return (LocalFlags & ImGuiDockNodeFlags_CentralNode) != 0; } bool IsHiddenTabBar() const { return (LocalFlags & ImGuiDockNodeFlags_HiddenTabBar) != 0; } // Hidden tab bar can be shown back by clicking the small triangle bool IsNoTabBar() const { return (LocalFlags & ImGuiDockNodeFlags_NoTabBar) != 0; } // Never show a tab bar diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index ffd026c0..cb69dd4b 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6979,10 +6979,8 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, SetItemAllowOverlap(); // Drag and drop a single floating window node moves it - // FIXME-DOCK: In theory we shouldn't test for the ConfigDockingNodifySingleWindows flag here. - // When our single window node and OnlyNodeWithWindows are working properly we may remove this check here. ImGuiDockNode* node = docked_window ? docked_window->DockNode : NULL; - const bool single_floating_window_node = node && node->IsRootNode() && !node->IsDockSpace() && node->Windows.Size == 1 && g.IO.ConfigDockingTabBarOnSingleWindows; + const bool single_floating_window_node = node && node->IsFloatingNode() && (node->Windows.Size == 1); if (held && single_floating_window_node && IsMouseDragging(0, 0.0f)) { // Move