Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Settings] Mica & modern titlebar #25936

Merged
merged 13 commits into from
Jun 11, 2023
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<PackageVersion Include="CommunityToolkit.Labs.WinUI.SettingsControls" Version="0.0.18" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.2.0" />
<PackageVersion Include="CommunityToolkit.WinUI.UI" Version="7.1.2" />
<PackageVersion Include="CommunityToolkit.WinUI.UI.Animations" Version="7.1.2" />
<PackageVersion Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
<PackageVersion Include="ControlzEx" Version="5.0.1" />
<PackageVersion Include="coverlet.collector" Version="1.3.0" />
Expand Down
1 change: 1 addition & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ SOFTWARE.
- CommunityToolkit.Labs.WinUI.SettingsControls 0.0.18
- CommunityToolkit.Mvvm 8.2.0
- CommunityToolkit.WinUI.UI 7.1.2
- CommunityToolkit.WinUI.UI.Animations 7.1.2
- CommunityToolkit.WinUI.UI.Controls 7.1.2
- ControlzEx 5.0.1
- HelixToolkit 2.20.2
Expand Down
17 changes: 10 additions & 7 deletions src/settings-ui/Settings.UI/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
xmlns:local="using:Microsoft.PowerToys.Settings.UI"
xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters"
xmlns:labs="using:CommunityToolkit.Labs.WinUI">
xmlns:labs="using:CommunityToolkit.Labs.WinUI"
xmlns:local="using:Microsoft.PowerToys.Settings.UI">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down Expand Up @@ -54,14 +54,17 @@
<Setter Property="IsTabStop" Value="False" />
</Style>

<Style
BasedOn="{StaticResource DefaultCheckBoxStyle}"
TargetType="controls:CheckBoxWithDescriptionControl" />
<Style BasedOn="{StaticResource DefaultCheckBoxStyle}" TargetType="controls:CheckBoxWithDescriptionControl" />
<!-- Other app resources here -->

<SolidColorBrush x:Key="WindowCaptionBackground" Color="Transparent" />
<SolidColorBrush x:Key="WindowCaptionBackgroundDisabled" Color="Transparent" />

<TransitionCollection x:Key="SettingsCardsAnimations">
<EntranceThemeTransition FromVerticalOffset="50"/> <!-- Animates cards when loaded-->
<RepositionThemeTransition IsStaggeringEnabled="False" /><!-- Smoothly animates individual cards upon whenever Expanders are expanded/collapsed -->
<EntranceThemeTransition FromVerticalOffset="50" />
<!-- Animates cards when loaded -->
<RepositionThemeTransition IsStaggeringEnabled="False" />
<!-- Smoothly animates individual cards upon whenever Expanders are expanded/collapsed -->
</TransitionCollection>
</ResourceDictionary>
</Application.Resources>
Expand Down
42 changes: 35 additions & 7 deletions src/settings-ui/Settings.UI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static void OpenSettingsWindow(Type type = null, bool ensurePageIsSelecte
}

settingsWindow.Activate();

