-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Enhanced Color Format Support in XAML/Styles based on CSS #7899
Comments
@jmacato I am willing to implement this at some point in the coming weeks. However, I would like:
|
I think there was no explicit objections when i raised this issue so this is good to go! More compatibility with common colorspaces will be awesome IMO |
Alright, thanks for confirming. This could grow into a moderately-sized PR all things considered (Span helpers, unit tests, HslColor). So I'm not committing to a time-frame; however, goal is by 11.0 in a few months tops. I also might do a string-based initial version that can be followed up with Span-based optimizations later. |
Any reason that this was added for
The same as I can write:
|
No reason, just an oversight. With colors we got it for free with the Color.Parse method. Brushes I'll have to look at. |
Is your feature request related to a problem? Please describe.
The framework works in the RGB color model for good reasons. However, there are cases where other color models should be supported for designers and control authors. In additional HTML/CSS supports alternative formats.
Describe the solution you'd like
Add support for all HTML/CSS color formats and include a new one for HSV.
Examples:
"Green"
(already supported)"#ff0000"
(already supported)"rgb(255, 0, 0)"
new for Avalonia based on CSS"rgba(0, 255, 0, 0.3)"
new for Avalonia based on CSS"hsl(120, 100%, 75%)"
new for Avalonia based on CSS"hsl(120, 1.0, 0.75)"
new for Avalonia (not in CSS)"hsla(120, 100%, 75%, 0.3)"
new for Avalonia based on CSS"hsla(120, 1.0, 0.75, 0.3)"
new for Avalonia (not in CSS)"hsv(300, 100%, 20%)"
new for Avalonia (not in CSS)"hsv(300, 1.0, 0.2)"
new for Avalonia (not in CSS)"hsva(300, 90%, 20%, 0.8)"
new for Avalonia (not in CSS)"hsva(300, 0.9, 0.2, 0.8)"
new for Avalonia (not in CSS)Note that alpha can also be specified as a percentage by adding a percent sign. This is an extension of the format that CSS does not have.
Advantages:
This would be supported in the XAML parser by modifying the
Color.Parse()
methods to handle all formats including those for HSV/HSL. It's convenient thatColor
is named simplyColor
instead ofRgbColor
as this modification still makes sense in the API naming!Other color models will be automatically converted to RGB after parsing. Code for parsing and conversion other color models to RGB would not be within the Color struct itself and would instead exist in
HsvColor
and potentiallyHslColor
.Describe alternatives you've considered
Alternative is to keep using simple RGB color formats.
Additional context
"rgb(255 0 30)"
The text was updated successfully, but these errors were encountered: