Skip to content

Commit

Permalink
improve media details command bar
Browse files Browse the repository at this point in the history
add command bar extension

add ellipsis button style

add more button animation

invert selection command bar translation animation

improve gamepad navigation
  • Loading branch information
United600 committed Jan 6, 2025
1 parent 0652bdd commit da5229d
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 55 deletions.
8 changes: 5 additions & 3 deletions Screenbox/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@
<CornerRadius x:Key="CircularCornerRadius">99</CornerRadius>

<!-- Animations -->
<ctAnimations:ImplicitAnimationSet x:Key="SimpleShowAnimations">
<ctAnimations:ImplicitAnimationSet x:Key="FadeInImplicitAnimation">
<ctAnimations:OpacityAnimation
EasingType="Linear"
From="0"
To="1"
Duration="{StaticResource ControlFastAnimationDuration}" />
Duration="{StaticResource ControlFasterAnimationDuration}" />
</ctAnimations:ImplicitAnimationSet>
<ctAnimations:ImplicitAnimationSet x:Key="SimpleHideAnimations">
<ctAnimations:ImplicitAnimationSet x:Key="FadeOutImplicitAnimation">
<ctAnimations:OpacityAnimation
EasingType="Linear"
From="1"
To="0"
Duration="{StaticResource ControlFasterAnimationDuration}" />
</ctAnimations:ImplicitAnimationSet>
Expand Down
122 changes: 122 additions & 0 deletions Screenbox/Controls/Extensions/CommandBarExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using CommunityToolkit.WinUI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace Screenbox.Controls.Extensions;

/// <summary>
/// Provides attached dependency properties for the <see cref="CommandBar"/> control.
/// </summary>
internal class CommandBarExtensions
{
/// <summary>
/// Attached <see cref="DependencyProperty"/> for binding a <see cref="KeyboardAccelerator"/> to the more <see cref="Button"/> of the associated <see cref="CommandBar"/>
/// </summary>
public static readonly DependencyProperty MoreButtonKeyboardAcceleratorsProperty = DependencyProperty.RegisterAttached(
"MoreButtonKeyboardAccelerators", typeof(KeyboardAccelerator), typeof(CommandBar), new PropertyMetadata(null, OnMoreButtonKeyboardAcceleratorsPropertyChanged));

/// <summary>
/// Gets the <see cref="KeyboardAccelerator"/> for the more <see cref="Button"/> of the associated with the <see cref="CommandBar"/>
/// </summary>
/// <returns>The <see cref="KeyboardAccelerator"/> associated with the <see cref="CommandBar"/> more <see cref="Button"/>.</returns>
public static KeyboardAccelerator GetMoreButtonKeyboardAccelerators(CommandBar obj)
{
return (KeyboardAccelerator)obj.GetValue(MoreButtonKeyboardAcceleratorsProperty);
}

/// <summary>
/// Sets the <see cref="KeyboardAccelerator"/> to the more <see cref="Button"/> of the associated <see cref="CommandBar"/>
/// </summary>
public static void SetMoreButtonKeyboardAccelerators(CommandBar obj, KeyboardAccelerator value)
{
obj.SetValue(MoreButtonKeyboardAcceleratorsProperty, value);
}

/// <summary>
/// Attached <see cref="DependencyProperty"/> for binding a <see cref="Style"/> to the more <see cref="Button"/> of the associated <see cref="CommandBar"/>
/// </summary>
public static readonly DependencyProperty MoreButtonStyleProperty = DependencyProperty.RegisterAttached(
"MoreButtonStyle", typeof(Style), typeof(CommandBarExtensions), new PropertyMetadata(null, OnMoreButtonStylePropertyChanged));

/// <summary>
/// Gets the <see cref="Style"/> for the more <see cref="Button"/> of the associated with the <see cref="CommandBar"/>
/// </summary>
/// <returns>The <see cref="Style"/> associated with the <see cref="CommandBar"/> more <see cref="Button"/>.</returns>
public static Style GetMoreButtonStyle(CommandBar obj)
{
return (Style)obj.GetValue(MoreButtonStyleProperty);
}

/// <summary>
/// Sets the <see cref="Style"/> to the more <see cref="Button"/> of the associated <see cref="CommandBar"/>
/// </summary>
public static void SetMoreButtonStyle(CommandBar obj, Style value)
{
obj.SetValue(MoreButtonStyleProperty, value);
}

private static void OnCommandBarUnloaded(object sender, RoutedEventArgs args)
{
if (sender is CommandBar commandBar)
{
commandBar.Loaded -= ChangeCommandBarMoreButtonKeyboardAccelerators;
commandBar.Loaded -= ChangeCommandBarMoreButtonStyle;
commandBar.Unloaded -= OnCommandBarUnloaded;
}
}

private static void OnMoreButtonKeyboardAcceleratorsPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
if (sender is CommandBar commandBar)
{
commandBar.Loaded -= ChangeCommandBarMoreButtonKeyboardAccelerators;
commandBar.Unloaded -= OnCommandBarUnloaded;

if (MoreButtonKeyboardAcceleratorsProperty != null)
{
commandBar.Loaded += ChangeCommandBarMoreButtonKeyboardAccelerators;
commandBar.Unloaded += OnCommandBarUnloaded;
}
}
}

