Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
fix(ui): hold dark Material You accent labels to 4.5:1
adnan-bhaldarda3e9f78ad1a
diff --git a/src/Filee.App/Services/MaterialYouPalette.cs b/src/Filee.App/Services/MaterialYouPalette.csindex 26fd0ce8..5e793d49 100644--- a/src/Filee.App/Services/MaterialYouPalette.cs+++ b/src/Filee.App/Services/MaterialYouPalette.cs@@ -150,18 +150,22 @@ public sealed class MaterialYouPaletteprivate static readonly Color DarkOnAccent = Color.Parse("#1F1E1D");- /// <summary>Lowest contrast at which a white label is still kept on a dark-mode accent fill (WCAG's 3:1 for UI components).</summary>- public const double MinWhiteLabelContrast = 3.0;-private static readonly Color DarkModeDarkLabel = Color.Parse("#16141A");/// <summary>- /// The label colour on a dark-mode accent fill. White stays white whenever it reads (3:1 or better), which keeps the- /// buttons the way they looked before: Lavender (#7F77DD) is 3.76:1 with white, but the old luminance cut-off (0.45)- /// turned its labels black. Only fills that are too pale for white (pastels, lightened accents) get the dark label.+ /// The label colour on a dark-mode accent fill, held to the same <see cref="MinAccentContrast"/> (4.5:1, normal-size+ /// text) as in light mode. White is used when it reaches that; otherwise the dark label, which has more contrast on+ /// mid-tone fills such as Lavender (#7F77DD: 3.76:1 with white, 4.86:1 with the dark label). The few fills where+ /// neither reaches 4.5:1 get whichever of the two is higher./// </summary>- internal static Color DarkModeOnAccent(Color fill) =>- ContrastRatio(fill, Colors.White) >= MinWhiteLabelContrast ? Colors.White : DarkModeDarkLabel;+ internal static Color DarkModeOnAccent(Color fill)+ {+ var white = ContrastRatio(fill, Colors.White);+ if (white >= MinAccentContrast)+ return Colors.White;++ return ContrastRatio(fill, DarkModeDarkLabel) >= white ? DarkModeDarkLabel : Colors.White;+ }/// <summary>/// Picks the light-mode accent fill and the colour used on top of it. The fill stays as close to the chosen accentdiff --git a/tests/Filee.App.Tests/MaterialYouThemeTests.cs b/tests/Filee.App.Tests/MaterialYouThemeTests.csindex 6c70f051..fb0898a6 100644--- a/tests/Filee.App.Tests/MaterialYouThemeTests.cs+++ b/tests/Filee.App.Tests/MaterialYouThemeTests.cs@@ -535,27 +535,21 @@ public class MaterialYouThemeTests}[Fact]- public void Dark_accent_labels_stay_white_when_white_reads_and_turn_dark_only_on_pale_fills()+ public void Dark_accent_labels_reach_the_same_contrast_as_in_light_mode(){- // Lavender in dark mode is #7F77DD, which is 3.76:1 with white. Its Save / New labels must stay white, not black.+ // Lavender in dark mode is #7F77DD: white would be 3.76:1, so it gets the dark label (4.86:1).var lavender = MaterialYouPalette.Generate(Color.Parse("#7F77DD"), isDark: true);- Assert.Equal(Color.Parse("#7F77DD"), lavender.Accent);- Assert.Equal(Colors.White, lavender.OnAccent);+ Assert.NotEqual(Colors.White, lavender.OnAccent);- // Pale fills cannot carry white: they get the dark label.- foreach (var pale in new[] { "#F5C26B", "#8FD6C0" })- {- var dark = MaterialYouPalette.Generate(Color.Parse(pale), isDark: true);- Assert.NotEqual(Colors.White, dark.OnAccent);- }+ var seeds = ThemeService.Presets.Select(p => p.DarkColor)+ .Concat(ThemeService.Swatches.Select(hex => Color.Parse(hex)));- // Whatever the label is, it always reads on its fill.- foreach (var hex in new[] { "#7F77DD", "#1D9E75", "#D85A30", "#378ADD", "#D4537E", "#BA7517", "#639922", "#5F5E5A", "#F5C26B", "#8FD6C0" })+ foreach (var seed in seeds){- var dark = MaterialYouPalette.Generate(Color.Parse(hex), isDark: true);+ var dark = MaterialYouPalette.Generate(seed, isDark: true);var ratio = MaterialYouPalette.ContrastRatio(dark.Accent, dark.OnAccent);- Assert.True(ratio >= MaterialYouPalette.MinWhiteLabelContrast,- $"{hex}: {dark.OnAccent} on {dark.Accent} has contrast {ratio:F2}");+ Assert.True(ratio >= MaterialYouPalette.MinAccentContrast,+ $"{seed}: {dark.OnAccent} on {dark.Accent} has contrast {ratio:F2}");}}