From cbade7b16d3b7f1bbcd257a9639209e937a88224 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 10 Jul 2020 19:04:58 +0200 Subject: [PATCH] Docking: Workaround recovery for node created without the _ockSpace flags later becoming DockSpace. (#3340) --- imgui.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 7b31979c..36d27145 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -14145,6 +14145,17 @@ void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags fla node->OnlyNodeWithWindows = NULL; IM_ASSERT(node->IsRootNode()); + + // We need to handle the rare case were a central node is missing. + // This can happen if the node was first created manually with DockBuilderAddNode() but _without_ the ImGuiDockNodeFlags_Dockspace. + // Doing it correctly would set the _CentralNode flags, which would then propagate according to subsequent split. + // It would also be ambiguous to attempt to assign a central node while there are split nodes, so we wait until there's a single node remaining. + // The specific sub-property of _CentralNode we are interested in recovering here is the "Don't delete when empty" property, + // as it doesn't make sense for an empty dockspace to not have this property. + if (node->IsLeafNode() && !node->IsCentralNode()) + node->LocalFlags |= ImGuiDockNodeFlags_CentralNode; + + // Update the node DockNodeUpdate(node); g.WithinEndChild = true; @@ -15765,14 +15776,16 @@ void ImGui::ShowMetricsWindow(bool* p_open) #ifdef IMGUI_HAS_DOCK if (ImGui::TreeNode("Dock nodes")) { + static bool root_nodes_only = true; ImGuiDockContext* dc = &g.DockContext; + ImGui::Checkbox("List root nodes", &root_nodes_only); ImGui::Checkbox("Ctrl shows window dock info", &show_docking_nodes); if (ImGui::SmallButton("Clear nodes")) { DockContextClearNodes(&g, 0, true); } ImGui::SameLine(); if (ImGui::SmallButton("Rebuild all")) { dc->WantFullRebuild = true; } for (int n = 0; n < dc->Nodes.Data.Size; n++) if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p) - if (node->IsRootNode()) + if (!root_nodes_only || node->IsRootNode()) Funcs::NodeDockNode(node, "Node"); ImGui::TreePop(); }