NormalThemeProvider.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using Microsoft.CmdPal.UI.ViewModels.Services; 6 using Microsoft.UI.Xaml; 7 using Windows.UI; 8 using Windows.UI.ViewManagement; 9 10 namespace Microsoft.CmdPal.UI.Services; 11 12 /// <summary> 13 /// Provides theme resources and acrylic backdrop parameters matching the default Command Palette theme. 14 /// </summary> 15 internal sealed class NormalThemeProvider : IThemeProvider 16 { 17 private static readonly Color DarkBaseColor = Color.FromArgb(255, 32, 32, 32); 18 private static readonly Color LightBaseColor = Color.FromArgb(255, 243, 243, 243); 19 private readonly UISettings _uiSettings; 20 21 public NormalThemeProvider(UISettings uiSettings) 22 { 23 ArgumentNullException.ThrowIfNull(uiSettings); 24 _uiSettings = uiSettings; 25 } 26 27 public string ThemeKey => "normal"; 28 29 public string ResourcePath => "ms-appx:///Styles/Theme.Normal.xaml"; 30 31 public AcrylicBackdropParameters GetAcrylicBackdrop(ThemeContext context) 32 { 33 var isLight = context.Theme == ElementTheme.Light || 34 (context.Theme == ElementTheme.Default && 35 _uiSettings.GetColorValue(UIColorType.Background).R > 128); 36 37 return new AcrylicBackdropParameters( 38 TintColor: isLight ? LightBaseColor : DarkBaseColor, 39 FallbackColor: isLight ? LightBaseColor : DarkBaseColor, 40 TintOpacity: 0.5f, 41 LuminosityOpacity: isLight ? 0.9f : 0.96f); 42 } 43 }