Skip to content

Commit e28b537

Browse files
authored
enhance: darker ChangeStatusIcon when using dark theme (#1423)
1 parent ed66d23 commit e28b537

File tree

1 file changed

+30
-56
lines changed

1 file changed

+30
-56
lines changed

src/Views/ChangeStatusIcon.cs

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,24 @@
44
using Avalonia;
55
using Avalonia.Controls;
66
using Avalonia.Media;
7+
using Avalonia.Styling;
78

89
namespace SourceGit.Views
910
{
1011
public class ChangeStatusIcon : Control
1112
{
1213
private static readonly string[] INDICATOR = ["?", "±", "T", "+", "−", "➜", "❏", "★", "!"];
13-
private static readonly IBrush[] BACKGROUNDS = [
14-
Brushes.Transparent,
15-
new LinearGradientBrush
16-
{
17-
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(238, 160, 14), 0), new GradientStop(Color.FromRgb(228, 172, 67), 1) },
18-
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
19-
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
20-
},
21-
new LinearGradientBrush
22-
{
23-
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(238, 160, 14), 0), new GradientStop(Color.FromRgb(228, 172, 67), 1) },
24-
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
25-
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
26-
},
27-
new LinearGradientBrush
28-
{
29-
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(47, 185, 47), 0), new GradientStop(Color.FromRgb(75, 189, 75), 1) },
30-
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
31-
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
32-
},
33-
new LinearGradientBrush
34-
{
35-
GradientStops = new GradientStops() { new GradientStop(Colors.Tomato, 0), new GradientStop(Color.FromRgb(252, 165, 150), 1) },
36-
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
37-
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
38-
},
39-
new LinearGradientBrush
40-
{
41-
GradientStops = new GradientStops() { new GradientStop(Colors.Orchid, 0), new GradientStop(Color.FromRgb(248, 161, 245), 1) },
42-
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
43-
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
44-
},
45-
new LinearGradientBrush
46-
{
47-
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(238, 160, 14), 0), new GradientStop(Color.FromRgb(228, 172, 67), 1) },
48-
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
49-
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
50-
},
51-
new LinearGradientBrush
52-
{
53-
GradientStops = new GradientStops() { new GradientStop(Color.FromRgb(47, 185, 47), 0), new GradientStop(Color.FromRgb(75, 189, 75), 1) },
54-
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
55-
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
56-
},
57-
Brushes.OrangeRed,
14+
private static readonly Color[] COLOR =
15+
[
16+
Colors.Transparent,
17+
Colors.Goldenrod,
18+
Colors.Goldenrod,
19+
Colors.LimeGreen,
20+
Colors.Tomato,
21+
Colors.Orchid,
22+
Colors.Goldenrod,
23+
Colors.LimeGreen,
24+
Colors.OrangeRed,
5825
];
5926

6027
public static readonly StyledProperty<bool> IsUnstagedChangeProperty =
@@ -75,25 +42,32 @@ public Models.Change Change
7542
set => SetValue(ChangeProperty, value);
7643
}
7744

45+
public ChangeStatusIcon()
46+
{
47+
ActualThemeVariantChanged += (_, _) => InvalidateVisual();
48+
}
49+
7850
public override void Render(DrawingContext context)
7951
{
8052
if (Change == null || Bounds.Width <= 0)
8153
return;
8254

8355
var typeface = new Typeface("fonts:SourceGit#JetBrains Mono");
8456

85-
IBrush background;
86-
string indicator;
87-
if (IsUnstagedChange)
88-
{
89-
background = BACKGROUNDS[(int)Change.WorkTree];
90-
indicator = INDICATOR[(int)Change.WorkTree];
91-
}
92-
else
57+
var idx = (int)(IsUnstagedChange ? Change.WorkTree : Change.Index);
58+
var indicator = INDICATOR[idx];
59+
var color = COLOR[idx];
60+
var hsl = color.ToHsl();
61+
var color2 = ActualThemeVariant == ThemeVariant.Dark
62+
? new HslColor(hsl.A, hsl.H,hsl.S, hsl.L - 0.1).ToRgb()
63+
: new HslColor(hsl.A, hsl.H,hsl.S, hsl.L + 0.1).ToRgb();
64+
65+
var background = new LinearGradientBrush
9366
{
94-
background = BACKGROUNDS[(int)Change.Index];
95-
indicator = INDICATOR[(int)Change.Index];
96-
}
67+
GradientStops = [new GradientStop(color, 0), new GradientStop(color2, 1)],
68+
StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative),
69+
EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
70+
};
9771

9872
var txt = new FormattedText(
9973
indicator,

0 commit comments

Comments
 (0)