Fix Content Window navigation bar to expand toolstrip for proper scroll bar display
#3326
This commit is contained in:
@@ -11,6 +11,9 @@ namespace FlaxEditor.GUI
|
||||
/// <seealso cref="FlaxEngine.GUI.Panel" />
|
||||
public class NavigationBar : Panel
|
||||
{
|
||||
private float _toolstripHeight = 0;
|
||||
private Margin _toolstripMargin;
|
||||
|
||||
/// <summary>
|
||||
/// The default buttons margin.
|
||||
/// </summary>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,15 +13,7 @@ namespace FlaxEditor.GUI
|
||||
/// <seealso cref="FlaxEngine.GUI.ContainerControl" />
|
||||
public class ToolStrip : ContainerControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The default margin vertically.
|
||||
/// </summary>
|
||||
public const int DefaultMarginV = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The default margin horizontally.
|
||||
/// </summary>
|
||||
public const int DefaultMarginH = 2;
|
||||
private Margin _itemsMargin;
|
||||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// Gets the height for the items.
|
||||
/// </summary>
|
||||
public float ItemsHeight => Height - 2 * DefaultMarginV;
|
||||
public float ItemsHeight => Height - _itemsMargin.Height;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ToolStrip"/> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnInit()
|
||||
{
|
||||
@@ -1200,9 +1215,9 @@ namespace FlaxEditor.Windows
|
||||
/// <inheritdoc />
|
||||
protected override void PerformLayoutBeforeChildren()
|
||||
{
|
||||
base.PerformLayoutBeforeChildren();
|
||||
UpdateNavigationBarBounds();
|
||||
|
||||
_navigationBar?.UpdateBounds(_toolStrip);
|
||||
base.PerformLayoutBeforeChildren();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user