Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 50 additions & 23 deletions FluentFlyoutWPF/Controls/TaskbarWidgetControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public TaskbarWidgetControl()
}

Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)); ;

// Initialize control order
ReorderControls();
}
Expand Down Expand Up @@ -179,27 +179,34 @@ private void Grid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

public (double logicalWidth, double logicalHeight) CalculateSize(double dpiScale)
{
// calculate widget width - use cached values if text hasn't changed
string currentTitle = SongTitle.Text;
string currentArtist = SongArtist.Text;

if (!string.Equals(currentTitle, _cachedTitleText, StringComparison.Ordinal))
{
_cachedTitleWidth = StringWidth.GetStringWidth(currentTitle, 400);
_cachedTitleText = currentTitle;
}
if (!string.Equals(currentArtist, _cachedArtistText, StringComparison.Ordinal))
double logicalWidth = 45;

if (SettingsManager.Current.TaskbarSongInfoEnabled && SongInfoStackPanel.Visibility == Visibility.Visible)
{
_cachedArtistWidth = StringWidth.GetStringWidth(currentArtist, 400);
_cachedArtistText = currentArtist;
}

double logicalWidth = Math.Max(_cachedTitleWidth, _cachedArtistWidth) + 55; // add margin for cover image
// maximum width limit, same as Windows native widget
logicalWidth = Math.Min(logicalWidth, _nativeWidgetsPadding / _scale);
// calculate widget width - use cached values if text hasn't changed
string currentTitle = SongTitle.Text;
string currentArtist = SongArtist.Text;

if (!string.Equals(currentTitle, _cachedTitleText, StringComparison.Ordinal))
{
_cachedTitleWidth = StringWidth.GetStringWidth(currentTitle, 400);
_cachedTitleText = currentTitle;
}
if (!string.Equals(currentArtist, _cachedArtistText, StringComparison.Ordinal))
{
_cachedArtistWidth = StringWidth.GetStringWidth(currentArtist, 400);
_cachedArtistText = currentArtist;
}

logicalWidth = Math.Max(_cachedTitleWidth, _cachedArtistWidth) + 55; // add margin for cover image
// maximum width limit, same as Windows native widget
logicalWidth = Math.Min(logicalWidth, _nativeWidgetsPadding / _scale);

SongTitle.Width = Math.Max(logicalWidth - 58, 0);
SongArtist.Width = Math.Max(logicalWidth - 58, 0);
SongTitle.Width = Math.Max(logicalWidth - 58, 0);
SongArtist.Width = Math.Max(logicalWidth - 58, 0);
}

// add space for playback controls if enabled and visible
if (SettingsManager.Current.TaskbarWidgetControlsEnabled && ControlsStackPanel.Visibility == Visibility.Visible)
Expand Down Expand Up @@ -252,6 +259,19 @@ public void UpdateUi(string title, string artist, BitmapImage? icon, GlobalSyste
_isPaused = true;
}

// adjust UI based on available controls
Dispatcher.Invoke(() =>
{
if (!SettingsManager.Current.TaskbarSongInfoEnabled)
{
SongInfoStackPanel.Visibility = Visibility.Collapsed;
}
else
{
SongInfoStackPanel.Visibility = Visibility.Visible;
}
});

// adjust UI based on available controls
Dispatcher.Invoke(() =>
{
Expand Down Expand Up @@ -341,6 +361,9 @@ public void UpdateUi(string title, string artist, BitmapImage? icon, GlobalSyste
ControlsStackPanel.Visibility = SettingsManager.Current.TaskbarWidgetControlsEnabled
? Visibility.Visible
: Visibility.Collapsed;
SongInfoStackPanel.Visibility = SettingsManager.Current.TaskbarSongInfoEnabled
? Visibility.Visible
: Visibility.Collapsed;

Visibility = Visibility.Visible;
});
Expand Down Expand Up @@ -369,11 +392,15 @@ private async void AnimateEntrance()
EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseOut }
};

// Apply animations
SongInfoStackPanel.BeginAnimation(OpacityProperty, opacityAnimation);
TranslateTransform translateTransform = new();
SongInfoStackPanel.RenderTransform = translateTransform;
translateTransform.BeginAnimation(TranslateTransform.XProperty, translateAnimation);
// don't play SongInfoStackPanel animation if it's not enabled
if (SettingsManager.Current.TaskbarSongInfoEnabled)
{
// Apply animations
SongInfoStackPanel.BeginAnimation(OpacityProperty, opacityAnimation);
TranslateTransform translateTransform = new();
SongInfoStackPanel.RenderTransform = translateTransform;
translateTransform.BeginAnimation(TranslateTransform.XProperty, translateAnimation);
}