private static void ChangeCommandBarMoreButtonKeyboardAccelerators(object sender, RoutedEventArgs args)
{
if (sender is CommandBar commandBar)
{
Button moreButton = commandBar.FindDescendant<Button>(b => b.Name == "MoreButton");
if (moreButton != null)
{
moreButton.KeyboardAccelerators.Add(GetMoreButtonKeyboardAccelerators(commandBar));
}
}
}

private static void OnMoreButtonStylePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
if (sender is CommandBar commandBar)
{
commandBar.Loaded -= ChangeCommandBarMoreButtonStyle;
commandBar.Unloaded -= OnCommandBarUnloaded;

if (MoreButtonStyleProperty != null)
{
commandBar.Loaded += ChangeCommandBarMoreButtonStyle;
commandBar.Unloaded += OnCommandBarUnloaded;
}
}
}

private static void ChangeCommandBarMoreButtonStyle(object sender, RoutedEventArgs args)
{
if (sender is CommandBar commandBar)
{
Button moreButton = commandBar.FindDescendant<Button>(b => b.Name == "MoreButton");
if (moreButton != null)
{
moreButton.Style = GetMoreButtonStyle(commandBar);
}
}
}
}
4 changes: 2 additions & 2 deletions Screenbox/Controls/PlaylistView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
x:Name="SelectionCommandRow"
Grid.Row="0"
Margin="{x:Bind Padding, Mode=OneWay}"
ctAnimations:Implicit.HideAnimations="{StaticResource SelectionCommandBarHideAnimations}"
ctAnimations:Implicit.ShowAnimations="{StaticResource SelectionCommandBarShowAnimations}"
ctAnimations:Implicit.HideAnimations="{StaticResource SelectionRowExitImplicitAnimation}"
ctAnimations:Implicit.ShowAnimations="{StaticResource SelectionRowEntranceImplicitAnimation}"
Visibility="Collapsed">

<Border
Expand Down
35 changes: 17 additions & 18 deletions Screenbox/Pages/AlbumDetailsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,49 +169,45 @@
<!-- Wrap the CommandBar in a Grid which will host the translation animation, this ensures that opening the overflow popup does not reset the command bar position. -->
<Grid x:Name="ButtonPanel">
<CommandBar
Margin="-4,10,0,0"
Padding="0"
Margin="-8,8,0,0"
HorizontalAlignment="Left"
extensions:CommandBarExtensions.MoreButtonStyle="{StaticResource EllipsisDefaultButtonStyle}"
AccessKey="{strings:KeyboardResources Key=CommandMoreOptionsKey}"
DefaultLabelPosition="Right">
<CommandBar.Resources>
<StaticResource x:Key="CommandBarBackground" ResourceKey="ControlFillColorTransparentBrush" />
<StaticResource x:Key="CommandBarBackgroundOpen" ResourceKey="ControlFillColorTransparentBrush" />
<StaticResource x:Key="CommandBarBorderBrushOpen" ResourceKey="ControlFillColorTransparentBrush" />
<StaticResource x:Key="CommandBarHighContrastBorder" ResourceKey="ControlFillColorTransparentBrush" />

<!-- Values modified to align with the dimensions and layout of the default button -->
<x:Double x:Key="AppBarThemeCompactHeight">44</x:Double>
<Thickness x:Key="AppBarButtonContentViewboxMargin">16,14,0,14</Thickness>
<Thickness x:Key="AppBarButtonContentViewboxCollapsedMargin">0,14,0,2</Thickness>
<!--<Thickness x:Key="AppBarButtonTextLabelMargin">6,0,6,8</Thickness>-->
<Thickness x:Key="AppBarButtonTextLabelOnRightMargin">8,12,16,13</Thickness>
<Thickness x:Key="AppBarButtonInnerBorderMargin">4,6,4,6</Thickness>
<!--<Thickness x:Key="AppBarButtonInnerBorderCompactMargin">4,6,4,26</Thickness>-->
<Thickness x:Key="AppBarEllipsisButtonInnerBorderMargin">4,8,4,8</Thickness>
<!-- Adjust margin to match the size and layout of the default button -->
<Thickness x:Key="AppBarButtonContentViewboxMargin">16,16,0,16</Thickness>
<Thickness x:Key="AppBarButtonTextLabelOnRightMargin">8,14,16,15</Thickness>
<Thickness x:Key="AppBarButtonInnerBorderMargin">4,8,4,8</Thickness>
</CommandBar.Resources>

