Skip to content

Commit 7c06d9f

Browse files
committed
Docking: Saving the NoTabBar, NoWindowMenuButton, NoCloseButton fields of dock node into the .ini file. Added them to the Metrics window. (#2583, #2423, #2109).
1 parent 511e32e commit 7c06d9f

File tree

2 files changed

+44
-39
lines changed

2 files changed

+44
-39
lines changed

imgui.cpp

+35-32
Original file line numberDiff line numberDiff line change
@@ -11065,18 +11065,16 @@ struct ImGuiDockPreviewData
1106511065
// Persistent Settings data, stored contiguously in SettingsNodes (sizeof() ~32 bytes)
1106611066
struct ImGuiDockNodeSettings
1106711067
{
11068-
ImGuiID ID;
11069-
ImGuiID ParentID;
11070-
ImGuiID SelectedTabID;
11071-
signed char SplitAxis;
11072-
char Depth;
11073-
char IsDockSpace;
11074-
char IsCentralNode;
11075-
char IsHiddenTabBar;
11076-
ImVec2ih Pos;
11077-
ImVec2ih Size;
11078-
ImVec2ih SizeRef;
11079-
ImGuiDockNodeSettings() { ID = ParentID = SelectedTabID = 0; SplitAxis = ImGuiAxis_None; Depth = 0; IsDockSpace = IsCentralNode = IsHiddenTabBar = 0; }
11068+
ImGuiID ID;
11069+
ImGuiID ParentID;
11070+
ImGuiID SelectedTabID;
11071+
signed char SplitAxis;
11072+
char Depth;
11073+
ImGuiDockNodeFlags Flags; // NB: We save individual flags one by one in ascii format (ImGuiDockNodeFlags_SavedFlagsMask_)
11074+
ImVec2ih Pos;
11075+
ImVec2ih Size;
11076+
ImVec2ih SizeRef;
11077+
ImGuiDockNodeSettings() { ID = ParentID = SelectedTabID = 0; SplitAxis = ImGuiAxis_None; Depth = 0; Flags = ImGuiDockNodeFlags_None; }
1108011078
};
1108111079

1108211080
struct ImGuiDockContext
@@ -11394,7 +11392,7 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx)
1139411392
ImGuiDockContextPruneNodeData* data_root = (data->RootID == settings->ID) ? data : pool.GetByKey(data->RootID);
1139511393

1139611394
bool remove = false;
11397-
remove |= (data->CountWindows == 1 && settings->ParentID == 0 && data->CountChildNodes == 0 && !settings->IsCentralNode); // Floating root node with only 1 window
11395+
remove |= (data->CountWindows == 1 && settings->ParentID == 0 && data->CountChildNodes == 0 && !(settings->Flags & ImGuiDockNodeFlags_CentralNode)); // Floating root node with only 1 window
1139811396
remove |= (data->CountWindows == 0 && settings->ParentID == 0 && data->CountChildNodes == 0); // Leaf nodes with 0 window
1139911397
remove |= (data_root->CountChildWindows == 0);
1140011398
if (remove)
@@ -11425,12 +11423,7 @@ static void ImGui::DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDoc
1142511423
node->ParentNode->ChildNodes[1] = node;
1142611424
node->SelectedTabID = settings->SelectedTabID;
1142711425
node->SplitAxis = settings->SplitAxis;
11428-
if (settings->IsDockSpace)
11429-
node->LocalFlags |= ImGuiDockNodeFlags_DockSpace;
11430-
if (settings->IsCentralNode)
11431-
node->LocalFlags |= ImGuiDockNodeFlags_CentralNode;
11432-
if (settings->IsHiddenTabBar)
11433-
node->LocalFlags |= ImGuiDockNodeFlags_HiddenTabBar;
11426+
node->LocalFlags |= (settings->Flags & ImGuiDockNodeFlags_SavedFlagsMask_);
1143411427