if (type != null)
{
settingsWindow.NavigateToSection(type);
Expand All @@ -104,7 +105,6 @@ public static void OpenSettingsWindow(Type type = null, bool ensurePageIsSelecte
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
var cmdArgs = Environment.GetCommandLineArgs();

var isDark = IsDarkTheme();

if (cmdArgs != null && cmdArgs.Length >= RequiredArgumentsQty)
Expand Down Expand Up @@ -164,6 +164,7 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar
{
settingsWindow = new MainWindow(isDark);
settingsWindow.Activate();
settingsWindow.ExtendsContentIntoTitleBar = true;
settingsWindow.NavigateToSection(StartupPage);

// https://github.com/microsoft/microsoft-ui-xaml/issues/7595 - Activate doesn't bring window to the foreground
Expand All @@ -182,13 +183,15 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar
PowerToysTelemetry.Log.WriteEvent(new OobeStartedEvent());
OobeWindow oobeWindow = new OobeWindow(OOBE.Enums.PowerToysModules.Overview, isDark);
oobeWindow.Activate();
oobeWindow.ExtendsContentIntoTitleBar = true;
SetOobeWindow(oobeWindow);
}
else if (ShowScoobe)
{
PowerToysTelemetry.Log.WriteEvent(new ScoobeStartedEvent());
OobeWindow scoobeWindow = new OobeWindow(OOBE.Enums.PowerToysModules.WhatsNew, isDark);
scoobeWindow.Activate();
scoobeWindow.ExtendsContentIntoTitleBar = true;
SetOobeWindow(scoobeWindow);
}
else if (ShowFlyout)
Expand All @@ -208,7 +211,9 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar
// For debugging purposes
// Window is also needed to show MessageDialog
settingsWindow = new MainWindow(isDark);
settingsWindow.ExtendsContentIntoTitleBar = true;
settingsWindow.Activate();
settingsWindow.NavigateToSection(StartupPage);

#if !DEBUG
ShowMessageDialogAndExit("The application cannot be run as a standalone process. Please start the application through the runner.", "Forbidden");
Expand Down Expand Up @@ -248,36 +253,43 @@ public static TwoWayPipeMessageIPCManaged GetTwoWayIPCManager()
return ipcmanager;
}

public static string SelectedTheme()
public static ElementTheme SelectedTheme()
{
return SettingsRepository<GeneralSettings>.GetInstance(settingsUtils).SettingsConfig.Theme.ToUpper(CultureInfo.InvariantCulture);
switch (SettingsRepository<GeneralSettings>.GetInstance(settingsUtils).SettingsConfig.Theme.ToUpper(CultureInfo.InvariantCulture))
{
case "DARK": return ElementTheme.Dark;
case "LIGHT": return ElementTheme.Light;
default: return ElementTheme.Default;
}
}

public static bool IsDarkTheme()
{
var selectedTheme = SelectedTheme();
return selectedTheme == "DARK" || (selectedTheme == "SYSTEM" && ThemeHelpers.GetAppTheme() == AppTheme.Dark);
return selectedTheme == ElementTheme.Dark || (selectedTheme == ElementTheme.Default && ThemeHelpers.GetAppTheme() == AppTheme.Dark);
}

public static void HandleThemeChange()
{
try
{
var isDark = IsDarkTheme();
bool isDark = IsDarkTheme();

if (settingsWindow != null)
{
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(settingsWindow);
ThemeHelpers.SetImmersiveDarkMode(hWnd, isDark);
SetContentTheme(isDark, settingsWindow);
}

if (oobeWindow != null)
{
var hWnd = WinRT.Interop.WindowNative.GetWindowHandle(oobeWindow);
ThemeHelpers.SetImmersiveDarkMode(hWnd, isDark);
SetContentTheme(isDark, oobeWindow);
}

var selectedTheme = SelectedTheme();
if (selectedTheme == "SYSTEM")
if (SelectedTheme() == ElementTheme.Default)
{
themeListener = new ThemeListener();
themeListener.ThemeChanged += (_) => HandleThemeChange();
Expand All @@ -298,6 +310,22 @@ public static void HandleThemeChange()
}
}

public static void SetContentTheme(bool isDark, WindowEx window)
{
var rootGrid = (FrameworkElement)window.Content;
if (rootGrid != null)
{
if (isDark)
{
rootGrid.RequestedTheme = ElementTheme.Dark;
}
else
{
rootGrid.RequestedTheme = ElementTheme.Light;
}
}
}

private static ISettingsUtils settingsUtils = new SettingsUtils();

private static MainWindow settingsWindow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
<TextBlock
x:Name="Header"
MaxWidth="{StaticResource PageMaxWidth}"
Margin="0,44,0,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AutomationProperties.HeadingLevel="1"
Expand Down
8 changes: 4 additions & 4 deletions src/settings-ui/Settings.UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
MinHeight="480"
Closed="Window_Closed"
mc:Ignorable="d">

<Grid>
<local:ShellPage />
</Grid>
<Window.SystemBackdrop>
<MicaBackdrop/>
</Window.SystemBackdrop>
<local:ShellPage x:Name="shellPage" />
</winuiex:WindowEx>
7 changes: 7 additions & 0 deletions src/settings-ui/Settings.UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ public MainWindow(bool isDark, bool createHidden = false)

this.InitializeComponent();

SetTheme(isDark);

// receive IPC Message
App.IPCMessageReceivedCallback = (string msg) =>
{
Expand Down Expand Up @@ -279,5 +281,10 @@ internal void EnsurePageIsSelected()
{
ShellPage.EnsurePageIsSelected();
}

private void SetTheme(bool isDark)
{
shellPage.RequestedTheme = isDark ? ElementTheme.Dark : ElementTheme.Light;
}
}
}
89 changes: 61 additions & 28 deletions src/settings-ui/Settings.UI/OOBE/Views/OobeShellPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,73 @@
x:Class="Microsoft.PowerToys.Settings.UI.OOBE.Views.OobeShellPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:animations="using:CommunityToolkit.WinUI.UI.Animations"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Microsoft.PowerToys.Settings.UI.OOBE.Views"
xmlns:localModels="using:Microsoft.PowerToys.Settings.UI.OOBE.ViewModel"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="using:CommunityToolkit.WinUI.UI"
HighContrastAdjustment="None"
Loaded="ShellPage_Loaded"
mc:Ignorable="d">
<!--
todo(Stefan):
BackdropMaterial.ApplyToRootOrPageBackground="True"
-->
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="48" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="LayoutVisualStates">
<VisualState x:Name="WideLayout">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="720" />
</VisualState.StateTriggers>
</VisualState>
<VisualState x:Name="SmallLayout">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="600" />
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="navigationView.PaneDisplayMode" Value="LeftMinimal" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Button
x:Name="PaneToggleBtn"
Width="48"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Click="PaneToggleBtn_Click"
Style="{StaticResource PaneToggleButtonStyle}" />
<Grid
x:Name="AppTitleBar"
Height="{Binding ElementName=navigationView, Path=CompactPaneLength}"
Margin="48,0,0,0"
VerticalAlignment="Top"
IsHitTestVisible="True">
<animations:Implicit.Animations>
<animations:OffsetAnimation Duration="0:0:0.3" />
</animations:Implicit.Animations>
<StackPanel Orientation="Horizontal">
<Image
Width="16"
Height="16"
HorizontalAlignment="Left"
Source="/icon.ico" />
<TextBlock
x:Name="AppTitleBarText"
x:Uid="OobeWindow_TitleTxt"
Margin="12,0,0,0"
VerticalAlignment="Center"
Style="{StaticResource CaptionTextBlockStyle}"
TextWrapping="NoWrap" />
</StackPanel>
</Grid>
<NavigationView
x:Name="NavigationView"
Grid.Row="1"
x:Name="navigationView"
IsBackButtonVisible="Collapsed"
IsPaneOpen="True"
DisplayModeChanged="NavigationView_DisplayModeChanged"
IsPaneToggleButtonVisible="False"
IsSettingsVisible="False"
OpenPaneLength="296"
Expand Down Expand Up @@ -116,31 +167,13 @@
<NavigationView.FooterMenuItems>
<NavigationViewItem
x:Uid="Shell_WhatsNew"
Icon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily}, Glyph=&#xF133;}"
Icon="{ui:FontIcon FontFamily={StaticResource SymbolThemeFontFamily},
Glyph=&#xF133;}"
Tag="WhatsNew" />
</NavigationView.FooterMenuItems>
<NavigationView.Content>
<Frame x:Name="NavigationFrame" />
</NavigationView.Content>
</NavigationView>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="LayoutVisualStates">
<VisualState x:Name="WideLayout">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="720" />
</VisualState.StateTriggers>
</VisualState>
<VisualState x:Name="SmallLayout">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="600" />
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="NavigationView.PaneDisplayMode" Value="LeftMinimal" />
<Setter Target="NavigationView.IsPaneToggleButtonVisible" Value="True" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</UserControl>
Loading