Skip to content

Commit 134817f

Browse files
committed
Revert "Fluent2: use OS accent shades on Windows"
This reverts part of the commit 71bbc90.
1 parent 319b470 commit 134817f

5 files changed

Lines changed: 7 additions & 102 deletions

File tree

src/Avalonia.Base/Platform/PlatformColorValues.cs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,6 @@ public Color AccentColor3
6161
init => _accentColor3 = value;
6262
}
6363

64-
/// <summary>
65-
/// Dark shade 1 of <see cref="AccentColor1"/>, when the platform provides one (Windows does).
66-
/// Null when the platform only reports the base accent color; consumers are expected to compute a shade instead.
67-
/// </summary>
68-
public Color? AccentColorDark1 { get; init; }
69-
70-
/// <summary>
71-
/// Dark shade 2 of <see cref="AccentColor1"/>, when the platform provides one. See <see cref="AccentColorDark1"/>.
72-
/// </summary>
73-
public Color? AccentColorDark2 { get; init; }
74-
75-
/// <summary>
76-
/// Dark shade 3 of <see cref="AccentColor1"/>, when the platform provides one. See <see cref="AccentColorDark1"/>.
77-
/// </summary>
78-
public Color? AccentColorDark3 { get; init; }
79-
80-
/// <summary>
81-
/// Light shade 1 of <see cref="AccentColor1"/>, when the platform provides one. See <see cref="AccentColorDark1"/>.
82-
/// </summary>
83-
public Color? AccentColorLight1 { get; init; }
84-
85-
/// <summary>
86-
/// Light shade 2 of <see cref="AccentColor1"/>, when the platform provides one. See <see cref="AccentColorDark1"/>.
87-
/// </summary>
88-
public Color? AccentColorLight2 { get; init; }
89-
90-
/// <summary>
91-
/// Light shade 3 of <see cref="AccentColor1"/>, when the platform provides one. See <see cref="AccentColorDark1"/>.
92-
/// </summary>
93-
public Color? AccentColorLight3 { get; init; }
94-
9564
public PlatformColorValues()
9665
{
9766
AccentColor1 = DefaultAccent;

src/Avalonia.Themes.Fluent2/Accents/SystemAccentColors.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ internal sealed class SystemAccentColors : ResourceProvider
2020
private static readonly Color s_defaultSystemAccentColor = Color.FromRgb(0, 120, 215);
2121
// Static shade values from WinUI (matching the Uno/WinUI SystemResources defaults). Used when
2222
// the platform provides no accent color, so the out-of-the-box palette matches WinUI exactly.
23-
// When the platform reports the OS-computed shades (Windows does, via UISettings) those are
24-
// used verbatim; otherwise an OS-provided base accent gets HSL-computed shades.
23+
// OS-provided accent colors get computed shades instead.
2524
private static readonly Color s_defaultSystemAccentColorDark1 = Color.FromUInt32(0xFF005A9E);
2625
private static readonly Color s_defaultSystemAccentColorDark2 = Color.FromUInt32(0xFF004275);
2726
private static readonly Color s_defaultSystemAccentColorDark3 = Color.FromUInt32(0xFF002642);
@@ -118,22 +117,11 @@ private void EnsureColors()
118117
{
119118
_invalidateColors = false;
120119

121-
var colorValues = GetFromOwner(Owner)?.GetColorValues();
120+
var platformSettings = GetFromOwner(Owner);
122121

123-
_systemAccentColor = colorValues?.AccentColor1 ?? s_defaultSystemAccentColor;
122+
_systemAccentColor = platformSettings?.GetColorValues().AccentColor1 ?? s_defaultSystemAccentColor;
124123

125-
if (colorValues is
126-
{
127-
AccentColorDark1: { } dark1, AccentColorDark2: { } dark2, AccentColorDark3: { } dark3,
128-
AccentColorLight1: { } light1, AccentColorLight2: { } light2, AccentColorLight3: { } light3
129-
})
130-
{
131-
// The platform reported the OS-computed shades (Windows, via UISettings);
132-
// use them verbatim so the palette matches the OS exactly.
133-
(_systemAccentColorDark1, _systemAccentColorDark2, _systemAccentColorDark3) = (dark1, dark2, dark3);
134-
(_systemAccentColorLight1, _systemAccentColorLight2, _systemAccentColorLight3) = (light1, light2, light3);
135-
}
136-
else if (_systemAccentColor == s_defaultSystemAccentColor)
124+
if (_systemAccentColor == s_defaultSystemAccentColor)
137125
{
138126
// Platforms without a real accent color report the default; use WinUI's static
139127
// shade values so the out-of-the-box palette matches WinUI exactly.

src/Avalonia.Themes.Fluent2/README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Migrating from `Avalonia.Themes.Fluent`: change the package reference and swap
4747
| Scroll bars | 16 px rail | **12 px rail, 2 px collapsed thumb** |
4848
| Window background | AltHigh | **SolidBackgroundFillColorBase** (#F3F3F3/#202020) |
4949
| Default accent shades | HSL-computed | **WinUI static values** (when no OS accent) |
50-
| OS accent shades (Windows) | HSL-computed | **read from the OS** (`UISettings` Light1–3/Dark1–3) |
5150

5251
One deliberate deviation from WinUI (following FluentAvalonia's lead): CheckBox
5352
and RadioButton do **not** get WinUI's forced 120 px `MinWidth` — they size to
@@ -80,10 +79,8 @@ English-only for now.
8079
- No HighContrast variant yet (same as v1).
8180
- AnimatedIcon glyph animations are approximated with static glyphs and simple
8281
transitions.
83-
- On Windows the six accent shades (`SystemAccentColorDark1``Light3`) come
84-
straight from the OS; on platforms that report only a base accent color
85-
(macOS, Linux) the shades are HSL-computed and can deviate slightly from
86-
Windows' palette algorithm.
82+
- OS-provided accent colors still use HSL-computed shades, which can deviate
83+
slightly from Windows' palette algorithm.
8784

8885
## Compatibility tests
8986

src/Windows/Avalonia.Win32/Win32PlatformSettings.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,7 @@ private PlatformColorValues GetUncachedColorValues()
8686
PlatformThemeVariant.Dark :
8787
PlatformThemeVariant.Light,
8888
ContrastPreference = ColorContrastPreference.NoPreference,
89-
AccentColor1 = accent,
90-
AccentColorDark1 = uiSettings.GetColorValue(UIColorType.AccentDark1).ToAvalonia(),
91-
AccentColorDark2 = uiSettings.GetColorValue(UIColorType.AccentDark2).ToAvalonia(),
92-
AccentColorDark3 = uiSettings.GetColorValue(UIColorType.AccentDark3).ToAvalonia(),
93-
AccentColorLight1 = uiSettings.GetColorValue(UIColorType.AccentLight1).ToAvalonia(),
94-
AccentColorLight2 = uiSettings.GetColorValue(UIColorType.AccentLight2).ToAvalonia(),
95-
AccentColorLight3 = uiSettings.GetColorValue(UIColorType.AccentLight3).ToAvalonia()
89+
AccentColor1 = accent
9690
};
9791
}
9892
}

tests/Avalonia.Themes.Fluent2.UnitTests/PaletteTests.cs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Avalonia.Controls;
22
using Avalonia.Media;
3-
using Avalonia.Platform;
43
using Avalonia.Styling;
54

65
namespace Avalonia.Themes.Fluent2.UnitTests;
@@ -66,48 +65,6 @@ public void Default_accent_uses_winui_static_shades()
6665
}
6766
}
6867