1143511428
// Bind host window immediately if it already exist (in case of a rebuild)
1143611429
// This is useful as the RootWindowForTitleBarHighlight links necessary to highlight the currently focused node requires node->HostWindow to be set.
@@ -14076,10 +14069,11 @@ static void ImGui::DockSettingsHandler_ReadLine(ImGuiContext* ctx, ImGuiSettings
1407614069
// Parsing, e.g.
1407714070
// " DockNode ID=0x00000001 Pos=383,193 Size=201,322 Split=Y,0.506 "
1407814071
// " DockNode ID=0x00000002 Parent=0x00000001 "
14072+
// Important: this code expect currently fields in a fixed order.
1407914073
ImGuiDockNodeSettings node;
1408014074
line = ImStrSkipBlank(line);
1408114075
if (strncmp(line, "DockNode", 8) == 0) { line = ImStrSkipBlank(line + strlen("DockNode")); }
14082-
else if (strncmp(line, "DockSpace", 9) == 0) { line = ImStrSkipBlank(line + strlen("DockSpace")); node.IsDockSpace = true; }
14076+
else if (strncmp(line, "DockSpace", 9) == 0) { line = ImStrSkipBlank(line + strlen("DockSpace")); node.Flags |= ImGuiDockNodeFlags_DockSpace; }
1408314077
else return;
1408414078
if (sscanf(line, "ID=0x%08X%n", &node.ID, &r) == 1) { line += r; } else return;
1408514079
if (sscanf(line, " Parent=0x%08X%n", &node.ParentID, &r) == 1) { line += r; if (node.ParentID == 0) return; }
@@ -14093,8 +14087,11 @@ static void ImGui::DockSettingsHandler_ReadLine(ImGuiContext* ctx, ImGuiSettings
1409314087
if (sscanf(line, " SizeRef=%i,%i%n", &x, &y, &r) == 2) { line += r; node.SizeRef = ImVec2ih((short)x, (short)y); }
1409414088
}
1409514089
if (sscanf(line, " Split=%c%n", &c, &r) == 1) { line += r; if (c == 'X') node.SplitAxis = ImGuiAxis_X; else if (c == 'Y') node.SplitAxis = ImGuiAxis_Y; }
14096-
if (sscanf(line, " CentralNode=%d%n", &x, &r) == 1) { line += r; node.IsCentralNode = (x != 0); }
14097-
if (sscanf(line, " HiddenTabBar=%d%n", &x, &r) == 1) { line += r; node.IsHiddenTabBar = (x != 0); }
14090+
if (sscanf(line, " CentralNode=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_CentralNode; }
14091+
if (sscanf(line, " NoTabBar=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoTabBar; }
14092+
if (sscanf(line, " HiddenTabBar=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_HiddenTabBar; }
14093+
if (sscanf(line, " NoWindowMenuButton=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoWindowMenuButton; }
14094+
if (sscanf(line, " NoCloseButton=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoCloseButton; }
1409814095
if (sscanf(line, " SelectedTab=0x%08X%n", &node.SelectedTabID,&r) == 1) { line += r; }
1409914096
ImGuiDockContext* dc = ctx->DockContext;
1410014097
if (node.ParentID != 0)
@@ -14112,9 +14109,7 @@ static void DockSettingsHandler_DockNodeToSettings(ImGuiDockContext* dc, ImGuiDo
1411214109
node_settings.SelectedTabID = node->SelectedTabID;
1411314110
node_settings.SplitAxis = node->IsSplitNode() ? (char)node->SplitAxis : ImGuiAxis_None;
1411414111
node_settings.Depth = (char)depth;
14115-
node_settings.IsDockSpace = (char)node->IsDockSpace();
14116-
node_settings.IsCentralNode = (char)node->IsCentralNode();
14117-
node_settings.IsHiddenTabBar = (char)node->IsHiddenTabBar();
14112+
node_settings.Flags = node->GetMergedFlags() & ImGuiDockNodeFlags_SavedFlagsMask_;
1411814113
node_settings.Pos = ImVec2ih((short)node->Pos.x, (short)node->Pos.y);
1411914114
node_settings.Size = ImVec2ih((short)node->Size.x, (short)node->Size.y);
1412014115
node_settings.SizeRef = ImVec2ih((short)node->SizeRef.x, (short)node->SizeRef.y);
@@ -14151,18 +14146,24 @@ static void ImGui::DockSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettings
1415114146
{
1415214147
const int line_start_pos = buf->size(); (void)line_start_pos;
1415314148
const ImGuiDockNodeSettings* node_settings = &dc->SettingsNodes[node_n];
14154-
buf->appendf("%*s%s%*s", node_settings->Depth * 2, "", node_settings->IsDockSpace ? "DockSpace" : "DockNode ", (max_depth - node_settings->Depth) * 2, ""); // Text align nodes to facilitate looking at .ini file
14149+
buf->appendf("%*s%s%*s", node_settings->Depth * 2, "", (node_settings->Flags & ImGuiDockNodeFlags_DockSpace) ? "DockSpace" : "DockNode ", (max_depth - node_settings->Depth) * 2, ""); // Text align nodes to facilitate looking at .ini file
1415514150
buf->appendf(" ID=0x%08X", node_settings->ID);
1415614151
if (node_settings->ParentID)
1415714152
buf->appendf(" Parent=0x%08X SizeRef=%d,%d", node_settings->ParentID, node_settings->SizeRef.x, node_settings->SizeRef.y);
1415814153
else
1415914154
buf->appendf(" Pos=%d,%d Size=%d,%d", node_settings->Pos.x, node_settings->Pos.y, node_settings->Size.x, node_settings->Size.y);
1416014155
if (node_settings->SplitAxis != ImGuiAxis_None)
1416114156
buf->appendf(" Split=%c", (node_settings->SplitAxis == ImGuiAxis_X) ? 'X' : 'Y');
14162-
if (node_settings->IsCentralNode)
14157+
if (node_settings->Flags & ImGuiDockNodeFlags_CentralNode)
1416314158
buf->appendf(" CentralNode=1");
14164-
if (node_settings->IsHiddenTabBar)
14159+
if (node_settings->Flags & ImGuiDockNodeFlags_NoTabBar)
14160+
buf->appendf(" NoTabBar=1");
14161+
if (node_settings->Flags & ImGuiDockNodeFlags_HiddenTabBar)
1416514162
buf->appendf(" HiddenTabBar=1");
14163+
if (node_settings->Flags & ImGuiDockNodeFlags_NoWindowMenuButton)
14164+
buf->appendf(" NoWindowMenuButton=1");
14165+
if (node_settings->Flags & ImGuiDockNodeFlags_NoCloseButton)
14166+
buf->appendf(" NoCloseButton=1");
1416614167
if (node_settings->SelectedTabID)
1416714168
buf->appendf(" SelectedTab=0x%08X", node_settings->SelectedTabID);
1416814169

@@ -14700,10 +14701,12 @@ void ImGui::ShowDockingDebug()
1470014701
ImGui::BulletText("Misc:%s%s%s%s", node->IsDockSpace() ? " IsDockSpace" : "", node->IsCentralNode() ? " IsCentralNode" : "", (g.FrameCount - node->LastFrameAlive < 2) ? " IsAlive" : "", (g.FrameCount - node->LastFrameActive < 2) ? " IsActive" : "");
1470114702
if (ImGui::TreeNode("flags", "LocalFlags: 0x%04X SharedFlags: 0x%04X", node->LocalFlags, node->SharedFlags))
1470214703
{
14703-
ImGui::CheckboxFlags("LocalFlags: NoSplit", (unsigned int*)&node->LocalFlags, ImGuiDockNodeFlags_NoSplit);
14704-
ImGui::CheckboxFlags("LocalFlags: NoResize", (unsigned int*)&node->LocalFlags, ImGuiDockNodeFlags_NoResize);
14705-
ImGui::CheckboxFlags("LocalFlags: NoTabBar", (unsigned int*)&node->LocalFlags, ImGuiDockNodeFlags_NoTabBar);
14706-
ImGui::CheckboxFlags("LocalFlags: HiddenTabBar",(unsigned int*)&node->LocalFlags, ImGuiDockNodeFlags_HiddenTabBar);
14704+
ImGui::CheckboxFlags("LocalFlags: NoSplit", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoSplit);
14705+
ImGui::CheckboxFlags("LocalFlags: NoResize", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoResize);
14706+
ImGui::CheckboxFlags("LocalFlags: NoTabBar", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoTabBar);
14707+
ImGui::CheckboxFlags("LocalFlags: HiddenTabBar", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_HiddenTabBar);
14708+
ImGui::CheckboxFlags("LocalFlags: NoWindowMenuButton", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoWindowMenuButton);
14709+
ImGui::CheckboxFlags("LocalFlags: NoCloseButton", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoCloseButton);
1470714710
ImGui::TreePop();
1470814711
}
1470914712
if (node->ChildNodes[0])

imgui_internal.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -884,18 +884,20 @@ struct ImGuiTabBarRef
884884
ImGuiTabBarRef(int index_in_main_pool) { Ptr = NULL; IndexInMainPool = index_in_main_pool; }
885885
};
886886

887+
// Extend ImGuiDockNodeFlags_
887888
enum ImGuiDockNodeFlagsPrivate_
888889
{
889890
// [Internal]
890-
ImGuiDockNodeFlags_DockSpace = 1 << 10, // Local // A dockspace is a node that occupy space within an existing user window. Otherwise the node is floating and create its own window.
891-
ImGuiDockNodeFlags_CentralNode = 1 << 11, // Local
892-
ImGuiDockNodeFlags_NoTabBar = 1 << 12, // Local // Tab bar is completely unavailable. No triangle in the corner to enable it back.
893-
ImGuiDockNodeFlags_HiddenTabBar = 1 << 13, // Local // Tab bar is hidden, with a triangle in the corner to show it again (NB: actual tab-bar instance may be destroyed as this is only used for single-window tab bar)
894-
ImGuiDockNodeFlags_NoWindowMenuButton = 1 << 14, // Local // Disable window/docking menu (that one that appears instead of the collapse button)
895-
ImGuiDockNodeFlags_NoCloseButton = 1 << 15, // Local
891+
ImGuiDockNodeFlags_DockSpace = 1 << 10, // Local, Saved // A dockspace is a node that occupy space within an existing user window. Otherwise the node is floating and create its own window.
892+
ImGuiDockNodeFlags_CentralNode = 1 << 11, // Local, Saved //
893+
ImGuiDockNodeFlags_NoTabBar = 1 << 12, // Local, Saved // Tab bar is completely unavailable. No triangle in the corner to enable it back.
894+
ImGuiDockNodeFlags_HiddenTabBar = 1 << 13, // Local, Saved // Tab bar is hidden, with a triangle in the corner to show it again (NB: actual tab-bar instance may be destroyed as this is only used for single-window tab bar)
895+
ImGuiDockNodeFlags_NoWindowMenuButton = 1 << 14, // Local, Saved // Disable window/docking menu (that one that appears instead of the collapse button)
896+
ImGuiDockNodeFlags_NoCloseButton = 1 << 15, // Local, Saved //
896897
ImGuiDockNodeFlags_SharedFlagsInheritMask_ = ~0,
897898
ImGuiDockNodeFlags_LocalFlagsMask_ = ImGuiDockNodeFlags_NoSplit | ImGuiDockNodeFlags_NoResize | ImGuiDockNodeFlags_AutoHideTabBar | ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton,
898-
ImGuiDockNodeFlags_LocalFlagsTransferMask_ = ImGuiDockNodeFlags_LocalFlagsMask_ & ~ImGuiDockNodeFlags_DockSpace // When splitting those flags are moved to the inheriting child, never duplicated
899+
ImGuiDockNodeFlags_LocalFlagsTransferMask_ = ImGuiDockNodeFlags_LocalFlagsMask_ & ~ImGuiDockNodeFlags_DockSpace, // When splitting those flags are moved to the inheriting child, never duplicated
900+
ImGuiDockNodeFlags_SavedFlagsMask_ = ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton
899901
};
900902

901903
// Store the source authority (dock node vs window) of a field

0 commit comments

Comments
 (0)