Skip to content

Commit

Permalink
Add TitleBar.ButtonGlyphStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Jul 1, 2024
1 parent 9cbca0a commit d52041b
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 34 deletions.
41 changes: 22 additions & 19 deletions source/iNKORE.UI.WPF.Modern/Controls/Primitives/TitleBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,29 +448,26 @@ public static void SetMinimizeButtonAvailability(Window window, TitleBarButtonAv

#endregion

#region ButtonGlyphStyle

public static readonly DependencyProperty ButtonGlyphStyleProperty =
DependencyProperty.RegisterAttached(
"ButtonGlyphStyle",
typeof(TitleBarButtonGlyphStyle?),
typeof(TitleBar),
new PropertyMetadata(null));

//#region MaximizeButtonTouchOptimize

//public static readonly DependencyProperty MaximizeButtonTouchOptimizeProperty =
// DependencyProperty.RegisterAttached(
// "MaximizeButtonTouchOptimize",
// typeof(bool),
// typeof(TitleBar),
// new PropertyMetadata(false));


//public static bool GetMaximizeButtonTouchOptimize(Window window)
//{
// return (bool)window.GetValue(MaximizeButtonTouchOptimizeProperty);
//}
public static TitleBarButtonGlyphStyle? GetButtonGlyphStyle(Window window)
{
return (TitleBarButtonGlyphStyle?)window.GetValue(ButtonGlyphStyleProperty);
}

//public static void SetMaximizeButtonTouchOptimize(Window window, bool value)
//{
// window.SetValue(MaximizeButtonTouchOptimizeProperty, value);
//}
public static void SetButtonGlyphStyle(Window window, TitleBarButtonGlyphStyle? value)
{
window.SetValue(ButtonGlyphStyleProperty, value);
}

//#endregion
#endregion


#region BackRequested
Expand Down Expand Up @@ -511,4 +508,10 @@ public enum TitleBarButtonAvailability
Disabled,
Enabled
}

public enum TitleBarButtonGlyphStyle
{
MDL2,
Fluent,
}
}
54 changes: 44 additions & 10 deletions source/iNKORE.UI.WPF.Modern/Controls/Primitives/TitleBarControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using iNKORE.UI.WPF.Modern.Helpers;
using iNKORE.UI.WPF.Helpers;
using iNKORE.UI.WPF.Modern.Helpers;
using iNKORE.UI.WPF.Modern.Helpers.Styles;
using System;
using System.ComponentModel;
Expand Down Expand Up @@ -49,6 +50,7 @@ public TitleBarControl()
CommandBindings.Add(new CommandBinding(SystemCommands.CloseWindowCommand, CloseWindow));

SetInsideTitleBar(this, true);
UpdateActualButtonGlyphStyle();
}

#region IsActive
Expand Down Expand Up @@ -349,7 +351,7 @@ internal static void SetInsideTitleBar(UIElement element, bool value)

private static void ButtonAvailabilityProperty_ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as TitleBarControl)?.RefreshButtonActualAvailabilities();
(d as TitleBarControl)?.UpdateButtonActualAvailabilities();
}

public static readonly DependencyProperty CloseButtonAvailabilityProperty =
Expand Down Expand Up @@ -407,6 +409,34 @@ public TitleBarButtonAvailability MinimizeButtonActualAvailability
private set => SetValue(MinimizeButtonActualAvailabilityPropertyKey, value);
}

#endregion

#region ButtonGlyphStyle

public static readonly DependencyProperty ButtonGlyphStyleProperty =
TitleBar.ButtonGlyphStyleProperty.AddOwner(typeof(TitleBarControl), new PropertyMetadata(null, ButtonGlyphStyleProperty_ValueChanged));

private static void ButtonGlyphStyleProperty_ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as TitleBarControl)?.UpdateActualButtonGlyphStyle();
}

public TitleBarButtonGlyphStyle? ButtonGlyphStyle
{
get { return (TitleBarButtonGlyphStyle?)GetValue(ButtonGlyphStyleProperty); }
set { SetValue(ButtonGlyphStyleProperty, value); }
}

