Skip to content

Commit fa401b4

Browse files
authored
refactor: use SVG path icons for theme and locale buttons (#24)
- Replace emoji with PathGeometry icons (Sun/Moon/Globe) - Theme: Moon icon in light mode, Sun icon in dark mode (toggled via IsDarkTheme) - Locale: Globe icon overlay with EN/中 text label - Remove ThemeButtonText emoji property from ViewModel
1 parent 7da80cd commit fa401b4

2 files changed

Lines changed: 59 additions & 10 deletions

File tree

src/ViewModels/MainWindowViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public partial class MainWindowViewModel : ViewModelBase
1212

1313
[ObservableProperty] private ViewModelBase _currentPage = new PatchViewModel();
1414
[ObservableProperty] private bool _isDarkTheme;
15-
[ObservableProperty] private string _themeButtonText = "🌙";
1615
[ObservableProperty] private string _localeText = "EN";
1716

1817
public ObservableCollection<NavItem> NavItems { get; } = new();
@@ -54,7 +53,6 @@ [RelayCommand] private void Navigate(NavItem item)
5453
private void ToggleTheme()
5554
{
5655
IsDarkTheme = !IsDarkTheme;
57-
ThemeButtonText = IsDarkTheme ? "☀️" : "🌙";
5856
var app = Avalonia.Application.Current;
5957
if (app != null)
6058
app.RequestedThemeVariant = IsDarkTheme

src/Views/MainWindow.axaml

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,34 @@
88
Title="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[App.Title]}"
99
Width="960" Height="640" MinWidth="780" MinHeight="540"
1010
WindowStartupLocation="CenterScreen">
11+
12+
<Window.Resources>
13+
<!-- Sun icon (for dark mode → switch to light) -->
14+
<PathGeometry x:Key="SunIcon">
15+
M12 2v2m0 16v2M4.93 4.93l1.41 1.41m11.32 11.32l1.41 1.41M2 12h2m16 0h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41M12 6a6 6 0 100 12 6 6 0 000-12z
16+
</PathGeometry>
17+
18+
<!-- Moon icon (for light mode → switch to dark) -->
19+
<PathGeometry x:Key="MoonIcon">
20+
M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z
21+
</PathGeometry>
22+
23+
<!-- Globe icon -->
24+
<PathGeometry x:Key="GlobeIcon">
25+
M12 2a10 10 0 100 20 10 10 0 000-20zm-2 18.41A8.04 8.04 0 015.05 13H7.1a16.1 16.1 0 002.9 7.41zM12 20a14.2 14.2 0 01-2.7-7h5.4A14.2 14.2 0 0112 20zm-4.9-9A8.04 8.04 0 0110 3.59 8.04 8.04 0 015.05 11H7.1zm9.8 0h2.05a8.04 8.04 0 00-4.95-7.41A16.1 16.1 0 0116.9 11zm2.05 2h-2.05a16.1 16.1 0 01-2.9 7.41A8.04 8.04 0 0018.95 13zm-11.85 0a8.04 8.04 0 004.95 7.41A16.1 16.1 0 017.1 13z
26+
</PathGeometry>
27+
28+
<!-- Theme toggle button template -->
29+
<ControlTemplate x:Key="IconButton">
30+
<Border Background="Transparent" CornerRadius="4">
31+
<Panel Width="36" Height="36">
32+
<ContentPresenter Content="{TemplateBinding Content}"
33+
HorizontalAlignment="Center" VerticalAlignment="Center"/>
34+
</Panel>
35+
</Border>
36+
</ControlTemplate>
37+
</Window.Resources>
38+
1139
<DockPanel>
1240
<!-- Left Sidebar -->
1341
<Border DockPanel.Dock="Left" Width="200" Background="{DynamicResource SystemControlBackgroundChromeMediumLowBrush}">
@@ -38,16 +66,39 @@
3866

3967
<!-- Bottom controls: theme + locale -->
4068
<StackPanel Grid.Row="2" Orientation="Horizontal"
41-
HorizontalAlignment="Center" Spacing="4" Margin="8,12">
42-
<Button Content="{Binding ThemeButtonText}"
43-
Command="{Binding ToggleThemeCommand}"
69+
HorizontalAlignment="Center" Spacing="0" Margin="4,8">
70+
<!-- Theme toggle -->
71+
<Button Command="{Binding ToggleThemeCommand}"
4472
Background="Transparent" BorderThickness="0"
45-
FontSize="16" Width="40" Height="36"
46-
ToolTip.Tip="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Theme.Toggle]}"/>
47-
<Button Content="{Binding LocaleText}"
48-
Command="{Binding ToggleLocaleCommand}"
73+
Width="44" Height="36"
74+
ToolTip.Tip="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Theme.Toggle]}">
75+
<Panel>
76+
<Path Data="{StaticResource MoonIcon}" Stretch="Uniform"
77+
Width="18" Height="18"
78+
Fill="{DynamicResource SystemControlForegroundBaseHighBrush}"
79+
IsVisible="{Binding !IsDarkTheme}"/>
80+
<Path Data="{StaticResource SunIcon}" Stretch="Uniform"
81+
Width="18" Height="18"
82+
Fill="{DynamicResource SystemControlForegroundBaseHighBrush}"
83+
IsVisible="{Binding IsDarkTheme}"/>
84+
</Panel>
85+
</Button>
86+
87+
<!-- Locale toggle -->
88+
<Button Command="{Binding ToggleLocaleCommand}"
4989
Background="Transparent" BorderThickness="0"
50-
FontSize="14" Width="40" Height="36"/>
90+
Width="44" Height="36"
91+
ToolTip.Tip="{Binding Source={x:Static svc:LocalizationService.Instance}, Path=[Theme.Toggle]}">
92+
<Grid>
93+
<Path Data="{StaticResource GlobeIcon}" Stretch="Uniform"
94+
Width="16" Height="16"
95+
Fill="{DynamicResource SystemControlForegroundBaseHighBrush}"
96+
Margin="0,0,0,0"/>
97+
<TextBlock Text="{Binding LocaleText}" FontSize="9" FontWeight="Bold"
98+
HorizontalAlignment="Center" VerticalAlignment="Center"
99+
Foreground="{DynamicResource SystemControlForegroundBaseHighBrush}"/>
100+
</Grid>
101+
</Button>
51102
</StackPanel>
52103
</Grid>
53104
</Border>

0 commit comments

Comments
 (0)