// don't play ControlsStackPanel animation if it's not enabled
if (!SettingsManager.Current.TaskbarWidgetControlsEnabled)
Expand Down
14 changes: 12 additions & 2 deletions FluentFlyoutWPF/Pages/TaskbarWidgetPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Margin="0,0,0,24">
<Border CornerRadius="10" ClipToBounds="True" Width="164" Height="98">
Expand Down Expand Up @@ -225,7 +226,7 @@
</ui:CardControl.Header>
<controls:ToggleSwitch IsChecked="{Binding TaskbarWidgetControlsEnabled, Mode=TwoWay}" IsEnabled="{Binding IsPremiumUnlocked}" />
</ui:CardControl>
<ui:CardControl Grid.Row="13" Icon="{ui:SymbolIcon ArrowMove24}" Margin="0,0,0,12">
<ui:CardControl Grid.Row="13" Icon="{ui:SymbolIcon ArrowMove24}" Margin="0,0,0,3">
<ui:CardControl.Header>
<StackPanel Orientation="Vertical">
<TextBlock Text="{DynamicResource TaskbarWidgetControlsPositionTitle}" FontSize="14" FontWeight="Regular" VerticalAlignment="Center" />
Expand All @@ -237,7 +238,16 @@
<ComboBoxItem Content="{DynamicResource PositionRight}" />
</ComboBox>
</ui:CardControl>
<ui:CardControl Grid.Row="14" Icon="{ui:SymbolIcon Wand24}" Margin="0,0,0,76">
<ui:CardControl Grid.Row="14" Icon="{ui:SymbolIcon Info24}" Margin="0,0,0,12">
<ui:CardControl.Header>
<StackPanel Orientation="Vertical">
<TextBlock Text="{DynamicResource TaskbarWidgetSongInfoTitle}" FontSize="14" FontWeight="Regular" VerticalAlignment="Center" />
<TextBlock Text="{DynamicResource TaskbarWidgetSongInfoDescription}" FontSize="12" Opacity="0.5" />
</StackPanel>
</ui:CardControl.Header>
<controls:ToggleSwitch IsChecked="{Binding TaskbarSongInfoEnabled, Mode=TwoWay}" IsEnabled="{Binding IsPremiumUnlocked}" />
</ui:CardControl>
<ui:CardControl Grid.Row="15" Icon="{ui:SymbolIcon Wand24}" Margin="0,0,0,76">
<ui:CardControl.Header>
<StackPanel Orientation="Vertical">
<TextBlock Text="{DynamicResource TaskbarWidgetAnimatedTitle}" FontSize="14" FontWeight="Regular" VerticalAlignment="Center" />
Expand Down
2 changes: 2 additions & 0 deletions FluentFlyoutWPF/Resources/Localization/Dictionary-en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ hides repeat, shuffle and player info</System:String>
<System:String x:Key="TaskbarWidgetAutoHideDescription">Hides the widget automatically when media is paused</System:String>
<System:String x:Key="TaskbarWidgetControlsTitle">Widget Media Controls</System:String>
<System:String x:Key="TaskbarWidgetControlsDescription">Show media control buttons on the widget</System:String>
<System:String x:Key="TaskbarWidgetSongInfoTitle">Widget Media Song Info</System:String>
<System:String x:Key="TaskbarWidgetSongInfoDescription">Show song info on the widget, as opposed to just the icon</System:String>
<System:String x:Key="TaskbarWidgetControlsPositionTitle">Media Controls Position</System:String>
<System:String x:Key="TaskbarWidgetControlsPositionDescription">Choose where to display the media control buttons</System:String>
<System:String x:Key="PositionLeft">Left</System:String>
Expand Down
19 changes: 16 additions & 3 deletions FluentFlyoutWPF/ViewModels/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public string LockKeysDurationText
/// 0 = Default behavior, 1 = Monitor containing the focused window, 2 = Monitor containing the cursor.
[ObservableProperty]
public partial int LockKeysMonitorPreference { get; set; }

/// <summary>
/// Determines if the user has updated to a new version
/// </summary>
Expand Down Expand Up @@ -339,7 +339,7 @@ public string LockKeysDurationText
/// </summary>
[ObservableProperty]
public partial int TaskbarWidgetSelectedMonitor { get; set; }

/// <summary>
/// Autohide Widget after a few milliseconds after pause
/// </summary>
Expand Down Expand Up @@ -414,6 +414,12 @@ public string TaskbarWidgetManualPaddingText
[ObservableProperty]
public partial int TaskbarWidgetControlsPosition { get; set; }

/// <summary>
/// Whether or not to show the song info in the taskbar widget
/// </summary>
[ObservableProperty]
public partial bool TaskbarSongInfoEnabled { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the taskbar widget should play animations.
/// </summary>
Expand Down Expand Up @@ -577,6 +583,7 @@ public UserSettings()
TaskbarWidgetHideCompletely = false;
TaskbarWidgetControlsEnabled = false;
TaskbarWidgetControlsPosition = 1;
TaskbarSongInfoEnabled = true;
TaskbarWidgetAnimated = true;
TaskbarVisualizerEnabled = false;
TaskbarVisualizerPosition = 1;
Expand Down Expand Up @@ -684,11 +691,17 @@ partial void OnTaskbarWidgetControlsEnabledChanged(bool oldValue, bool newValue)
partial void OnTaskbarWidgetControlsPositionChanged(int oldValue, int newValue)
{
if (oldValue == newValue || _initializing) return;

MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
mainWindow.taskbarWindow?.Widget?.ReorderControls();
}

partial void OnTaskbarSongInfoEnabledChanged(bool oldValue, bool newValue)
{
if (oldValue == newValue || _initializing) return;
UpdateTaskbar();
}

partial void OnTaskbarVisualizerPositionChanged(int oldValue, int newValue)
{
if (oldValue == newValue || _initializing) return;
Expand Down