-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathThemeManager.cs
More file actions
250 lines (236 loc) · 12.1 KB
/
ThemeManager.cs
File metadata and controls
250 lines (236 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
using Avalonia;
using Avalonia.Media;
using System;
namespace ShowWrite
{
public enum ThemeType
{
Dark,
Light,
LightMinimal,
NoBackground
}
public class ThemeColors
{
public string Name { get; set; } = "";
public Color Background { get; set; }
public Color Surface { get; set; }
public Color SurfaceVariant { get; set; }
public Color Primary { get; set; }
public Color PrimaryHover { get; set; }
public Color TextPrimary { get; set; }
public Color TextSecondary { get; set; }
public Color TextTertiary { get; set; }
public Color Border { get; set; }
public Color HoverBackground { get; set; }
public Color PressedBackground { get; set; }
public Color Danger { get; set; }
public Color DangerHover { get; set; }
public Color IconColor { get; set; }
public Color IconColorChecked { get; set; }
public Color VideoBackground { get; set; }
public bool ShowButtonText { get; set; } = true;
public double IconSize { get; set; } = 28;
public double ButtonSize { get; set; } = 56;
public double ButtonGroupCornerRadius { get; set; } = 12;
public bool ShowButtonShadow { get; set; } = false;
public double SliderIndicatorSize { get; set; } = 56;
public double SliderIndicatorCornerRadius { get; set; } = 8;
public double ButtonCornerRadius { get; set; } = 8;
public double ButtonPadding { get; set; } = 4;
public double ButtonGroupPadding { get; set; } = 8;
public bool ShowButtonGroupBackground { get; set; } = true;
}
public static class ThemeManager
{
public static readonly ThemeColors DarkTheme = new ThemeColors
{
Name = "深色",
Background = Color.Parse("#1E1E1E"),
Surface = Color.Parse("#2D2D2D"),
SurfaceVariant = Color.Parse("#3D3D3D"),
Primary = Color.Parse("#0078D4"),
PrimaryHover = Color.Parse("#1E90FF"),
TextPrimary = Colors.White,
TextSecondary = Color.Parse("#CCCCCC"),
TextTertiary = Color.Parse("#888888"),
Border = Color.Parse("#555555"),
HoverBackground = Color.Parse("#3D3D3D"),
PressedBackground = Color.Parse("#555555"),
Danger = Color.Parse("#E53935"),
DangerHover = Color.Parse("#EF5350"),
IconColor = Colors.White,
IconColorChecked = Colors.White,
VideoBackground = Colors.Black,
ShowButtonText = true,
IconSize = 28,
ButtonSize = 56,
ButtonGroupCornerRadius = 12,
ShowButtonShadow = false
};
public static readonly ThemeColors LightTheme = new ThemeColors
{
Name = "浅色",
Background = Color.Parse("#F5F5F5"),
Surface = Color.Parse("#FFFFFF"),
SurfaceVariant = Color.Parse("#E8E8E8"),
Primary = Color.Parse("#0078D4"),
PrimaryHover = Color.Parse("#1E90FF"),
TextPrimary = Color.Parse("#1E1E1E"),
TextSecondary = Color.Parse("#555555"),
TextTertiary = Color.Parse("#888888"),
Border = Color.Parse("#CCCCCC"),
HoverBackground = Color.Parse("#E8E8E8"),
PressedBackground = Color.Parse("#D0D0D0"),
Danger = Color.Parse("#E53935"),
DangerHover = Color.Parse("#EF5350"),
IconColor = Color.Parse("#1E1E1E"),
IconColorChecked = Colors.White,
VideoBackground = Colors.White,
ShowButtonText = true,
IconSize = 28,
ButtonSize = 56,
ButtonGroupCornerRadius = 12,
ShowButtonShadow = false
};
public static readonly ThemeColors LightMinimalTheme = new ThemeColors
{
Name = "白色-简约",
Background = Color.Parse("#F5F5F5"),
Surface = Color.Parse("#FFFFFF"),
SurfaceVariant = Color.Parse("#E8E8E8"),
Primary = Color.Parse("#0078D4"),
PrimaryHover = Color.Parse("#1E90FF"),
TextPrimary = Color.Parse("#1E1E1E"),
TextSecondary = Color.Parse("#555555"),
TextTertiary = Color.Parse("#888888"),
Border = Color.Parse("#CCCCCC"),
HoverBackground = Color.Parse("#E8E8E8"),
PressedBackground = Color.Parse("#D0D0D0"),
Danger = Color.Parse("#E53935"),
DangerHover = Color.Parse("#EF5350"),
IconColor = Color.Parse("#1E1E1E"),
IconColorChecked = Colors.White,
VideoBackground = Colors.White,
ShowButtonText = false,
IconSize = 26,
ButtonSize = 44,
ButtonGroupCornerRadius = 22,
ShowButtonShadow = true,
SliderIndicatorSize = 44,
SliderIndicatorCornerRadius = 22,
ButtonCornerRadius = 22,
ButtonPadding = 2,
ButtonGroupPadding = 12
};
public static readonly ThemeColors NoBackgroundTheme = new ThemeColors
{
Name = "我眼不瞎",
Background = Color.Parse("#F5F5F5"),
Surface = Color.Parse("#00000000"),
SurfaceVariant = Color.Parse("#00000000"),
Primary = Color.Parse("#00000000"),
PrimaryHover = Color.Parse("#00000000"),
TextPrimary = Color.Parse("#1E1E1E"),
TextSecondary = Color.Parse("#555555"),
TextTertiary = Color.Parse("#888888"),
Border = Color.Parse("#00000000"),
HoverBackground = Color.Parse("#00000000"),
PressedBackground = Color.Parse("#00000000"),
Danger = Color.Parse("#E53935"),
DangerHover = Color.Parse("#EF5350"),
IconColor = Color.Parse("#808080"),
IconColorChecked = Color.Parse("#808080"),
VideoBackground = Colors.White,
ShowButtonText = false,
IconSize = 28,
ButtonSize = 56,
ButtonGroupCornerRadius = 0,
ShowButtonShadow = true,
SliderIndicatorSize = 44,
SliderIndicatorCornerRadius = 22,
ButtonCornerRadius = 8,
ButtonPadding = 4,
ButtonGroupPadding = 0,
ShowButtonGroupBackground = false
};
private static ThemeType _currentTheme = ThemeType.Dark;
public static ThemeType CurrentTheme => _currentTheme;
public static ThemeColors CurrentColors => _currentTheme switch
{
ThemeType.Light => LightTheme,
ThemeType.LightMinimal => LightMinimalTheme,
ThemeType.NoBackground => NoBackgroundTheme,
_ => DarkTheme
};
public static event Action<ThemeType>? ThemeChanged;
public static void SetTheme(ThemeType theme)
{
if (_currentTheme == theme) return;
_currentTheme = theme;
ThemeChanged?.Invoke(theme);
}
public static void ApplyTheme(Application app, ThemeType theme)
{
_currentTheme = theme;
var colors = CurrentColors;
app.Resources["ThemeBackground"] = new SolidColorBrush(colors.Background);
app.Resources["ThemeSurface"] = new SolidColorBrush(colors.Surface);
app.Resources["ThemeSurfaceVariant"] = new SolidColorBrush(colors.SurfaceVariant);
app.Resources["ThemePrimary"] = new SolidColorBrush(colors.Primary);
app.Resources["ThemePrimaryHover"] = new SolidColorBrush(colors.PrimaryHover);
app.Resources["ThemeTextPrimary"] = new SolidColorBrush(colors.TextPrimary);
app.Resources["ThemeTextSecondary"] = new SolidColorBrush(colors.TextSecondary);
app.Resources["ThemeTextTertiary"] = new SolidColorBrush(colors.TextTertiary);
app.Resources["ThemeBorder"] = new SolidColorBrush(colors.Border);
app.Resources["ThemeHoverBackground"] = new SolidColorBrush(colors.HoverBackground);
app.Resources["ThemePressedBackground"] = new SolidColorBrush(colors.PressedBackground);
app.Resources["ThemeDanger"] = new SolidColorBrush(colors.Danger);
app.Resources["ThemeDangerHover"] = new SolidColorBrush(colors.DangerHover);
app.Resources["ThemeIconColor"] = new SolidColorBrush(colors.IconColor);
app.Resources["ThemeIconColorChecked"] = new SolidColorBrush(colors.IconColorChecked);
app.Resources["ThemeVideoBackground"] = new SolidColorBrush(colors.VideoBackground);
app.Resources["ThemeShowButtonText"] = colors.ShowButtonText;
app.Resources["ThemeIconSize"] = colors.IconSize;
app.Resources["ThemeButtonSize"] = colors.ButtonSize;
app.Resources["ThemeButtonGroupCornerRadius"] = new CornerRadius(colors.ButtonGroupCornerRadius);
app.Resources["ThemeShowButtonShadow"] = colors.ShowButtonShadow;
app.Resources["ThemeSliderIndicatorSize"] = colors.SliderIndicatorSize;
app.Resources["ThemeSliderIndicatorCornerRadius"] = new CornerRadius(colors.SliderIndicatorCornerRadius);
app.Resources["ThemeButtonCornerRadius"] = new CornerRadius(colors.ButtonCornerRadius);
app.Resources["ThemeButtonPadding"] = new Thickness(colors.ButtonPadding);
app.Resources["ThemeButtonGroupPadding"] = new Thickness(colors.ButtonGroupPadding, 4, colors.ButtonGroupPadding, 4);
app.Resources["ThemeShowButtonGroupBackground"] = colors.ShowButtonGroupBackground;
}
public static void InitializeTheme(Application app)
{
app.Resources["ThemeBackground"] = new SolidColorBrush(DarkTheme.Background);
app.Resources["ThemeSurface"] = new SolidColorBrush(DarkTheme.Surface);
app.Resources["ThemeSurfaceVariant"] = new SolidColorBrush(DarkTheme.SurfaceVariant);
app.Resources["ThemePrimary"] = new SolidColorBrush(DarkTheme.Primary);
app.Resources["ThemePrimaryHover"] = new SolidColorBrush(DarkTheme.PrimaryHover);
app.Resources["ThemeTextPrimary"] = new SolidColorBrush(DarkTheme.TextPrimary);
app.Resources["ThemeTextSecondary"] = new SolidColorBrush(DarkTheme.TextSecondary);
app.Resources["ThemeTextTertiary"] = new SolidColorBrush(DarkTheme.TextTertiary);
app.Resources["ThemeBorder"] = new SolidColorBrush(DarkTheme.Border);
app.Resources["ThemeHoverBackground"] = new SolidColorBrush(DarkTheme.HoverBackground);
app.Resources["ThemePressedBackground"] = new SolidColorBrush(DarkTheme.PressedBackground);
app.Resources["ThemeDanger"] = new SolidColorBrush(DarkTheme.Danger);
app.Resources["ThemeDangerHover"] = new SolidColorBrush(DarkTheme.DangerHover);
app.Resources["ThemeIconColor"] = new SolidColorBrush(DarkTheme.IconColor);
app.Resources["ThemeIconColorChecked"] = new SolidColorBrush(DarkTheme.IconColorChecked);
app.Resources["ThemeVideoBackground"] = new SolidColorBrush(DarkTheme.VideoBackground);
app.Resources["ThemeShowButtonText"] = DarkTheme.ShowButtonText;
app.Resources["ThemeIconSize"] = DarkTheme.IconSize;
app.Resources["ThemeButtonSize"] = DarkTheme.ButtonSize;
app.Resources["ThemeButtonGroupCornerRadius"] = new CornerRadius(DarkTheme.ButtonGroupCornerRadius);
app.Resources["ThemeShowButtonShadow"] = DarkTheme.ShowButtonShadow;
app.Resources["ThemeSliderIndicatorSize"] = DarkTheme.SliderIndicatorSize;
app.Resources["ThemeSliderIndicatorCornerRadius"] = new CornerRadius(DarkTheme.SliderIndicatorCornerRadius);
app.Resources["ThemeButtonCornerRadius"] = new CornerRadius(DarkTheme.ButtonCornerRadius);
app.Resources["ThemeButtonPadding"] = new Thickness(DarkTheme.ButtonPadding);
app.Resources["ThemeButtonGroupPadding"] = new Thickness(DarkTheme.ButtonGroupPadding, 4, DarkTheme.ButtonGroupPadding, 4);
app.Resources["ThemeShowButtonGroupBackground"] = DarkTheme.ShowButtonGroupBackground;
}
}
}