Skip to content

Commit

Permalink
fix accent color
Browse files Browse the repository at this point in the history
  • Loading branch information
heftymouse committed Jun 16, 2024
1 parent 0612a92 commit cba81e5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/Files.App/Data/Contracts/IAppThemeModeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Windows.UI;

namespace Files.App.Data.Contracts
{
Expand All @@ -18,6 +19,11 @@ public interface IAppThemeModeService
/// </summary>
public ElementTheme AppThemeMode { get; set; }

/// <summary>
/// Gets the default accent fill color for the current theme mode.
/// </summary>
public Color DefaultAccentColor { get; }

/// <summary>
/// Refreshes the application theme mode only for the main window.
/// </summary>
Expand Down
16 changes: 15 additions & 1 deletion src/Files.App/Services/App/AppThemeModeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media;
using Windows.Storage;
using Windows.UI;
using Windows.UI.ViewManagement;
Expand Down Expand Up @@ -34,6 +35,19 @@ public ElementTheme AppThemeMode
}
}

/// <inheritdoc/>
public Color DefaultAccentColor
{
get => AppThemeMode switch
{
// these values are from the definition of AccentFillColorDefaultBrush in generic.xaml
// will have to be updated if WinUI changes in the future
ElementTheme.Light => (Color)(App.Current.Resources["SystemAccentColorDark1"]),
ElementTheme.Dark => (Color)(App.Current.Resources["SystemAccentColorLight2"]),
ElementTheme.Default or _ => (App.Current.Resources["AccentFillColorDefaultBrush"] as SolidColorBrush)!.Color
};
}

/// <inheritdoc/>
public event EventHandler? AppThemeModeChanged;

Expand Down Expand Up @@ -99,7 +113,7 @@ public void SetAppThemeMode(Window? window = null, AppWindowTitleBar? titleBar =
}
catch (Exception ex)
{
App.Logger.LogWarning(ex, "Failed to change theme mode of the app.");
App.Logger.LogWarning(ex, "Failed to change theme mode of the app.");
}
}

Expand Down
27 changes: 14 additions & 13 deletions src/Files.App/UserControls/StatusCenter/SpeedGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Hosting;
using Microsoft.UI.Xaml.Media;
using System.Collections.Specialized;
using System.Numerics;

Expand Down Expand Up @@ -107,6 +106,7 @@ private void OnPointsChanged(object? sender, NotifyCollectionChangedEventArgs e)

private void OnAppThemeModeChanged(object? sender, EventArgs e)
{
// this seemingly doesn't fire? leaving it here in case it does in the future (if it's ever used outside of the flyout)
if (initialized)
SetGraphColors();
}
Expand All @@ -131,26 +131,28 @@ private void InitGraph()
rootClip.Top = 1.5f;
rootClip.Left = 1.5f;
rootClip.Bottom = height - 1.5f;
rootClip.Right = width - 2f; // i fear i might be a victim of DPI scaling here
rootClip.Right = width - 2f;
rootClip.TopLeftRadius = new(4f);
rootClip.TopRightRadius = new(4f);
rootClip.BottomLeftRadius = new(4f);
rootClip.BottomRightRadius = new(4f);
rootVisual.Clip = rootClip;

var accentColor = (App.Current.Resources["AccentFillColorDefaultBrush"] as SolidColorBrush)!.Color;

backgroundBrush = compositor.CreateColorBrush(accentColor with { A = 0x0f });
backgroundBrush = compositor.CreateColorBrush();

var graphFillBrush = compositor.CreateLinearGradientBrush();
graphFillBrush.StartPoint = new(0.5f, 0f);
graphFillBrush.EndPoint = new(0.5f, 1f);
graphFillTop = compositor.CreateColorGradientStop(0f, accentColor with { A = 0x7f });
graphFillBottom = compositor.CreateColorGradientStop(1f, accentColor with { A = 0x0f });
graphFillTop = compositor.CreateColorGradientStop();
graphFillTop.Offset = 0f;
graphFillBottom = compositor.CreateColorGradientStop();
graphFillBottom.Offset = 1f;
graphFillBrush.ColorStops.Add(graphFillBottom);
graphFillBrush.ColorStops.Add(graphFillTop);

graphStrokeBrush = compositor.CreateColorBrush(accentColor);
graphStrokeBrush = compositor.CreateColorBrush();

SetGraphColors();

var container = compositor.CreateSpriteVisual();
container.Size = rootVisual.Size;
Expand Down Expand Up @@ -198,13 +200,11 @@ void UpdateGraph()
graphGeometry.Path = path;

using var lineAnim = compositor.CreateScalarKeyFrameAnimation();
lineAnim.InsertExpressionKeyFrame(0f, "this.StartingValue");
lineAnim.InsertKeyFrame(1f, YValue(Points[^1].Y), linearEasing);
lineAnim.Duration = TimeSpan.FromMilliseconds(72);
line.StartAnimation("Offset.Y", lineAnim);

using var clipAnim = compositor.CreateScalarKeyFrameAnimation();
clipAnim.InsertExpressionKeyFrame(0f, "this.StartingValue");
clipAnim.InsertKeyFrame(1f, width - (width * Points[^1].X / 100f) - 1, linearEasing);
clipAnim.Duration = TimeSpan.FromMilliseconds(72);
graphClip.StartAnimation("RightInset", clipAnim);
Expand All @@ -231,12 +231,13 @@ CompositionPath CreatePathFromPoints()

void SetGraphColors()
{
var accentColor = (App.Current.Resources["AccentFillColorDefaultBrush"] as SolidColorBrush)!.Color;
var accentColor = themeModeService.DefaultAccentColor;

backgroundBrush.Color = accentColor with { A = 0x0f };
var veryLightColor = accentColor with { A = 0x0f };
backgroundBrush.Color = veryLightColor;

graphFillTop.Color = accentColor with { A = 0x7f };
graphFillBottom.Color = accentColor with { A = 0x0f };
graphFillBottom.Color = veryLightColor;

graphStrokeBrush.Color = accentColor;
}
Expand Down

0 comments on commit cba81e5

Please sign in to comment.