Skip to content

Commit 312c2b6

Browse files
committed
feat: enhance font and note style settings
- Added support for custom fonts with new font loading and application methods. - Introduced note style settings, allowing users to choose between title bar and full styles. - Updated UI components to reflect selected font and note style dynamically. - Enhanced AppSettings to manage font and note style persistence. - Updated localization for new font and note style options.
1 parent 8d0b8bf commit 312c2b6

21 files changed

Lines changed: 456 additions & 215 deletions

‎AcrylicSettingsWindow.xaml.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public AcrylicSettingsWindow(BackdropSettings settings, Action<BackdropSettings>
4040
AppWindow.SetIcon(iconPath);
4141

4242
var theme = AppSettings.LoadThemeSetting();
43-
AppSettings.ApplyThemeToWindow(this, theme);
4443

4544
// Apply acrylic to this window too (live preview)
4645
AppSettings.ApplyToWindow(this, settings, ref _acrylicController, ref _configSource);
46+
AppSettings.ApplyThemeToWindow(this, theme, _configSource);
4747

4848
LoadSettings(settings);
4949
ApplyAcrylicLocalization();

‎ActionPanel.cs‎

Lines changed: 236 additions & 198 deletions
Large diffs are not rendered by default.

‎App.xaml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
<ResourceDictionary.MergedDictionaries>
1010
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
1111
</ResourceDictionary.MergedDictionaries>
12+
<FontFamily x:Key="GeistRegular">Assets/Fonts/Geist-Regular.otf#Geist</FontFamily>
13+
<FontFamily x:Key="GeistMedium">Assets/Fonts/Geist-Medium.otf#Geist Medium</FontFamily>
14+
<FontFamily x:Key="GeistBold">Assets/Fonts/Geist-Bold.otf#Geist Bold</FontFamily>
15+
<FontFamily x:Key="InterRegular">Assets/Fonts/Inter-Regular.ttf#Inter</FontFamily>
16+
<FontFamily x:Key="InterMedium">Assets/Fonts/Inter-Medium.ttf#Inter Medium</FontFamily>
17+
<FontFamily x:Key="InterBold">Assets/Fonts/Inter-Bold.ttf#Inter Bold</FontFamily>
18+
<FontFamily x:Key="JetBrainsMonoRegular">Assets/Fonts/JetBrainsMono-Regular.ttf#JetBrains Mono</FontFamily>
19+
<FontFamily x:Key="JetBrainsMonoMedium">Assets/Fonts/JetBrainsMono-Medium.ttf#JetBrains Mono Medium</FontFamily>
20+
<FontFamily x:Key="JetBrainsMonoBold">Assets/Fonts/JetBrainsMono-Bold.ttf#JetBrains Mono Bold</FontFamily>
21+
<FontFamily x:Key="ContentControlThemeFontFamily">Assets/Fonts/Geist-Regular.otf#Geist</FontFamily>
1222
<local:ColorToBrushConverter x:Key="ColorToBrush"/>
1323
<LinearGradientBrush x:Key="AccentLinearDownGradientBrush"
1424
StartPoint="0,0" EndPoint="0,1">

‎App.xaml.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Media;
23

34
namespace NoteUI;
45

@@ -14,8 +15,15 @@ public App()
1415
protected override void OnLaunched(LaunchActivatedEventArgs args)
1516
{
1617
Lang.SetLanguage(AppSettings.LoadLanguage());
18+
ApplyFontResource(AppSettings.LoadFontSetting());
1719
ReminderService.Initialize();
1820
_window = new MainWindow();
1921
_window.Activate();
2022
}
23+
24+
public static void ApplyFontResource(string font)
25+
{
26+
var fontFamily = AppSettings.GetFontFamily(font);
27+
Application.Current.Resources["ContentControlThemeFontFamily"] = fontFamily;
28+
}
2129
}

‎AppSettings.cs‎

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Text.Json;
22
using Microsoft.UI.Composition.SystemBackdrops;
33
using Microsoft.UI.Xaml;
4+
using Microsoft.UI.Xaml.Controls;
45
using Microsoft.UI.Xaml.Media;
56
using WinRT;
67

