Fix Content Window navigation bar to expand toolstrip for proper scroll bar display

#3326
This commit is contained in:
Wojtek Figat
2025-08-25 14:38:55 +02:00
parent 6fea9eefaa
commit b965ca6c8c
5 changed files with 83 additions and 20 deletions

View File

@@ -11,6 +11,9 @@ namespace FlaxEditor.GUI
/// <seealso cref="FlaxEngine.GUI.Panel" /> /// <seealso cref="FlaxEngine.GUI.Panel" />
public class NavigationBar : Panel public class NavigationBar : Panel
{ {
private float _toolstripHeight = 0;
private Margin _toolstripMargin;
/// <summary> /// <summary>
/// The default buttons margin. /// The default buttons margin.
/// </summary> /// </summary>
@@ -50,9 +53,42 @@ namespace FlaxEditor.GUI
{ {
if (toolstrip == null) if (toolstrip == null)
return; 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 lastToolstripButton = toolstrip.LastButton;
var parentSize = Parent.Size; var parentSize = Parent.Size;
Bounds = new Rectangle(lastToolstripButton.Right + 8.0f, 0, parentSize.X - X - 8.0f, toolstrip.Height); Bounds = new Rectangle(lastToolstripButton.Right + 8.0f, 0, parentSize.X - X - 8.0f, toolstrip.Height);
} }
/// <inheritdoc />
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;
}
} }
} }

View File

@@ -13,15 +13,7 @@ namespace FlaxEditor.GUI
/// <seealso cref="FlaxEngine.GUI.ContainerControl" /> /// <seealso cref="FlaxEngine.GUI.ContainerControl" />
public class ToolStrip : ContainerControl public class ToolStrip : ContainerControl
{ {
/// <summary> private Margin _itemsMargin;
/// The default margin vertically.
/// </summary>
public const int DefaultMarginV = 1;
/// <summary>
/// The default margin horizontally.
/// </summary>
public const int DefaultMarginH = 2;
/// <summary> /// <summary>
/// Event fired when button gets clicked with the primary mouse button. /// Event fired when button gets clicked with the primary mouse button.
@@ -66,10 +58,26 @@ namespace FlaxEditor.GUI
} }
} }
/// <summary>
/// Gets or sets the space around items.
/// </summary>
public Margin ItemsMargin
{
get => _itemsMargin;
set
{
if (_itemsMargin != value)
{
_itemsMargin = value;
PerformLayout();
}
}
}
/// <summary> /// <summary>
/// Gets the height for the items. /// Gets the height for the items.
/// </summary> /// </summary>
public float ItemsHeight => Height - 2 * DefaultMarginV; public float ItemsHeight => Height - _itemsMargin.Height;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ToolStrip"/> class. /// Initializes a new instance of the <see cref="ToolStrip"/> class.
@@ -82,6 +90,7 @@ namespace FlaxEditor.GUI
AnchorPreset = AnchorPresets.HorizontalStretchTop; AnchorPreset = AnchorPresets.HorizontalStretchTop;
BackgroundColor = Style.Current.LightBackground; BackgroundColor = Style.Current.LightBackground;
Offsets = new Margin(0, 0, y, height * Editor.Instance.Options.Options.Interface.IconsScale); Offsets = new Margin(0, 0, y, height * Editor.Instance.Options.Options.Interface.IconsScale);
_itemsMargin = new Margin(2, 2, 1, 1);
} }
/// <summary> /// <summary>
@@ -161,7 +170,7 @@ namespace FlaxEditor.GUI
protected override void PerformLayoutBeforeChildren() protected override void PerformLayoutBeforeChildren()
{ {
// Arrange controls // Arrange controls
float x = DefaultMarginH; float x = _itemsMargin.Left;
float h = ItemsHeight; float h = ItemsHeight;
for (int i = 0; i < _children.Count; i++) for (int i = 0; i < _children.Count; i++)
{ {
@@ -169,8 +178,8 @@ namespace FlaxEditor.GUI
if (c.Visible) if (c.Visible)
{ {
var w = c.Width; var w = c.Width;
c.Bounds = new Rectangle(x, DefaultMarginV, w, h); c.Bounds = new Rectangle(x, _itemsMargin.Top, w, h);
x += w + DefaultMarginH; x += w + _itemsMargin.Width;
} }
} }
} }

View File

@@ -543,11 +543,12 @@ namespace FlaxEditor.Surface
nodes.Add(context); nodes.Add(context);
context = context.Parent; context = context.Parent;
} }
float margin = 1;
float x = NavigationBar.DefaultButtonsMargin; 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--) 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(); button.PerformLayout();
x += button.Width + NavigationBar.DefaultButtonsMargin; x += button.Width + NavigationBar.DefaultButtonsMargin;
navigationBar.AddChild(button); navigationBar.AddChild(button);

View File

@@ -194,17 +194,18 @@ namespace FlaxEditor.Windows
nodes.Add(node); nodes.Add(node);
node = node.ParentNode; node = node.ParentNode;
} }
float margin = 1;
float x = NavigationBar.DefaultButtonsMargin; 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--) 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(); button.PerformLayout();
x += button.Width + NavigationBar.DefaultButtonsMargin; x += button.Width + NavigationBar.DefaultButtonsMargin;
_navigationBar.AddChild(button); _navigationBar.AddChild(button);
if (i > 0) if (i > 0)
{ {
var separator = new ContentNavigationSeparator(button, x, ToolStrip.DefaultMarginV, h); var separator = new ContentNavigationSeparator(button, x, margin, h);
separator.PerformLayout(); separator.PerformLayout();
x += separator.Width + NavigationBar.DefaultButtonsMargin; x += separator.Width + NavigationBar.DefaultButtonsMargin;
_navigationBar.AddChild(separator); _navigationBar.AddChild(separator);
@@ -215,6 +216,7 @@ namespace FlaxEditor.Windows
// Update // Update
_navigationBar.IsLayoutLocked = wasLayoutLocked; _navigationBar.IsLayoutLocked = wasLayoutLocked;
_navigationBar.PerformLayout(); _navigationBar.PerformLayout();
UpdateNavigationBarBounds();
} }
/// <summary> /// <summary>

View File

@@ -1016,6 +1016,21 @@ namespace FlaxEditor.Windows
_navigateUpButton.Enabled = folder != null && _tree.SelectedNode != _root; _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();
}
}
}
/// <inheritdoc /> /// <inheritdoc />
public override void OnInit() public override void OnInit()
{ {
@@ -1200,9 +1215,9 @@ namespace FlaxEditor.Windows
/// <inheritdoc /> /// <inheritdoc />
protected override void PerformLayoutBeforeChildren() protected override void PerformLayoutBeforeChildren()
{ {
base.PerformLayoutBeforeChildren(); UpdateNavigationBarBounds();
_navigationBar?.UpdateBounds(_toolStrip); base.PerformLayoutBeforeChildren();
} }
/// <inheritdoc /> /// <inheritdoc />