-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[API Proposal] Introducing AccentColor as SystemColors #9295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
LGTM. |
This was widely discussed a few years ago in the WinUI and CommunityToolkit repositories. Accent color calculations are not a simple algorithm and it's hidden by Microsoft within Windows. Your design team considers this algorithm proprietary and you won't release it publicly. This means everyone has to read AccentLight1-3, AccentDark1-3, etc. directly from Windows which does the calculation. The calculation is fairly complex too and it making sure the Accent colors 1-3 are calculated from the base color in a way that ensures contrast and good visibility. It isn't simply adjusting the luminence, value or brightness of colors. It also adjusts Hue in some cases.
Yes, but keep in mind the structure of Fluent theme is as follows. I simplified by removing light/dark/contrast variations and non-color resources like FontSize, Padding, etc.
Mapping the Fluent theme to SystemColors essentially means you need to provide levels 0 and 1. Level zero is the accent colors. But level 1 is: wpf/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Resources/Theme/Light.xaml Lines 25 to 309 in e1e077d
We need access to level 2 resources to be able to re-template but that is part of another discussion. |
@robert-abeo , thanks for the insight on the history of accent colors. It pretty much means that we would have to access all of them from WinUI's UISetting type then. Yeah, while working with Fluent I have understood the layering in the resources and styles and I will try to keep that in order. |
Looks great, what about the change while the application is running, maybe some 'AccentColorsChanged' delegate? |
These would be updated, so if you use DynamicResource with the keys, the color will change when it changes in the system. There is also UserPreferenceChanged event generated when the theme changes. |
LGTM for SystemColors. |
If the community is okay with the shape of this API and there are no objections, I will go ahead and mark it as ready for review tomorrow. |
Based on latest strategy for a "hybrid" registration of styles I think it does make sense to only extend SystemColors with the accent colors. Summarizing the longer comment above, Fluent2 defines system colors in XAML resources directly (a small subset below). If we were to loose access to these by string key the next best option would have been to add as many as possible to SystemColors. That will no longer be needed. The hope is in .NET 10+ WPF will stop mangling theme style resource keys as well so this can all be simplified further in the future again. Either way SystemColors won't need this information now. wpf/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Resources/Theme/Light.xaml Lines 121 to 132 in e1e077d
|
Note on the keys: You've dropped the If you went with the separate Side-note, you might find something useful here: |
LGTM except a small question: |
@ThomasGoulet73, no we used a WinRT type UISettings to retreive the values, this is present from Windows 10. In the case where we don't have this type to provide a value, we will provide a fallback for the same. |
namespace System.Windows;
public static class SystemColors
{
// Accent Colors
public static Color AccentColor { get; }
public static Color AccentColorLight1 { get; }
public static Color AccentColorLight2 { get; }
public static Color AccentColorLight3 { get; }
public static Color AccentColorDark1 { get; }
public static Color AccentColorDark2 { get; }
public static Color AccentColorDark3 { get; }
// Accent Color Keys
public static ResourceKey AccentColorKey { get; }
public static ResourceKey AccentColorLight1Key { get; }
public static ResourceKey AccentColorLight2Key { get; }
public static ResourceKey AccentColorLight3Key { get; }
public static ResourceKey AccentColorDark1Key { get; }
public static ResourceKey AccentColorDark2Key { get; }
public static ResourceKey AccentColorDark3Key { get; }
// Accent Color Brushes
public static SolidColorBrush AccentColorBrush { get; }
public static SolidColorBrush AccentColorLight1Brush { get; }
public static SolidColorBrush AccentColorLight2Brush { get; }
public static SolidColorBrush AccentColorLight3Brush { get; }
public static SolidColorBrush AccentColorDark1Brush { get; }
public static SolidColorBrush AccentColorDark2Brush { get; }
public static SolidColorBrush AccentColorDark3Brush { get; }
// Accent Color Brush Keys
public static ResourceKey AccentColorBrushKey { get; }
public static ResourceKey AccentColorLight1BrushKey { get; }
public static ResourceKey AccentColorLight2BrushKey { get; }
public static ResourceKey AccentColorLight3BrushKey { get; }
public static ResourceKey AccentColorDark1BrushKey { get; }
public static ResourceKey AccentColorDark2BrushKey { get; }
public static ResourceKey AccentColorDark3BrushKey { get; }
} |
Background and Motivation
Since Windows 10 onwards, Accent color has been one of the key compoenents of visual styles in Windows controls. However, there is no easy way to get the system's accent color. Accent colors can be used in custom styles to align the styling of controls with what the OS is showing.
In earlier versions of Windows, visual styles were defined using system colors and brushes, and corresponding to that we had
SystemColors
static class that contained getters to all the system colors, brushes and corresponding resource keys for using the colors and brushes in XAML.Since, Accent color and it's variations are also system wide defined colors, we propose to expose them using the
SystemColors
class.API Proposal
I think it may be possible to reduce the number of properties that we are exposing here, if the operations to calculate the variations of AccentColor are simpler. We don't know that yet so, I would like to keep these APIs experimental.
Alternative Design
Rather than having the accent colors defined here, we can introduce a new class, say
AccentColorManager
which will store the system accent and opens up possibility for theme related customization.The text was updated successfully, but these errors were encountered: