From b965ca6c8cb0d2c2faca2174177096a91628d2f5 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 25 Aug 2025 14:38:55 +0200 Subject: [PATCH] Fix Content Window navigation bar to expand toolstrip for proper scroll bar display #3326 --- Source/Editor/GUI/NavigationBar.cs | 36 +++++++++++++++++++ Source/Editor/GUI/ToolStrip.cs | 35 +++++++++++------- Source/Editor/Surface/VisjectSurface.cs | 5 +-- .../Windows/ContentWindow.Navigation.cs | 8 +++-- Source/Editor/Windows/ContentWindow.cs | 19 ++++++++-- 5 files changed, 83 insertions(+), 20 deletions(-) diff --git a/Source/Editor/GUI/NavigationBar.cs b/Source/Editor/GUI/NavigationBar.cs index bedf4c070..eb87eaafc 100644 --- a/Source/Editor/GUI/NavigationBar.cs +++ b/Source/Editor/GUI/NavigationBar.cs @@ -11,6 +11,9 @@ namespace FlaxEditor.GUI /// public class NavigationBar : Panel { + private float _toolstripHeight = 0; + private Margin _toolstripMargin; + /// /// The default buttons margin. /// @@ -50,9 +53,42 @@ namespace FlaxEditor.GUI { if (toolstrip == null) return; + + if (_toolstripHeight <= 0.0f) + { + // Cache initial toolstrip state + _toolstripHeight = toolstrip.Height; + _toolstripMargin = toolstrip.ItemsMargin; + } + + // Control toolstrip bottom margin to prevent navigation bar scroll going over the buttons + var toolstripLocked = toolstrip.IsLayoutLocked; + toolstrip.IsLayoutLocked = true; + var toolstripHeight = _toolstripHeight; + var toolstripMargin = _toolstripMargin; + if (HScrollBar.Visible) + { + float scrollMargin = 8; + toolstripHeight += scrollMargin; + toolstripMargin.Bottom += scrollMargin; + } + toolstrip.Height = toolstripHeight; + toolstrip.IsLayoutLocked = toolstripLocked; + toolstrip.ItemsMargin = toolstripMargin; + var lastToolstripButton = toolstrip.LastButton; var parentSize = Parent.Size; Bounds = new Rectangle(lastToolstripButton.Right + 8.0f, 0, parentSize.X - X - 8.0f, toolstrip.Height); } + + /// + public override void PerformLayout(bool force = false) + { + base.PerformLayout(force); + + // Stretch excluding toolstrip margin to fill the space + if (Parent is ToolStrip toolStrip) + Height = toolStrip.Height; + } } } diff --git a/Source/Editor/GUI/ToolStrip.cs b/Source/Editor/GUI/ToolStrip.cs index 09f61b71d..eeba67cde 100644 --- a/Source/Editor/GUI/ToolStrip.cs +++ b/Source/Editor/GUI/ToolStrip.cs @@ -13,15 +13,7 @@ namespace FlaxEditor.GUI /// public class ToolStrip : ContainerControl { - /// - /// The default margin vertically. - /// - public const int DefaultMarginV = 1; - - /// - /// The default margin horizontally. - /// - public const int DefaultMarginH = 2; + private Margin _itemsMargin; /// /// Event fired when button gets clicked with the primary mouse button. @@ -66,10 +58,26 @@ namespace FlaxEditor.GUI } } + /// + /// Gets or sets the space around items. + /// + public Margin ItemsMargin + { + get => _itemsMargin; + set + { + if (_itemsMargin != value) + { + _itemsMargin = value; + PerformLayout(); + } + } + } + /// /// Gets the height for the items. /// - public float ItemsHeight => Height - 2 * DefaultMarginV; + public float ItemsHeight => Height - _itemsMargin.Height; /// /// Initializes a new instance of the class. @@ -82,6 +90,7 @@ namespace FlaxEditor.GUI AnchorPreset = AnchorPresets.HorizontalStretchTop; BackgroundColor = Style.Current.LightBackground; Offsets = new Margin(0, 0, y, height * Editor.Instance.Options.Options.Interface.IconsScale); + _itemsMargin = new Margin(2, 2, 1, 1); } /// @@ -161,7 +170,7 @@ namespace FlaxEditor.GUI protected override void PerformLayoutBeforeChildren() { // Arrange controls - float x = DefaultMarginH; + float x = _itemsMargin.Left; float h = ItemsHeight; for (int i = 0; i < _children.Count; i++) { @@ -169,8 +178,8 @@ namespace FlaxEditor.GUI if (c.Visible) { var w = c.Width; - c.Bounds = new Rectangle(x, DefaultMarginV, w, h); - x += w + DefaultMarginH; + c.Bounds = new Rectangle(x, _itemsMargin.Top, w, h); + x += w + _itemsMargin.Width; } } } diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs index 3bdad7eab..8cbcb4a21 100644 --- a/Source/Editor/Surface/VisjectSurface.cs +++ b/Source/Editor/Surface/VisjectSurface.cs @@ -543,11 +543,12 @@ namespace FlaxEditor.Surface nodes.Add(context); context = context.Parent; } + float margin = 1; float x = NavigationBar.DefaultButtonsMargin; - float h = toolStrip.ItemsHeight - 2 * ToolStrip.DefaultMarginV; + float h = toolStrip.ItemsHeight - 2 * margin; for (int i = nodes.Count - 1; i >= 0; i--) { - var button = new VisjectContextNavigationButton(this, nodes[i].Context, x, ToolStrip.DefaultMarginV, h); + var button = new VisjectContextNavigationButton(this, nodes[i].Context, x, margin, h); button.PerformLayout(); x += button.Width + NavigationBar.DefaultButtonsMargin; navigationBar.AddChild(button); diff --git a/Source/Editor/Windows/ContentWindow.Navigation.cs b/Source/Editor/Windows/ContentWindow.Navigation.cs index 1033db472..53dd6447b 100644 --- a/Source/Editor/Windows/ContentWindow.Navigation.cs +++ b/Source/Editor/Windows/ContentWindow.Navigation.cs @@ -194,17 +194,18 @@ namespace FlaxEditor.Windows nodes.Add(node); node = node.ParentNode; } + float margin = 1; float x = NavigationBar.DefaultButtonsMargin; - float h = _toolStrip.ItemsHeight - 2 * ToolStrip.DefaultMarginV; + float h = _toolStrip.ItemsHeight - 2 * margin; for (int i = nodes.Count - 1; i >= 0; i--) { - var button = new ContentNavigationButton(nodes[i], x, ToolStrip.DefaultMarginV, h); + var button = new ContentNavigationButton(nodes[i], x, margin, h); button.PerformLayout(); x += button.Width + NavigationBar.DefaultButtonsMargin; _navigationBar.AddChild(button); if (i > 0) { - var separator = new ContentNavigationSeparator(button, x, ToolStrip.DefaultMarginV, h); + var separator = new ContentNavigationSeparator(button, x, margin, h); separator.PerformLayout(); x += separator.Width + NavigationBar.DefaultButtonsMargin; _navigationBar.AddChild(separator); @@ -215,6 +216,7 @@ namespace FlaxEditor.Windows // Update _navigationBar.IsLayoutLocked = wasLayoutLocked; _navigationBar.PerformLayout(); + UpdateNavigationBarBounds(); } /// diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index cf33d0b63..3d2ec4a66 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -1016,6 +1016,21 @@ namespace FlaxEditor.Windows _navigateUpButton.Enabled = folder != null && _tree.SelectedNode != _root; } + private void UpdateNavigationBarBounds() + { + if (_navigationBar != null && _toolStrip != null) + { + var bottomPrev = _toolStrip.Bottom; + _navigationBar.UpdateBounds(_toolStrip); + if (bottomPrev != _toolStrip.Bottom) + { + // Navigation bar changed toolstrip height + _split.Offsets = new Margin(0, 0, _toolStrip.Bottom, 0); + PerformLayout(); + } + } + } + /// public override void OnInit() { @@ -1200,9 +1215,9 @@ namespace FlaxEditor.Windows /// protected override void PerformLayoutBeforeChildren() { - base.PerformLayoutBeforeChildren(); + UpdateNavigationBarBounds(); - _navigationBar?.UpdateBounds(_toolStrip); + base.PerformLayoutBeforeChildren(); } ///