public static readonly DependencyPropertyKey ActualButtonGlyphStylePropertyKey = DependencyProperty.RegisterReadOnly(nameof(ActualButtonGlyphStyle), typeof(TitleBarButtonGlyphStyle), typeof(TitleBarControl), new PropertyMetadata(TitleBarButtonGlyphStyle.MDL2));
public static readonly DependencyProperty ActualButtonGlyphStyleProperty = ActualButtonGlyphStylePropertyKey.DependencyProperty;

public TitleBarButtonGlyphStyle ActualButtonGlyphStyle
{
get => (TitleBarButtonGlyphStyle)GetValue(ActualButtonGlyphStyleProperty);
private set => SetValue(ActualButtonGlyphStylePropertyKey, value);
}


#endregion

private Button BackButton { get; set; }
Expand Down Expand Up @@ -479,8 +509,8 @@ protected override void OnVisualParentChanged(DependencyObject oldParent)
{
if (_parentWindow != null)
{
descriptor_ResizeMode.RemoveValueChanged(_parentWindow, _window_ButtonAvailabilityShouldRefresh);
descriptor_WindowStyle.RemoveValueChanged(_parentWindow, _window_ButtonAvailabilityShouldRefresh);
descriptor_ResizeMode.RemoveValueChanged(_parentWindow, _window_ButtonAvailabilityShouldUpdate);
descriptor_WindowStyle.RemoveValueChanged(_parentWindow, _window_ButtonAvailabilityShouldUpdate);

if (_altLeftBinding != null)
{
Expand All @@ -497,18 +527,18 @@ protected override void OnVisualParentChanged(DependencyObject oldParent)
{
_altLeftBinding = new KeyBinding(new GoBackCommand(this), Key.Left, ModifierKeys.Alt);
_parentWindow.InputBindings.Add(_altLeftBinding);
descriptor_ResizeMode.AddValueChanged(_parentWindow, _window_ButtonAvailabilityShouldRefresh);
descriptor_WindowStyle.AddValueChanged(_parentWindow, _window_ButtonAvailabilityShouldRefresh);
descriptor_ResizeMode.AddValueChanged(_parentWindow, _window_ButtonAvailabilityShouldUpdate);
descriptor_WindowStyle.AddValueChanged(_parentWindow, _window_ButtonAvailabilityShouldUpdate);

RefreshButtonActualAvailabilities();
UpdateButtonActualAvailabilities();
}
}

private void _window_ButtonAvailabilityShouldRefresh(object sender, EventArgs e)
private void _window_ButtonAvailabilityShouldUpdate(object sender, EventArgs e)
{
if(sender == _parentWindow)
{
RefreshButtonActualAvailabilities();
UpdateButtonActualAvailabilities();
}
}

Expand All @@ -531,7 +561,7 @@ private void OnBackButtonClick(object sender, RoutedEventArgs e)
}
}

public void RefreshButtonActualAvailabilities()
public void UpdateButtonActualAvailabilities()
{

// Close button
Expand Down Expand Up @@ -618,6 +648,10 @@ public void RefreshButtonActualAvailabilities()
InitializeSnapLayout();
}

public void UpdateActualButtonGlyphStyle()
{
ActualButtonGlyphStyle = ButtonGlyphStyle ?? (OSVersionHelper.OSVersion > new Version(10, 0, 22000) ? TitleBarButtonGlyphStyle.Fluent : TitleBarButtonGlyphStyle.MDL2);
}

private void OnLeftSystemOverlaySizeChanged(object sender, SizeChangedEventArgs e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,25 @@
<Setter TargetName="MaximizeRestoreButton" Property="Command" Value="{x:Static SystemCommands.RestoreWindowCommand}" />
<Setter TargetName="MaximizeRestoreButton" Property="AutomationProperties.Name" Value="Restore" />
</DataTrigger>

<!--Fluent Button Glyphs-->

<Trigger Property="ActualButtonGlyphStyle" Value="Fluent">
<Setter TargetName="MinimizeButton" Property="Content" Value="{StaticResource ChromeMinimize11}" />
<Setter TargetName="MaximizeRestoreButton" Property="Content" Value="{StaticResource ChromeMaximize11}" />
<Setter TargetName="CloseButton" Property="Content" Value="{StaticResource ChromeClose11}" />
</Trigger>

<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ActualButtonGlyphStyle}" Value="Fluent"/>
<Condition Binding="{Binding WindowState, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Value="Maximized" />
</MultiDataTrigger.Conditions>
<Setter TargetName="MaximizeRestoreButton" Property="Content" Value="{StaticResource ChromeRestore11}" />
</MultiDataTrigger>

