Add Background Brush to the control for more styling

#1898
This commit is contained in:
Wojtek Figat
2024-09-12 16:29:14 +02:00
parent c69beae81a
commit 51ee3de689

View File

@@ -81,6 +81,7 @@ namespace FlaxEngine.GUI
// Style // Style
private Color _backgroundColor = Color.Transparent; private Color _backgroundColor = Color.Transparent;
private IBrush _backgroundBrush = null;
// Tooltip // Tooltip
@@ -174,6 +175,25 @@ namespace FlaxEngine.GUI
set => _backgroundColor = value; set => _backgroundColor = value;
} }
/// <summary>
/// Gets or sets control background brush used to fill the contents. Uses Background Color property as tint color.
/// </summary>
[EditorDisplay("Background Style"), EditorOrder(2001)]
public IBrush BackgroundBrush
{
get => _backgroundBrush;
set
{
_backgroundBrush = value;
#if FLAX_EDITOR
// Auto-reset background color so brush is visible as it uses it for tint
if (value != null && _backgroundColor == Color.Transparent && FlaxEditor.CustomEditors.CustomEditor.IsSettingValue)
_backgroundColor = Color.White;
#endif
}
}
/// <summary> /// <summary>
/// Gets or sets the anchor preset used by the control anchors (based on <see cref="AnchorMin"/> and <see cref="AnchorMax"/>). /// Gets or sets the anchor preset used by the control anchors (based on <see cref="AnchorMin"/> and <see cref="AnchorMax"/>).
/// </summary> /// </summary>
@@ -416,9 +436,14 @@ namespace FlaxEngine.GUI
public virtual void Draw() public virtual void Draw()
{ {
// Paint Background // Paint Background
if (_backgroundColor.A > 0.0f) var rect = new Rectangle(Float2.Zero, _bounds.Size);
if (BackgroundBrush != null)
{ {
Render2D.FillRectangle(new Rectangle(Float2.Zero, Size), _backgroundColor); BackgroundBrush.Draw(rect, _backgroundColor);
}
else if (_backgroundColor.A > 0.0f)
{
Render2D.FillRectangle(rect, _backgroundColor);
} }
} }