enhance: darker ChangeStatusIcon when using dark theme

This commit is contained in:
Nathan Baulch 2025-06-15 06:46:17 +10:00
parent 28844c59cf
commit 52bb6ae040

View file

@ -4,57 +4,24 @@ using System.Globalization;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Styling;
namespace SourceGit.Views namespace SourceGit.Views
{ {
public class ChangeStatusIcon : Control public class ChangeStatusIcon : Control
{ {
private static readonly string[] INDICATOR = ["?", "±", "T", "+", "", "➜", "❏", "★", "!"]; private static readonly string[] INDICATOR = ["?", "±", "T", "+", "", "➜", "❏", "★", "!"];
private static readonly IBrush[] BACKGROUNDS = [ private static readonly Color[] COLOR =
Brushes.Transparent, [
new LinearGradientBrush Colors.Transparent,
{ Colors.Goldenrod,
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(238, 160, 14), 0), new GradientStop(Color.FromRgb(228, 172, 67), 1) }, Colors.Goldenrod,
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative), Colors.LimeGreen,
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative), Colors.Tomato,
}, Colors.Orchid,
new LinearGradientBrush Colors.Goldenrod,
{ Colors.LimeGreen,
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(238, 160, 14), 0), new GradientStop(Color.FromRgb(228, 172, 67), 1) }, Colors.OrangeRed,
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
},
new LinearGradientBrush
{
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(47, 185, 47), 0), new GradientStop(Color.FromRgb(75, 189, 75), 1) },
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
},
new LinearGradientBrush
{
GradientStops = new GradientStops() { new GradientStop(Colors.Tomato, 0), new GradientStop(Color.FromRgb(252, 165, 150), 1) },
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
},
new LinearGradientBrush
{
GradientStops = new GradientStops() { new GradientStop(Colors.Orchid, 0), new GradientStop(Color.FromRgb(248, 161, 245), 1) },
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
},
new LinearGradientBrush
{
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(238, 160, 14), 0), new GradientStop(Color.FromRgb(228, 172, 67), 1) },
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
},
new LinearGradientBrush
{
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(47, 185, 47), 0), new GradientStop(Color.FromRgb(75, 189, 75), 1) },
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
},
Brushes.OrangeRed,
]; ];
public static readonly StyledProperty<bool> IsUnstagedChangeProperty = public static readonly StyledProperty<bool> IsUnstagedChangeProperty =
@ -75,6 +42,11 @@ namespace SourceGit.Views
set => SetValue(ChangeProperty, value); set => SetValue(ChangeProperty, value);
} }
public ChangeStatusIcon()
{
ActualThemeVariantChanged += (_, _) => InvalidateVisual();
}
public override void Render(DrawingContext context) public override void Render(DrawingContext context)
{ {
if (Change == null || Bounds.Width <= 0) if (Change == null || Bounds.Width <= 0)
@ -82,18 +54,20 @@ namespace SourceGit.Views
var typeface = new Typeface("fonts:SourceGit#JetBrains Mono"); var typeface = new Typeface("fonts:SourceGit#JetBrains Mono");
IBrush background; var idx = (int)(IsUnstagedChange ? Change.WorkTree : Change.Index);
string indicator; var indicator = INDICATOR[idx];
if (IsUnstagedChange) var color = COLOR[idx];
var hsl = color.ToHsl();
var color2 = ActualThemeVariant == ThemeVariant.Dark
? new HslColor(hsl.A, hsl.H,hsl.S, hsl.L - 0.1).ToRgb()
: new HslColor(hsl.A, hsl.H,hsl.S, hsl.L + 0.1).ToRgb();
var background = new LinearGradientBrush
{ {
background = BACKGROUNDS[(int)Change.WorkTree]; GradientStops = [new GradientStop(color, 0), new GradientStop(color2, 1)],
indicator = INDICATOR[(int)Change.WorkTree]; StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
} EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
else };
{
background = BACKGROUNDS[(int)Change.Index];
indicator = INDICATOR[(int)Change.Index];
}
var txt = new FormattedText( var txt = new FormattedText(
indicator, indicator,