<!--High Contrasts-->

<DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="true">
<Setter TargetName="PART_BackButton" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter TargetName="Title" Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ActiveCaptionTextBrushKey}}" />
Expand Down
15 changes: 10 additions & 5 deletions source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public class SnapLayout

private double _dpiScale;

private Button _button;
private TitleBarButton _button;

private string _hoverColorKey;

Check warning on line 36 in source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs

View workflow job for this annotation

GitHub Actions / build

The field 'SnapLayout._hoverColorKey' is assigned but its value is never used

Check warning on line 36 in source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs

View workflow job for this annotation

GitHub Actions / build

The field 'SnapLayout._hoverColorKey' is assigned but its value is never used

Check warning on line 36 in source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs

View workflow job for this annotation

GitHub Actions / build

The field 'SnapLayout._hoverColorKey' is assigned but its value is never used

Check warning on line 36 in source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs

View workflow job for this annotation

GitHub Actions / build

The field 'SnapLayout._hoverColorKey' is assigned but its value is never used
private string _pressedColorKey;

Check warning on line 37 in source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs

View workflow job for this annotation

GitHub Actions / build

The field 'SnapLayout._pressedColorKey' is assigned but its value is never used

Check warning on line 37 in source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs

View workflow job for this annotation

GitHub Actions / build

The field 'SnapLayout._pressedColorKey' is assigned but its value is never used

Check warning on line 37 in source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs

View workflow job for this annotation

GitHub Actions / build

The field 'SnapLayout._pressedColorKey' is assigned but its value is never used

Check warning on line 37 in source/iNKORE.UI.WPF.Modern/Helpers/Styles/SnapLayout.cs

View workflow job for this annotation

GitHub Actions / build

The field 'SnapLayout._pressedColorKey' is assigned but its value is never used

public Button Target { get { return _button; } }

public void Register(Button button)
public void Register(TitleBarButton button)
{
_isButtonFocused = false;
_button = button;
Expand Down Expand Up @@ -147,18 +147,23 @@ private void RefreshButtonColor()
if (_isButtonClicked)
{
//_button.Background = _pressedColor;
_button.SetResourceReference(Button.BackgroundProperty, _pressedColorKey);
//button.SetResourceReference(Button.BackgroundProperty, _pressedColorKey);
_button.Background = _button.PressedBackground;
}
else
{
if (_isButtonFocused)
{
//_button.Background = _hoverColor;
_button.SetResourceReference(Button.BackgroundProperty, _hoverColorKey);
//_button.SetResourceReference(Button.BackgroundProperty, _hoverColorKey);
_button.Background = _button.HoverBackground;

}
else
{
_button.Background = DefaultButtonBackground;
//_button.Background = DefaultButtonBackground;
_button.ClearValue(TitleBarButton.BackgroundProperty);

}
}
}
Expand Down
1 change: 1 addition & 0 deletions source/iNKORE.UI.WPF.Modern/Themes/Styles/Window.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
MaximizeButtonAvailability="{TemplateBinding primitives:TitleBar.MaximizeButtonAvailability}"
MinimizeButtonAvailability="{TemplateBinding primitives:TitleBar.MinimizeButtonAvailability}"
CloseButtonAvailability="{TemplateBinding primitives:TitleBar.CloseButtonAvailability}"
ButtonGlyphStyle="{TemplateBinding primitives:TitleBar.ButtonGlyphStyle}"
Style="{TemplateBinding primitives:TitleBar.Style}" />

<AdornerDecorator x:Name="AdornerDecorator" Grid.Row="1">
Expand Down

0 comments on commit d52041b

Please sign in to comment.