<AppBarButton
x:Name="PlayButton"
AccessKey="{strings:KeyboardResources Key=CommandPlayKey}"
Command="{x:Bind ViewModel.PlayCommand}"
CommandParameter="{x:Bind ViewModel.SortedItems, Mode=OneWay, Converter={StaticResource FirstOrDefaultConverter}}"
Icon="{ui:FontIcon FontFamily={StaticResource ScreenboxSymbolThemeFontFamily},
Glyph={StaticResource PlayGlyph}}"
Label="{strings:Resources Key=Play}"
Style="{StaticResource AccentButtonAppBarButtonStyle}"
XYFocusDown="{x:Bind ItemList}">
Style="{StaticResource AccentButtonAppBarButtonStyle}">
<interactivity:Interaction.Behaviors>
<interactions:AutoFocusBehavior />
</interactivity:Interaction.Behaviors>
</AppBarButton>

<AppBarButton
AccessKey="{strings:KeyboardResources Key=CommandShuffleAndPlayKey}"
Command="{x:Bind ViewModel.ShuffleAndPlayCommand}"
Icon="{ui:FontIcon FontFamily={StaticResource ScreenboxSymbolThemeFontFamily},
Glyph={StaticResource ShuffleGlyph},
MirroredWhenRightToLeft=True}"
Label="{strings:Resources Key=ShuffleAndPlay}"
Style="{StaticResource DefaultButtonAppBarButtonStyle}"
XYFocusDown="{x:Bind ItemList}"
XYFocusLeft="{x:Bind PlayButton}" />
Style="{StaticResource DefaultButtonAppBarButtonStyle}" />
</CommandBar>
</Grid>
</StackPanel>
Expand All @@ -229,8 +225,7 @@
IsItemClickEnabled="True"
ItemContainerStyle="{StaticResource MediaListViewItemStyle}"
ItemsSource="{x:Bind ViewModel.SortedItems}"
SelectionMode="None"
XYFocusUp="{x:Bind PlayButton}">
SelectionMode="None">
<ListView.ItemTemplate>
<DataTemplate>
<controls:MediaListViewItem
Expand All @@ -256,6 +251,10 @@
</interactivity:Interaction.Behaviors>
</ListView>

<interactivity:Interaction.Behaviors>
<interactions:GamepadXYNavigationBehavior />
</interactivity:Interaction.Behaviors>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="NavigationViewStates">
<VisualState x:Name="Expanded" />
Expand Down
35 changes: 17 additions & 18 deletions Screenbox/Pages/ArtistDetailsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,48 +250,44 @@
<!-- Wrap the CommandBar in a Grid which will host the translation animation, this ensures that opening the overflow popup does not reset the command bar position. -->
<Grid x:Name="ButtonPanel">
<CommandBar
Margin="-4,10,0,0"
Padding="0"
Margin="-8,8,0,0"
HorizontalAlignment="Left"
extensions:CommandBarExtensions.MoreButtonStyle="{StaticResource EllipsisDefaultButtonStyle}"
AccessKey="{strings:KeyboardResources Key=CommandMoreOptionsKey}"
DefaultLabelPosition="Right">
<CommandBar.Resources>
<StaticResource x:Key="CommandBarBackground" ResourceKey="ControlFillColorTransparentBrush" />
<StaticResource x:Key="CommandBarBackgroundOpen" ResourceKey="ControlFillColorTransparentBrush" />
<StaticResource x:Key="CommandBarBorderBrushOpen" ResourceKey="ControlFillColorTransparentBrush" />
<StaticResource x:Key="CommandBarHighContrastBorder" ResourceKey="ControlFillColorTransparentBrush" />

