Add ScrollBarsSize to Panel

This commit is contained in:
Wojtek Figat
2021-08-23 16:51:01 +02:00
parent bbe9193686
commit 5b52e76fc9

View File

@@ -14,6 +14,7 @@ namespace FlaxEngine.GUI
private bool _alwaysShowScrollbars; private bool _alwaysShowScrollbars;
private int _layoutUpdateLock; private int _layoutUpdateLock;
private ScrollBars _scrollBars; private ScrollBars _scrollBars;
private float _scrollBarsSize = ScrollBar.DefaultSize;
private Margin _scrollMargin; private Margin _scrollMargin;
/// <summary> /// <summary>
@@ -64,7 +65,7 @@ namespace FlaxEngine.GUI
VScrollBar = GetChild<VScrollBar>(); VScrollBar = GetChild<VScrollBar>();
if (VScrollBar == null) if (VScrollBar == null)
{ {
VScrollBar = new VScrollBar(this, Width - ScrollBar.DefaultSize, Height) VScrollBar = new VScrollBar(this, Width - _scrollBarsSize, Height)
{ {
AnchorPreset = AnchorPresets.TopLeft AnchorPreset = AnchorPresets.TopLeft
}; };
@@ -84,7 +85,7 @@ namespace FlaxEngine.GUI
HScrollBar = GetChild<HScrollBar>(); HScrollBar = GetChild<HScrollBar>();
if (HScrollBar == null) if (HScrollBar == null)
{ {
HScrollBar = new HScrollBar(this, Height - ScrollBar.DefaultSize, Width) HScrollBar = new HScrollBar(this, Height - _scrollBarsSize, Width)
{ {
AnchorPreset = AnchorPresets.TopLeft AnchorPreset = AnchorPresets.TopLeft
}; };
@@ -103,6 +104,22 @@ namespace FlaxEngine.GUI
} }
} }
/// <summary>
/// Gets or sets the size of the scroll bars.
/// </summary>
[EditorOrder(5), Tooltip("Scroll bars size.")]
public float ScrollBarsSize
{
get => _scrollBarsSize;
set
{
if (Mathf.NearEqual(_scrollBarsSize, value))
return;
_scrollBarsSize = value;
PerformLayout();
}
}
/// <summary> /// <summary>
/// Gets or sets a value indicating whether always show scrollbars. Otherwise show them only if scrolling is available. /// Gets or sets a value indicating whether always show scrollbars. Otherwise show them only if scrolling is available.
/// </summary> /// </summary>
@@ -410,7 +427,7 @@ namespace FlaxEngine.GUI
if (VScrollBar != null) if (VScrollBar != null)
{ {
float height = Height; float height = Height;
bool vScrollEnabled = (controlsBounds.Bottom > height + 0.01f || controlsBounds.Y < 0.0f) && height > ScrollBar.DefaultSize; bool vScrollEnabled = (controlsBounds.Bottom > height + 0.01f || controlsBounds.Y < 0.0f) && height > _scrollBarsSize;
if (VScrollBar.Enabled != vScrollEnabled) if (VScrollBar.Enabled != vScrollEnabled)
{ {
@@ -432,12 +449,12 @@ namespace FlaxEngine.GUI
{ {
VScrollBar.SetScrollRange(scrollBounds.Top, Mathf.Max(Mathf.Max(0, scrollBounds.Top), scrollBounds.Height - height)); VScrollBar.SetScrollRange(scrollBounds.Top, Mathf.Max(Mathf.Max(0, scrollBounds.Top), scrollBounds.Height - height));
} }
VScrollBar.Bounds = new Rectangle(Width - ScrollBar.DefaultSize, 0, ScrollBar.DefaultSize, Height); VScrollBar.Bounds = new Rectangle(Width - _scrollBarsSize, 0, _scrollBarsSize, Height);
} }
if (HScrollBar != null) if (HScrollBar != null)
{ {
float width = Width; float width = Width;
bool hScrollEnabled = (controlsBounds.Right > width + 0.01f || controlsBounds.X < 0.0f) && width > ScrollBar.DefaultSize; bool hScrollEnabled = (controlsBounds.Right > width + 0.01f || controlsBounds.X < 0.0f) && width > _scrollBarsSize;
if (HScrollBar.Enabled != hScrollEnabled) if (HScrollBar.Enabled != hScrollEnabled)
{ {
@@ -459,7 +476,7 @@ namespace FlaxEngine.GUI
{ {
HScrollBar.SetScrollRange(scrollBounds.Left, Mathf.Max(Mathf.Max(0, scrollBounds.Left), scrollBounds.Width - width)); HScrollBar.SetScrollRange(scrollBounds.Left, Mathf.Max(Mathf.Max(0, scrollBounds.Left), scrollBounds.Width - width));
} }
HScrollBar.Bounds = new Rectangle(0, Height - ScrollBar.DefaultSize, Width - (VScrollBar != null && VScrollBar.Visible ? VScrollBar.Width : 0), ScrollBar.DefaultSize); HScrollBar.Bounds = new Rectangle(0, Height - _scrollBarsSize, Width - (VScrollBar != null && VScrollBar.Visible ? VScrollBar.Width : 0), _scrollBarsSize);
} }
} }