Skip to content

Commit

Permalink
Add GetApplicationTheme and ResetBackdropProperties
Browse files Browse the repository at this point in the history
 Fix Default TintColor
ReEnable TintColor Option in Gallery Settings Page
  • Loading branch information
ghost1372 committed Dec 4, 2024
1 parent 51e5a98 commit a33eba3
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 27 deletions.
5 changes: 4 additions & 1 deletion dev/DevWinUI.Gallery/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static T GetService<T>() where T : class
public App()
{
Services = ConfigureServices();
Application.Current.RequestedTheme = GetThemeService.GetApplicationTheme();
this.InitializeComponent();
}

Expand Down Expand Up @@ -49,7 +50,9 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)

if (GetThemeService != null)
{
GetThemeService.AutoInitialize(MainWindow).EnableRequestedTheme();
GetThemeService.AutoInitialize(MainWindow)
.EnableRequestedTheme()
.ConfigureTintColor();
}

rootFrame.Navigate(typeof(MainPage));
Expand Down
38 changes: 19 additions & 19 deletions dev/DevWinUI.Gallery/Views/Settings/ThemeSettingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,48 +55,48 @@
IsClickEnabled="True"
LaunchUri="ms-settings:colors" />

<!--<dev:SettingsExpander Description="Add tint to your window to make your experience more personalized."
Header="TintColor"
HeaderIcon="{dev:BitmapIcon Source=Assets/Fluent/tint.png}"
IsEnabled="False">
<dev:SettingsExpander Description="Add tint to your window to make your experience more personalized."
Header="TintColor"
HeaderIcon="{dev:BitmapIcon Source=Assets/Fluent/tint.png}">
<Button Padding="0">
<StackPanel Orientation="Horizontal">
<Border Width="24"
Height="24"
Margin="4"
Background="Gray"
CornerRadius="4">
Height="24"
Margin="4"
Background="Gray"
CornerRadius="4">
<Grid>
<PathIcon Data="M0 6 L0 0 L6 0 L6 6 L12 6 L12 0 L18 0 L18 6 L12 6 L12 12 L18 12 L18 6 L24 6 L24 12 L18 12 L18 18 L24 18 L24 24 L6 24 L6 18 L0 18 L0 12 L6 12 L6 18 L12 18 L12 24 L18 24 L18 18 L12 18 L12 12 L6 12 L6 6 Z"
Foreground="LightGray" />
Foreground="LightGray" />
<Rectangle x:Name="TintBox" />
</Grid>
</Border>
<FontIcon Margin="8,4,10,4"
FontSize="12"
Glyph="&#xE70D;" />
FontSize="12"
Glyph="&#xE70D;" />
</StackPanel>
<Button.Flyout>
<Flyout>
<ColorPicker ColorChanged="ColorPicker_ColorChanged"
IsAlphaEnabled="True"
IsMoreButtonVisible="True" />
IsAlphaEnabled="True"
IsMoreButtonVisible="True" />
</Flyout>
</Button.Flyout>
</Button>
<dev:SettingsExpander.ItemsHeader>
<dev:SettingsCard>
<dev:SettingsCard.Description>
<dev:ColorPalette Margin="5,5,0,0"
HorizontalAlignment="Left"
ItemWidth="32"
Palette="Rectangle"
ShowHeader="False"
Color="NormalLarge" />
HorizontalAlignment="Left"
ItemClick="ColorPalette_ItemClick"
ItemWidth="32"
Palette="Rectangle"
ShowHeader="False"
Color="NormalLarge" />
</dev:SettingsCard.Description>
</dev:SettingsCard>
</dev:SettingsExpander.ItemsHeader>
</dev:SettingsExpander>-->
</dev:SettingsExpander>
</StackPanel>
</ScrollView>
</Page>
Expand Down
26 changes: 25 additions & 1 deletion dev/DevWinUI.Gallery/Views/Settings/ThemeSettingPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
namespace DevWinUIGallery.Views;
using Microsoft.UI.Xaml.Media;

namespace DevWinUIGallery.Views;

public sealed partial class ThemeSettingPage : Page
{
public ThemeSettingPage()
{
this.InitializeComponent();
}
private void ColorPicker_ColorChanged(ColorPicker sender, ColorChangedEventArgs args)
{
TintBox.Fill = new SolidColorBrush(args.NewColor);
App.Current.GetThemeService.SetBackdropTintColor(args.NewColor);
}

private void ColorPalette_ItemClick(object sender, ItemClickEventArgs e)
{
var color = e.ClickedItem as ColorPaletteItem;
if (color != null)
{
if (color.Hex.Contains("#000000"))
{
App.Current.GetThemeService.ResetBackdropProperties();
}
else
{
App.Current.GetThemeService.SetBackdropTintColor(color.Color);
}
TintBox.Fill = new SolidColorBrush(color.Color);
}
}
}