69-
[AvaloniaFact]
70-
public void Platform_provided_accent_shades_take_precedence_over_computed_ones()
71-
{
72-
var originalSettings = AvaloniaLocator.Current.GetService<IPlatformSettings>();
73-
Assert.NotNull(originalSettings);
74-
AvaloniaLocator.CurrentMutable.Bind<IPlatformSettings>().ToConstant(new ShadeReportingPlatformSettings());
75-
76-
var theme = new Fluent2Theme();
77-
var app = Application.Current!;
78-
app.Styles.Add(theme);
79-
try
80-
{
81-
Assert.True(app.TryGetResource("SystemAccentColor", ThemeVariant.Light, out var accent));
82-
Assert.Equal(Colors.Crimson, Assert.IsType<Color>(accent));
83-
84-
// The OS-reported shades are used verbatim, not HSL-computed from the base color.
85-
Assert.True(app.TryGetResource("SystemAccentColorDark1", ThemeVariant.Light, out var dark1));
86-
Assert.Equal(Colors.DarkRed, Assert.IsType<Color>(dark1));
87-
Assert.True(app.TryGetResource("SystemAccentColorLight3", ThemeVariant.Light, out var light3));
88-
Assert.Equal(Colors.MistyRose, Assert.IsType<Color>(light3));
89-
}
90-
finally
91-
{
92-
app.Styles.Remove(theme);
93-
AvaloniaLocator.CurrentMutable.Bind<IPlatformSettings>().ToConstant(originalSettings);
94-
}
95-
}
96-
97-
private sealed class ShadeReportingPlatformSettings : DefaultPlatformSettings
98-
{
99-
public override PlatformColorValues GetColorValues() => new()
100-
{
101-
AccentColor1 = Colors.Crimson,
102-
AccentColorDark1 = Colors.DarkRed,
103-
AccentColorDark2 = Colors.Maroon,
104-
AccentColorDark3 = Colors.Brown,
105-
AccentColorLight1 = Colors.Salmon,
106-
AccentColorLight2 = Colors.LightSalmon,
107-
AccentColorLight3 = Colors.MistyRose,
108-
};
109-
}
110-
11168
[AvaloniaFact]
11269
public void Legacy_palette_colors_derive_fluent2_tokens()
11370
{

0 commit comments

Comments
 (0)