4
4
using Avalonia ;
5
5
using Avalonia . Controls ;
6
6
using Avalonia . Media ;
7
+ using Avalonia . Styling ;
7
8
8
9
namespace SourceGit . Views
9
10
{
10
11
public class ChangeStatusIcon : Control
11
12
{
12
13
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 ,
58
25
] ;
59
26
60
27
public static readonly StyledProperty < bool > IsUnstagedChangeProperty =
@@ -75,25 +42,32 @@ public Models.Change Change
75
42
set => SetValue ( ChangeProperty , value ) ;
76
43
}
77
44
45
+ public ChangeStatusIcon ( )
46
+ {
47
+ ActualThemeVariantChanged += ( _ , _ ) => InvalidateVisual ( ) ;
48
+ }
49
+
78
50
public override void Render ( DrawingContext context )
79
51
{
80
52
if ( Change == null || Bounds . Width <= 0 )
81
53
return ;
82
54
83
55
var typeface = new Typeface ( "fonts:SourceGit#JetBrains Mono" ) ;
84
56
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
93
66
{
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
+ } ;
97
71
98
72
var txt = new FormattedText (
99
73
indicator ,
0 commit comments