Compare commits

...

1 Commits

Author SHA1 Message Date
Niels Laute
5ade908fbb Push 2026-04-03 09:21:53 +02:00
8 changed files with 84 additions and 2 deletions

View File

@@ -76,6 +76,20 @@ public sealed partial class DockAppearanceSettingsViewModel : ObservableObject,
}
}
public string FontFamily
{
get => _settingsService.Settings.DockSettings.FontFamily;
set
{
if (_settingsService.Settings.DockSettings.FontFamily != value)
{
_settingsService.UpdateSettings(s => s with { DockSettings = s.DockSettings with { FontFamily = value } });
OnPropertyChanged();
DebouncedReapply();
}
}
}
public ColorizationMode ColorizationMode
{
get => _settingsService.Settings.DockSettings.ColorizationMode;

View File

@@ -45,6 +45,8 @@ public record DockSettings
public string? BackgroundImagePath { get; init; }
public string FontFamily { get; init; } = "Segoe UI";
// </Theme settings>
public ImmutableList<DockBandSettings> StartBands { get; init; } = ImmutableList.Create(
new DockBandSettings

View File

@@ -238,6 +238,9 @@ public sealed partial class DockControl : UserControl, IRecipient<CloseContextMe
ItemsOrientation = isHorizontal ? Orientation.Horizontal : Orientation.Vertical;
var fontFamily = string.IsNullOrWhiteSpace(settings.FontFamily) ? "Segoe UI" : settings.FontFamily;
FontFamily = new Microsoft.UI.Xaml.Media.FontFamily(fontFamily);
if (settings.Backdrop == DockBackdrop.Transparent)
{
RootGrid.BorderBrush = new SolidColorBrush(Colors.Transparent);

View File

@@ -50,6 +50,7 @@
<Style.Setters>
<Setter Property="Background" Value="{ThemeResource DockItemBackground}" />
<Setter Property="BorderBrush" Value="{ThemeResource DockItemBorderBrush}" />
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="Padding" Value="{StaticResource DockItemPadding}" />
<Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}" />
<Setter Property="CornerRadius" Value="{StaticResource DockItemCornerRadius}" />
@@ -101,7 +102,7 @@
MaxWidth="100"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
FontFamily="Segoe UI"
FontFamily="{TemplateBinding FontFamily}"
FontSize="12"
Text="{TemplateBinding Title}"
TextAlignment="Left"
@@ -113,7 +114,7 @@
Margin="0,-2,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
FontFamily="Segoe UI"
FontFamily="{TemplateBinding FontFamily}"
FontSize="10"
Foreground="{ThemeResource TextFillColorTertiary}"
Text="{TemplateBinding Subtitle}"

View File

@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.Graphics.Canvas.Text;
namespace Microsoft.CmdPal.UI.Helpers;
internal static class SystemFontHelper
{
private static List<string>? _cachedFontFamilies;
public static List<string> GetSystemFontFamilies()
{
if (_cachedFontFamilies is not null)
{
return _cachedFontFamilies;
}
var fontFamilies = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
using var fontSet = CanvasFontSet.GetSystemFontSet();
foreach (var face in fontSet.Fonts)
{
var familyNames = face.FamilyNames;
if (familyNames.Count > 0)
{
// Prefer the en-us name; fall back to the first available name
if (!familyNames.TryGetValue("en-us", out var name))
{
name = familyNames.Values.FirstOrDefault();
}
if (!string.IsNullOrWhiteSpace(name))
{
fontFamilies.Add(name);
}
}
}
_cachedFontFamilies = [.. fontFamilies.OrderBy(f => f, StringComparer.OrdinalIgnoreCase)];
return _cachedFontFamilies;
}
}

View File

@@ -104,6 +104,15 @@
</ComboBox>
</controls:SettingsCard>
<!-- Font Family -->
<controls:SettingsCard x:Uid="DockAppearance_FontFamily_SettingsCard" HeaderIcon="{ui:FontIcon Glyph=&#xE8D2;}">
<ComboBox
x:Name="FontFamilyComboBox"
MinWidth="{StaticResource SettingActionControlMinWidth}"
ItemsSource="{x:Bind SystemFonts}"
SelectedItem="{x:Bind ViewModel.DockAppearance.FontFamily, Mode=TwoWay}" />
</controls:SettingsCard>
<!-- Background / Colorization Section -->
<controls:SettingsExpander
x:Uid="DockAppearance_Background_SettingsExpander"

View File

@@ -4,6 +4,7 @@
using System.Diagnostics;
using ManagedCommon;
using Microsoft.CmdPal.UI.Helpers;
using Microsoft.CmdPal.UI.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.Dock;
using Microsoft.CmdPal.UI.ViewModels.Services;
@@ -22,6 +23,8 @@ public sealed partial class DockSettingsPage : Page
internal SettingsViewModel ViewModel { get; }
public List<string> SystemFonts { get; } = SystemFontHelper.GetSystemFontFamilies();
public List<DockBandSettingsViewModel> AllDockBandItems => GetAllBandSettings();
public DockSettingsPage()

View File

@@ -817,6 +817,12 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
<data name="DockAppearance_Backdrop_Acrylic.Content" xml:space="preserve">
<value>Acrylic</value>
</data>
<data name="DockAppearance_FontFamily_SettingsCard.Header" xml:space="preserve">
<value>Font</value>
</data>
<data name="DockAppearance_FontFamily_SettingsCard.Description" xml:space="preserve">
<value>Choose the font used for text in the dock</value>
</data>
<data name="DockAppearance_Background_SettingsExpander.Header" xml:space="preserve">
<value>Background</value>
</data>