<!-- Values modified to align with the dimensions and layout of the default button -->
<x:Double x:Key="AppBarThemeCompactHeight">44</x:Double>
<Thickness x:Key="AppBarButtonContentViewboxMargin">16,14,0,14</Thickness>
<Thickness x:Key="AppBarButtonContentViewboxCollapsedMargin">0,14,0,2</Thickness>
<!--<Thickness x:Key="AppBarButtonTextLabelMargin">6,0,6,8</Thickness>-->
<Thickness x:Key="AppBarButtonTextLabelOnRightMargin">8,12,16,13</Thickness>
<Thickness x:Key="AppBarButtonInnerBorderMargin">4,6,4,6</Thickness>
<!--<Thickness x:Key="AppBarButtonInnerBorderCompactMargin">4,6,4,26</Thickness>-->
<Thickness x:Key="AppBarEllipsisButtonInnerBorderMargin">4,8,4,8</Thickness>
<!-- Adjust margin to match the size and layout of the default button -->
<Thickness x:Key="AppBarButtonContentViewboxMargin">16,16,0,16</Thickness>
<Thickness x:Key="AppBarButtonTextLabelOnRightMargin">8,14,16,15</Thickness>
<Thickness x:Key="AppBarButtonInnerBorderMargin">4,8,4,8</Thickness>
</CommandBar.Resources>

<AppBarButton
x:Name="PlayButton"
AccessKey="{strings:KeyboardResources Key=CommandPlayKey}"
Command="{x:Bind ViewModel.PlayCommand}"
Icon="{ui:FontIcon FontFamily={StaticResource ScreenboxSymbolThemeFontFamily},
Glyph={StaticResource PlayGlyph}}"
Label="{strings:Resources Key=Play}"
Style="{StaticResource AccentButtonAppBarButtonStyle}"
XYFocusDown="{x:Bind ItemList}">
Style="{StaticResource AccentButtonAppBarButtonStyle}">
<interactivity:Interaction.Behaviors>
<interactions:AutoFocusBehavior />
</interactivity:Interaction.Behaviors>
</AppBarButton>

<AppBarButton
AccessKey="{strings:KeyboardResources Key=CommandShuffleAndPlayKey}"
Command="{x:Bind ViewModel.ShuffleAndPlayCommand}"
Icon="{ui:FontIcon FontFamily={StaticResource ScreenboxSymbolThemeFontFamily},
Glyph={StaticResource ShuffleGlyph},
MirroredWhenRightToLeft=True}"
Label="{strings:Resources Key=ShuffleAndPlay}"
Style="{StaticResource DefaultButtonAppBarButtonStyle}"
XYFocusDown="{x:Bind ItemList}"
XYFocusLeft="{x:Bind PlayButton}" />
Style="{StaticResource DefaultButtonAppBarButtonStyle}" />
</CommandBar>
</Grid>
</StackPanel>
Expand All @@ -309,8 +305,7 @@
IsItemClickEnabled="True"
ItemContainerStyle="{StaticResource MediaListViewItemStyle}"
ItemsSource="{x:Bind AlbumSource.View}"
SelectionMode="None"
XYFocusUp="{x:Bind PlayButton}">
SelectionMode="None">
<ListView.ItemTemplate>
<DataTemplate>
<controls:MediaListViewItem
Expand Down Expand Up @@ -373,6 +368,10 @@
</interactivity:Interaction.Behaviors>
</ListView>

<interactivity:Interaction.Behaviors>
<interactions:GamepadXYNavigationBehavior />
</interactivity:Interaction.Behaviors>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="NavigationViewStates">
<VisualState x:Name="Expanded" />
Expand Down
4 changes: 4 additions & 0 deletions Screenbox/Pages/FolderViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@
Text="{strings:Resources Key=EmptyFolder}"
Visibility="{x:Bind ViewModel.IsEmpty, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}" />

<interactivity:Interaction.Behaviors>
<interactions:GamepadXYNavigationBehavior />
</interactivity:Interaction.Behaviors>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="NavigationViewStates">
<VisualState x:Name="Expanded" />
Expand Down
4 changes: 2 additions & 2 deletions Screenbox/Pages/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@
Grid.Column="1"
Margin="{StaticResource AppTitleMarginExpanded}"
VerticalAlignment="Center"
ctAnimations:Implicit.HideAnimations="{StaticResource SimpleHideAnimations}"
ctAnimations:Implicit.ShowAnimations="{StaticResource SimpleShowAnimations}"
ctAnimations:Implicit.HideAnimations="{StaticResource FadeOutImplicitAnimation}"
ctAnimations:Implicit.ShowAnimations="{StaticResource FadeInImplicitAnimation}"
IsHitTestVisible="False"
Orientation="Horizontal">
<Image
Expand Down
Loading

0 comments on commit da5229d

Please sign in to comment.