2 changes: 1 addition & 1 deletion dev/DevWinUI/Common/Backdrop/AcrylicSystemBackdrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed partial class AcrylicSystemBackdrop : SystemBackdrop
public readonly static Color Default_FallbackColor_Light = Color.FromArgb(0xff, 0xd3, 0xd3, 0xd3);

public readonly DesktopAcrylicKind Kind;
private DesktopAcrylicController acrylicController;
internal DesktopAcrylicController acrylicController;

public SystemBackdropConfiguration BackdropConfiguration { get; private set; }

Expand Down
10 changes: 5 additions & 5 deletions dev/DevWinUI/Common/Backdrop/MicaSystemBackdrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
namespace DevWinUI;
public sealed partial class MicaSystemBackdrop : SystemBackdrop
{
public readonly static Color Default_TintColor_Dark = Color.FromArgb(0xff, 0x20, 0x20, 0x20);
public readonly static Color Default_TintColor_Light = Color.FromArgb(0xff, 0xf3, 0xf3, 0xf3);
public readonly static Color Default_TintColor_MicaAlt_Dark = Color.FromArgb(0xff, 0x0a, 0x0a, 0x0a);
public readonly static Color Default_TintColor_MicaAlt_Light = Color.FromArgb(0xff, 0xda, 0xda, 0xda);
public readonly static Color Default_TintColor_Dark = ColorHelper.GetColorFromHex("#000000");
public readonly static Color Default_TintColor_Light = ColorHelper.GetColorFromHex("#000000");
public readonly static Color Default_TintColor_MicaAlt_Dark = ColorHelper.GetColorFromHex("#000000");
public readonly static Color Default_TintColor_MicaAlt_Light = ColorHelper.GetColorFromHex("#000000");
public readonly static Color Default_FallbackColor_MicaAlt_Dark = Color.FromArgb(0xff, 0x20, 0x20, 0x20);
public readonly static Color Default_FallbackColor_MicaAlt_Light = Color.FromArgb(0xff, 0xe8, 0xe8, 0xe8);

public readonly MicaKind Kind;
private MicaController micaController;
internal MicaController micaController;

public SystemBackdropConfiguration BackdropConfiguration { get; private set; }

Expand Down
2 changes: 2 additions & 0 deletions dev/DevWinUI/Services/ThemeService/IThemeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface IThemeService
BackdropType GetBackdropType();
BackdropType GetBackdropType(SystemBackdrop systemBackdrop);
ElementTheme GetElementTheme();
ApplicationTheme GetApplicationTheme();
ElementTheme GetActualTheme();

void SetBackdropType(BackdropType backdropType);
Expand All @@ -31,6 +32,7 @@ public interface IThemeService
void SetBackdropRadioButtonDefaultItem(Panel BackdropPanel);
void UpdateCaptionButtons();
void UpdateCaptionButtons(Window window);
void ResetBackdropProperties();

ThemeService AutoInitialize(Window window);
ThemeService Initialize(Window window, bool useAutoSave, string filename);
Expand Down
15 changes: 15 additions & 0 deletions dev/DevWinUI/Services/ThemeService/ThemeService.Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ public ElementTheme GetElementTheme()
{
return RootTheme;
}
public ApplicationTheme GetApplicationTheme()
{
switch (RootTheme)
{
default:
case ElementTheme.Default:
return Application.Current.RequestedTheme == ApplicationTheme.Dark
? ApplicationTheme.Dark
: ApplicationTheme.Light;
case ElementTheme.Light:
return ApplicationTheme.Light;
case ElementTheme.Dark:
return ApplicationTheme.Dark;
}
}

public ElementTheme GetActualTheme()
{
Expand Down
28 changes: 28 additions & 0 deletions dev/DevWinUI/Services/ThemeService/ThemeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,32 @@ public static void ChangeThemeWithoutSave(Window window)
element.RequestedTheme = ElementTheme.Light;
}
}

public void ResetBackdropProperties()
{
var backdrop = GetSystemBackdrop();
if (backdrop != null)
{
if (backdrop is MicaSystemBackdrop mica)
{
mica.micaController.ResetProperties();
if (useAutoSave && GlobalData.Config != null)
{
GlobalData.Config.BackdropFallBackColor = mica.micaController.FallbackColor;
GlobalData.Config.BackdropTintColor = mica.micaController.TintColor;
GlobalData.Save();
}
}
else if (backdrop is AcrylicSystemBackdrop acrylic)
{
acrylic.acrylicController.ResetProperties();
if (useAutoSave && GlobalData.Config != null)
{
GlobalData.Config.BackdropFallBackColor = acrylic.acrylicController.FallbackColor;
GlobalData.Config.BackdropTintColor = acrylic.acrylicController.TintColor;
GlobalData.Save();
}
}
}
}
}

0 comments on commit a33eba3

Please sign in to comment.