@@ -55,6 +56,82 @@ public static void SaveLanguage(string lang)
5556
MergeAndSaveSettings(new Dictionary<string, object> { ["language"] = lang });
5657
}
5758

59+
// ── Font ─────────────────────────────────────────────────
60+
61+
public static string LoadFontSetting()
62+
{
63+
try
64+
{
65+
if (File.Exists(SettingsPath))
66+
{
67+
var json = File.ReadAllText(SettingsPath);
68+
var doc = JsonDocument.Parse(json);
69+
if (doc.RootElement.TryGetProperty("font", out var prop))
70+
return prop.GetString() ?? "geist";
71+
}
72+
}
73+
catch { }
74+
return "geist";
75+
}
76+
77+
public static void SaveFontSetting(string font)
78+
{
79+
MergeAndSaveSettings(new Dictionary<string, object> { ["font"] = font });
80+
}
81+
82+
public static FontFamily GetFontFamily(string font)
83+
{
84+
return font switch
85+
{
86+
"segoe" => new FontFamily("Segoe UI"),
87+
"inter" => new FontFamily("Assets/Fonts/Inter-Regular.ttf#Inter"),
88+
"jetbrains" => new FontFamily("Assets/Fonts/JetBrainsMono-Regular.ttf#JetBrains Mono"),
89+
_ => new FontFamily("Assets/Fonts/Geist-Regular.otf#Geist"),
90+
};
91+
}
92+
93+
public static void ApplyFontToTree(FrameworkElement root, FontFamily fontFamily)
94+
{
95+
if (root is Control c)
96+
c.FontFamily = fontFamily;
97+
else if (root is TextBlock tb)
98+
tb.FontFamily = fontFamily;
99+
100+
if (root is Panel panel)
101+
{
102+
foreach (var child in panel.Children)
103+
if (child is FrameworkElement fe)
104+
ApplyFontToTree(fe, fontFamily);
105+
}
106+
else if (root is ContentControl cc && cc.Content is FrameworkElement content)
107+
{
108+
ApplyFontToTree(content, fontFamily);
109+
}
110+
}
111+
112+
// ── Note style ────────────────────────────────────────────
113+
114+
public static string LoadNoteStyle()
115+
{
116+
try
117+
{
118+
if (File.Exists(SettingsPath))
119+
{
120+
var json = File.ReadAllText(SettingsPath);
121+
var doc = JsonDocument.Parse(json);
122+
if (doc.RootElement.TryGetProperty("noteStyle", out var prop))
123+
return prop.GetString() ?? "titlebar";
124+
}
125+
}
126+
catch { }
127+
return "titlebar";
128+
}
129+
130+
public static void SaveNoteStyle(string style)
131+
{
132+
MergeAndSaveSettings(new Dictionary<string, object> { ["noteStyle"] = style });
133+
}
134+
58135
// ── Slash commands ──────────────────────────────────────────
59136

60137
public static bool LoadSlashEnabled()
@@ -240,7 +317,8 @@ private static void ConfigureBackdropController(
240317
}
241318
}
242319

243-
public static void ApplyThemeToWindow(Window window, string theme)
320+
public static void ApplyThemeToWindow(Window window, string theme,
321+
SystemBackdropConfiguration? configSource = null)
244322
{
245323
if (window.Content is FrameworkElement fe)
246324
{
@@ -250,6 +328,9 @@ public static void ApplyThemeToWindow(Window window, string theme)
250328
"dark" => ElementTheme.Dark,
251329
_ => ElementTheme.Default
252330
};
331+
332+
if (configSource != null)
333+
configSource.Theme = (SystemBackdropTheme)fe.ActualTheme;
253334
}
254335
}
255336

‎Assets/Fonts/Geist-Bold.otf‎

163 KB
Binary file not shown.

‎Assets/Fonts/Geist-Medium.otf‎

158 KB
Binary file not shown.

‎Assets/Fonts/Geist-Regular.otf‎

154 KB
Binary file not shown.

‎Assets/Fonts/Inter-Bold.ttf‎

411 KB
Binary file not shown.

‎Assets/Fonts/Inter-Medium.ttf‎

408 KB
Binary file not shown.

0 commit comments

Comments
 (0)