From a7016d11867f4ed022234cd0d25c395f84eb52a0 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Mon, 26 Jan 2026 21:56:30 -0600 Subject: [PATCH] Fix issue with tabs not collapsing panel 1 if no tabs on panel 1 --- Source/Editor/GUI/Docking/DockPanel.cs | 51 +++++++++++++++++++++++++- Source/Editor/Modules/WindowsModule.cs | 5 +++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/Source/Editor/GUI/Docking/DockPanel.cs b/Source/Editor/GUI/Docking/DockPanel.cs index bfac161f0..c8900dcba 100644 --- a/Source/Editor/GUI/Docking/DockPanel.cs +++ b/Source/Editor/GUI/Docking/DockPanel.cs @@ -469,7 +469,7 @@ namespace FlaxEditor.GUI.Docking var childPanels = _childPanels.ToArray(); if (childPanels.Length != 0) { - // Move tabs from child panels into this one + // Fallback: move tabs from child panels into this one. DockWindow selectedTab = null; foreach (var childPanel in childPanels) { @@ -490,7 +490,8 @@ namespace FlaxEditor.GUI.Docking { // Unlink splitter var splitterParent = splitter.Parent; - Assert.IsNotNull(splitterParent); + if (splitterParent == null) + return; splitter.Parent = null; // Move controls from second split panel to the split panel parent @@ -507,17 +508,63 @@ namespace FlaxEditor.GUI.Docking splitter.Dispose(); } } + else if (IsMaster && _childPanels.Count != 0) + { + if (TryCollapseSplitter(_tabsProxy?.Parent as Panel)) + return; + } else if (!IsMaster) { throw new InvalidOperationException(); } } + else if (_childPanels.Count != 0) + { + if (TryCollapseSplitter(_tabsProxy?.Parent as Panel)) + return; + } else if (!IsMaster) { throw new InvalidOperationException(); } } + internal bool CollapseEmptyTabsProxy() + { + if (TabsCount == 0 && ChildPanelsCount > 0) + { + return TryCollapseSplitter(_tabsProxy?.Parent as Panel); + } + return false; + } + + private bool TryCollapseSplitter(Panel removedPanelParent) + { + if (removedPanelParent == null) + return false; + if (!(removedPanelParent.Parent is SplitPanel tabsSplitter)) + return false; + + var splitterParent = tabsSplitter.Parent; + if (splitterParent == null) + return false; + tabsSplitter.Parent = null; + + var scrPanel = removedPanelParent == tabsSplitter.Panel2 ? tabsSplitter.Panel1 : tabsSplitter.Panel2; + var srcPanelChildrenCount = scrPanel.ChildrenCount; + for (int i = srcPanelChildrenCount - 1; i >= 0 && scrPanel.ChildrenCount > 0; i--) + { + scrPanel.GetChild(i).Parent = splitterParent; + } + Assert.IsTrue(scrPanel.ChildrenCount == 0); + Assert.IsTrue(splitterParent.ChildrenCount == srcPanelChildrenCount); + + tabsSplitter.Dispose(); + if (_tabsProxy != null && _tabsProxy.Parent == removedPanelParent) + _tabsProxy = null; + return true; + } + internal virtual void DockWindowInternal(DockState state, DockWindow window, bool autoSelect = true, float? splitterValue = null) { DockWindow(state, window, autoSelect, splitterValue); diff --git a/Source/Editor/Modules/WindowsModule.cs b/Source/Editor/Modules/WindowsModule.cs index 218394a3b..162fa3a40 100644 --- a/Source/Editor/Modules/WindowsModule.cs +++ b/Source/Editor/Modules/WindowsModule.cs @@ -491,10 +491,15 @@ namespace FlaxEditor.Modules Editor.LogWarning("Empty panel inside layout."); p.RemoveIt(); } + else + { + p.CollapseEmptyTabsProxy(); + } } } panel.SelectTab(selectedTab); + panel.CollapseEmptyTabsProxy(); } private static void SaveBounds(XmlWriter writer, Window win)