From 2dcd4e1cdb427a06c98fac88c7f58efe3e2dc063 Mon Sep 17 00:00:00 2001 From: Eideren Date: Wed, 11 Jun 2025 17:32:42 +0200 Subject: [PATCH] feat: UI Button color --- sources/engine/Stride.UI/Controls/Button.cs | 9 +++++++++ sources/engine/Stride.UI/Controls/ImageElement.cs | 2 +- sources/engine/Stride.UI/Controls/ToggleButton.cs | 10 ++++++++++ .../Stride.UI/Renderers/DefaultButtonRenderer.cs | 2 +- .../Stride.UI/Renderers/DefaultToggleButtonRenderer.cs | 2 +- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/sources/engine/Stride.UI/Controls/Button.cs b/sources/engine/Stride.UI/Controls/Button.cs index c117f323be..a82d2d5cf0 100644 --- a/sources/engine/Stride.UI/Controls/Button.cs +++ b/sources/engine/Stride.UI/Controls/Button.cs @@ -109,6 +109,15 @@ public ISpriteProvider MouseOverImage } } + /// + /// Gets or set the color used to tint the image. Default value is White. + /// + /// The initial image color is multiplied by this color. + /// The color used to tint the image. The default value is white. + [DataMember] + [Display(category: AppearanceCategory)] + public Color Color { get; set; } = Color.White; + /// /// Gets or sets a value that describes how the button image should be stretched to fill the destination rectangle. /// diff --git a/sources/engine/Stride.UI/Controls/ImageElement.cs b/sources/engine/Stride.UI/Controls/ImageElement.cs index 051b7007bc..d8a5270dfc 100644 --- a/sources/engine/Stride.UI/Controls/ImageElement.cs +++ b/sources/engine/Stride.UI/Controls/ImageElement.cs @@ -44,7 +44,7 @@ public ISpriteProvider Source } /// - /// Gets or set the color used to tint the image. Default value is White/>. + /// Gets or set the color used to tint the image. Default value is White. /// /// The initial image color is multiplied by this color. /// The color used to tint the image. The default value is white. diff --git a/sources/engine/Stride.UI/Controls/ToggleButton.cs b/sources/engine/Stride.UI/Controls/ToggleButton.cs index b266e07a83..04ef623f5a 100644 --- a/sources/engine/Stride.UI/Controls/ToggleButton.cs +++ b/sources/engine/Stride.UI/Controls/ToggleButton.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using Stride.Core; +using Stride.Core.Mathematics; using Stride.Engine; using Stride.UI.Attributes; using Stride.UI.Events; @@ -100,6 +101,15 @@ public ISpriteProvider IndeterminateImage } } + /// + /// Gets or set the color used to tint the image. Default value is White. + /// + /// The initial image color is multiplied by this color. + /// The color used to tint the image. The default value is white. + [DataMember] + [Display(category: AppearanceCategory)] + public Color Color { get; set; } = Color.White; + /// /// Determines whether the control supports two or three states. /// diff --git a/sources/engine/Stride.UI/Renderers/DefaultButtonRenderer.cs b/sources/engine/Stride.UI/Renderers/DefaultButtonRenderer.cs index c3e27d739a..04ae5a0bf8 100644 --- a/sources/engine/Stride.UI/Renderers/DefaultButtonRenderer.cs +++ b/sources/engine/Stride.UI/Renderers/DefaultButtonRenderer.cs @@ -26,7 +26,7 @@ public override void RenderColor(UIElement element, UIRenderingContext context) if (sprite?.Texture == null) return; - var color = element.RenderOpacity * Color.White; + var color = element.RenderOpacity * button.Color; Batch.DrawImage(sprite.Texture, ref element.WorldMatrixInternal, ref sprite.RegionInternal, ref element.RenderSizeInternal, ref sprite.BordersInternal, ref color, context.DepthBias, sprite.Orientation); } } diff --git a/sources/engine/Stride.UI/Renderers/DefaultToggleButtonRenderer.cs b/sources/engine/Stride.UI/Renderers/DefaultToggleButtonRenderer.cs index e3eb2304db..bedad30a41 100644 --- a/sources/engine/Stride.UI/Renderers/DefaultToggleButtonRenderer.cs +++ b/sources/engine/Stride.UI/Renderers/DefaultToggleButtonRenderer.cs @@ -29,7 +29,7 @@ public override void RenderColor(UIElement element, UIRenderingContext context) if (sprite?.Texture == null) return; - var color = toggleButton.RenderOpacity * Color.White; + var color = toggleButton.RenderOpacity * toggleButton.Color; Batch.DrawImage(sprite.Texture, ref element.WorldMatrixInternal, ref sprite.RegionInternal, ref element.RenderSizeInternal, ref sprite.BordersInternal, ref color, context.DepthBias, sprite.Orientation); }