@ -9868,6 +9868,14 @@ static int IMGUI_CDECL DockNodeComparerDepthMostFirst(const void* lhs, const voi
return ImGui : : DockNodeGetDepth ( b ) - ImGui : : DockNodeGetDepth ( a ) ;
return ImGui : : DockNodeGetDepth ( b ) - ImGui : : DockNodeGetDepth ( a ) ;
}
}
// Pre C++0x doesn't allow us to use a local type (without linkage) as template parameter, so we moved this here.
struct ImGuiDockContextPruneNodeData
{
int CountWindows , CountChildWindows , CountChildNodes ;
ImGuiID RootID ;
ImGuiDockContextPruneNodeData ( ) { CountWindows = CountChildWindows = CountChildNodes = 0 ; RootID = 0 ; }
} ;
// Garbage collect unused nodes (run once at init time)
// Garbage collect unused nodes (run once at init time)
static void ImGui : : DockContextPruneUnusedSettingsNodes ( ImGuiContext * ctx )
static void ImGui : : DockContextPruneUnusedSettingsNodes ( ImGuiContext * ctx )
{
{
@ -9875,20 +9883,14 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx)
ImGuiDockContext * dc = ctx - > DockContext ;
ImGuiDockContext * dc = ctx - > DockContext ;
IM_ASSERT ( g . Windows . Size = = 0 ) ;
IM_ASSERT ( g . Windows . Size = = 0 ) ;
struct NodeData
ImPool < ImGuiDockContextPruneNodeData > pool ;
{
int CountWindows , CountChildWindows , CountChildNodes ;
ImGuiID RootID ;
NodeData ( ) { CountWindows = CountChildWindows = CountChildNodes = 0 ; RootID = 0 ; }
} ;
ImPool < NodeData > pool ;
pool . Reserve ( dc - > SettingsNodes . Size ) ;
pool . Reserve ( dc - > SettingsNodes . Size ) ;
// Count child nodes and compute RootID
// Count child nodes and compute RootID
for ( int settings_n = 0 ; settings_n < dc - > SettingsNodes . Size ; settings_n + + )
for ( int settings_n = 0 ; settings_n < dc - > SettingsNodes . Size ; settings_n + + )
{
{
ImGuiDockNodeSettings * settings = & dc - > SettingsNodes [ settings_n ] ;
ImGuiDockNodeSettings * settings = & dc - > SettingsNodes [ settings_n ] ;
NodeData* parent_data = settings - > ParentID ? pool . GetByKey ( settings - > ParentID ) : 0 ;
ImGuiDockContextPrune NodeData* parent_data = settings - > ParentID ? pool . GetByKey ( settings - > ParentID ) : 0 ;
pool . GetOrAddByKey ( settings - > ID ) - > RootID = parent_data ? parent_data - > RootID : settings - > ID ;
pool . GetOrAddByKey ( settings - > ID ) - > RootID = parent_data ? parent_data - > RootID : settings - > ID ;
if ( settings - > ParentID )
if ( settings - > ParentID )
pool . GetOrAddByKey ( settings - > ParentID ) - > CountChildNodes + + ;
pool . GetOrAddByKey ( settings - > ParentID ) - > CountChildNodes + + ;
@ -9897,9 +9899,9 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx)
// Count reference to dock ids from window settings
// Count reference to dock ids from window settings
for ( int settings_n = 0 ; settings_n < g . SettingsWindows . Size ; settings_n + + )
for ( int settings_n = 0 ; settings_n < g . SettingsWindows . Size ; settings_n + + )
if ( ImGuiID dock_id = g . SettingsWindows [ settings_n ] . DockId )
if ( ImGuiID dock_id = g . SettingsWindows [ settings_n ] . DockId )
if ( NodeData* data = pool . GetByKey ( dock_id ) )
if ( ImGuiDockContextPrune NodeData* data = pool . GetByKey ( dock_id ) )
{
{
NodeData* data_root = ( data - > RootID = = dock_id ) ? data : pool . GetByKey ( data - > RootID ) ;
ImGuiDockContextPrune NodeData* data_root = ( data - > RootID = = dock_id ) ? data : pool . GetByKey ( data - > RootID ) ;
data - > CountWindows + + ;
data - > CountWindows + + ;
data_root - > CountChildWindows + + ;
data_root - > CountChildWindows + + ;
}
}
@ -9908,10 +9910,10 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx)
for ( int settings_n = 0 ; settings_n < dc - > SettingsNodes . Size ; settings_n + + )
for ( int settings_n = 0 ; settings_n < dc - > SettingsNodes . Size ; settings_n + + )
{
{
ImGuiDockNodeSettings * settings = & dc - > SettingsNodes [ settings_n ] ;
ImGuiDockNodeSettings * settings = & dc - > SettingsNodes [ settings_n ] ;
NodeData* data = pool . GetByKey ( settings - > ID ) ;
ImGuiDockContextPrune NodeData* data = pool . GetByKey ( settings - > ID ) ;
if ( data - > CountWindows > 1 )
if ( data - > CountWindows > 1 )
continue ;
continue ;
NodeData* data_root = ( data - > RootID = = settings - > ID ) ? data : pool . GetByKey ( data - > RootID ) ;
ImGuiDockContextPrune NodeData* data_root = ( data - > RootID = = settings - > ID ) ? data : pool . GetByKey ( data - > RootID ) ;
bool remove = false ;
bool remove = false ;
remove | = ( data - > CountWindows = = 1 & & settings - > ParentID = = 0 & & data - > CountChildNodes = = 0 & & ! settings - > IsDocumentRoot ) ; // Floating root node with only 1 window
remove | = ( data - > CountWindows = = 1 & & settings - > ParentID = = 0 & & data - > CountChildNodes = = 0 & & ! settings - > IsDocumentRoot ) ; // Floating root node with only 1 window