Skip to content

Commit d46aa64

Browse files
authored
feat: UI Button color (#2815)
1 parent 881ec7d commit d46aa64

5 files changed

Lines changed: 22 additions & 3 deletions

File tree

sources/engine/Stride.UI/Controls/Button.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ public ISpriteProvider MouseOverImage
109109
}
110110
}
111111

112+
/// <summary>
113+
/// Gets or set the color used to tint the image. Default value is White.
114+
/// </summary>
115+
/// <remarks>The initial image color is multiplied by this color.</remarks>
116+
/// <userdoc>The color used to tint the image. The default value is white.</userdoc>
117+
[DataMember]
118+
[Display(category: AppearanceCategory)]
119+
public Color Color { get; set; } = Color.White;
120+
112121
/// <summary>
113122
/// Gets or sets a value that describes how the button image should be stretched to fill the destination rectangle.
114123
/// </summary>

sources/engine/Stride.UI/Controls/ImageElement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ISpriteProvider Source
4444
}
4545

4646
/// <summary>
47-
/// Gets or set the color used to tint the image. Default value is White/>.
47+
/// Gets or set the color used to tint the image. Default value is White.
4848
/// </summary>
4949
/// <remarks>The initial image color is multiplied by this color.</remarks>
5050
/// <userdoc>The color used to tint the image. The default value is white.</userdoc>

sources/engine/Stride.UI/Controls/ToggleButton.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66

77
using Stride.Core;
8+
using Stride.Core.Mathematics;
89
using Stride.Engine;
910
using Stride.Graphics;
1011
using Stride.UI.Attributes;
@@ -194,6 +195,15 @@ internal ISpriteProvider ToggleButtonImageProvider
194195
/// </summary>
195196
internal Sprite ToggleButtonImage => ToggleButtonImageProvider?.GetSprite();
196197

198+
/// <summary>
199+
/// Gets or set the color used to tint the image. Default value is White.
200+
/// </summary>
201+
/// <remarks>The initial image color is multiplied by this color.</remarks>
202+
/// <userdoc>The color used to tint the image. The default value is white.</userdoc>
203+
[DataMember]
204+
[Display(category: AppearanceCategory)]
205+
public Color Color { get; set; } = Color.White;
206+
197207
/// <summary>
198208
/// Determines whether the control supports two or three states.
199209
/// </summary>

sources/engine/Stride.UI/Renderers/DefaultButtonRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override void RenderColor(UIElement element, UIRenderingContext context)
2626
if (sprite?.Texture == null)
2727
return;
2828

29-
var color = element.RenderOpacity * Color.White;
29+
var color = element.RenderOpacity * button.Color;
3030
Batch.DrawImage(sprite.Texture, ref element.WorldMatrixInternal, ref sprite.RegionInternal, ref element.RenderSizeInternal, ref sprite.BordersInternal, ref color, context.DepthBias, sprite.Orientation);
3131
}
3232
}

sources/engine/Stride.UI/Renderers/DefaultToggleButtonRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override void RenderColor(UIElement element, UIRenderingContext context)
2929
if (sprite?.Texture == null)
3030
return;
3131

32-
var color = toggleButton.RenderOpacity * Color.White;
32+
var color = toggleButton.RenderOpacity * toggleButton.Color;
3333
Batch.DrawImage(sprite.Texture, ref element.WorldMatrixInternal, ref sprite.RegionInternal, ref element.RenderSizeInternal, ref sprite.BordersInternal, ref color, context.DepthBias, sprite.Orientation);
3434
}
3535
}

0 commit comments

Comments
 (0)