From dc0aa61a14e59ef076ba0cc0c9977f60b59840f0 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 9 May 2024 22:14:08 -0500 Subject: [PATCH] Add scrollbar colors to `Panel` --- Source/Engine/UI/GUI/Panels/Panel.cs | 78 ++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/Source/Engine/UI/GUI/Panels/Panel.cs b/Source/Engine/UI/GUI/Panels/Panel.cs index 8c90b6544..8ae178c0f 100644 --- a/Source/Engine/UI/GUI/Panels/Panel.cs +++ b/Source/Engine/UI/GUI/Panels/Panel.cs @@ -17,6 +17,9 @@ namespace FlaxEngine.GUI private ScrollBars _scrollBars; private float _scrollBarsSize = ScrollBar.DefaultSize; private Margin _scrollMargin; + private Color _scrollbarTrackColor; + private Color _scrollbarThumbColor; + private Color _scrollbarThumbSelectedColor; /// /// The cached scroll area bounds. Used to scroll contents of the panel control. Cached during performing layout. @@ -49,7 +52,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the scroll bars usage by this panel. /// - [EditorOrder(0), Tooltip("The scroll bars usage.")] + [EditorDisplay("Scrollbar Style"), EditorOrder(0), Tooltip("The scroll bars usage.")] public ScrollBars ScrollBars { get => _scrollBars; @@ -73,6 +76,12 @@ namespace FlaxEngine.GUI //VScrollBar.X += VScrollBar.Width; VScrollBar.ValueChanged += () => SetViewOffset(Orientation.Vertical, VScrollBar.Value); } + if (VScrollBar != null) + { + VScrollBar.TrackColor = _scrollbarTrackColor; + VScrollBar.ThumbColor = _scrollbarThumbColor; + VScrollBar.ThumbSelectedColor = _scrollbarThumbSelectedColor; + } } else if (VScrollBar != null) { @@ -94,6 +103,12 @@ namespace FlaxEngine.GUI //HScrollBar.Offsets += new Margin(0, 0, HScrollBar.Height * 0.5f, 0); HScrollBar.ValueChanged += () => SetViewOffset(Orientation.Horizontal, HScrollBar.Value); } + if (HScrollBar != null) + { + HScrollBar.TrackColor = _scrollbarTrackColor; + HScrollBar.ThumbColor = _scrollbarThumbColor; + HScrollBar.ThumbSelectedColor = _scrollbarThumbSelectedColor; + } } else if (HScrollBar != null) { @@ -108,7 +123,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the size of the scroll bars. /// - [EditorOrder(5), Tooltip("Scroll bars size.")] + [EditorDisplay("Scrollbar Style"), EditorOrder(5), Tooltip("Scroll bars size.")] public float ScrollBarsSize { get => _scrollBarsSize; @@ -124,7 +139,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets a value indicating whether always show scrollbars. Otherwise show them only if scrolling is available. /// - [EditorOrder(10), Tooltip("Whether always show scrollbars. Otherwise show them only if scrolling is available.")] + [EditorDisplay("Scrollbar Style"), EditorOrder(10), Tooltip("Whether always show scrollbars. Otherwise show them only if scrolling is available.")] public bool AlwaysShowScrollbars { get => _alwaysShowScrollbars; @@ -157,7 +172,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the scroll margin applies to the child controls area. Can be used to expand the scroll area bounds by adding a margin. /// - [EditorOrder(20), Tooltip("Scroll margin applies to the child controls area. Can be used to expand the scroll area bounds by adding a margin.")] + [EditorDisplay("Scrollbar Style"), EditorOrder(20), Tooltip("Scroll margin applies to the child controls area. Can be used to expand the scroll area bounds by adding a margin.")] public Margin ScrollMargin { get => _scrollMargin; @@ -171,6 +186,57 @@ namespace FlaxEngine.GUI } } + /// + /// The color of the scroll bar track. + /// + [EditorDisplay("Scrollbar Style"), EditorOrder(30), ExpandGroups] + public Color ScrollbarTrackColor + { + get => _scrollbarTrackColor; + set + { + _scrollbarTrackColor = value; + if (VScrollBar != null) + VScrollBar.TrackColor = _scrollbarTrackColor; + if (HScrollBar != null) + HScrollBar.TrackColor = _scrollbarTrackColor; + } + } + + /// + /// The color of the scroll bar thumb. + /// + [EditorDisplay("Scrollbar Style"), EditorOrder(31)] + public Color ScrollbarThumbColor + { + get => _scrollbarThumbColor; + set + { + _scrollbarThumbColor = value; + if (VScrollBar != null) + VScrollBar.ThumbColor = _scrollbarThumbColor; + if (HScrollBar != null) + HScrollBar.ThumbColor = _scrollbarThumbColor; + } + } + + /// + /// The color of the scroll bar thumb when selected. + /// + [EditorDisplay("Scrollbar Style"), EditorOrder(32)] + public Color ScrollbarThumbSelectedColor + { + get => _scrollbarThumbSelectedColor; + set + { + _scrollbarThumbSelectedColor = value; + if (VScrollBar != null) + VScrollBar.ThumbSelectedColor = _scrollbarThumbSelectedColor; + if (HScrollBar != null) + HScrollBar.ThumbSelectedColor = _scrollbarThumbSelectedColor; + } + } + /// /// Initializes a new instance of the class. /// @@ -187,6 +253,10 @@ namespace FlaxEngine.GUI public Panel(ScrollBars scrollBars, bool autoFocus = false) { AutoFocus = autoFocus; + var style = Style.Current; + _scrollbarTrackColor = style.BackgroundHighlighted; + _scrollbarThumbColor = style.BackgroundNormal; + _scrollbarThumbSelectedColor = style.BackgroundSelected; ScrollBars = scrollBars; }