Microsoft.Maui.Graphics
Microsoft.Maui.Graphics copied to clipboard
Breaking changes between Forms Color and Maui Color
Besides the Color/Colors changes which are mostly cosmetic and a bit rare in code... maybe... there are a few things that are quite different.
- #54 Going from R/G/B/A to Red/Green/Blue/Alpha is a bit new
- #55 The underlying components are now float and not double
- #57 Lack of Accent and Default (and Transparent, but that can be added to Colors)
- #56 The type is now a class and not a struct
This is just a list here to link to the real issues.
Here is a working gist of other changes: https://gist.github.com/hartez/593fc3fb87035a3aedc91657e9c15ab3
First, as I've thought about this all day, I'd be ok with Color being a struct if it reduces friction as long as we make Color properties nullable (Color?). The only nagging issue is that was does "Color.Default" mean? The default color to use is scenario specific, and really get's messy when your UI auto-switches based on light/dark mode.
Regarding the double to float change, I feel pretty strongly that float is the correct type to use. iOS/Mac using float (ok, they use nfloat) and SkiaSharp uses floats. A float to double conversion is essentially free; however not the other way around.
What is someone doing with a color that truly requires double precision?
Would an option be to have 2 versions of Color (similar to what we have for the other primitives)?. Make Color use doubles and have a ColorF for people like me that care about every little millisecond when rendering to a graphics canvas?
Regarding the double to float change, I feel pretty strongly that float is the correct type to use. iOS/Mac using float (ok, they use nfloat) and SkiaSharp uses floats. A float to double conversion is essentially free; however not the other way around.
What is someone doing with a color that truly requires double precision?
Would an option be to have 2 versions of Color (similar to what we have for the other primitives)?. Make Color use doubles and have a ColorF for people like me that care about every little millisecond when rendering to a graphics canvas?
I honestly don't think anyone is going to be mad about the double -> float change. We'll get this out in a preview and see if it's causing folks any issues, but my instinct says most folks won't care and a few will celebrate because it's more in line with what everyone else does.
Well, nfloat
is backed by a double
on iOS and mac in 64 bit hosts, which means, generally everywhere at this point. I think there could be an argument made about potential issues with loss of precision somewhere down the road, though it seems likely it wouldn't be an issue for some time...
I also not missing constructor args from (byte, byte, byte) now gets done via a (double, ...) and this means that it will get clamped: https://github.com/dotnet/Microsoft.Maui.Graphics/pull/63
@mattleibow There are methods to create a Color from bytes:
public static Color FromRgb(byte red, byte green, byte blue)
public static Color FromRgba(byte red, byte green, byte blue, byte alpha)
@mattleibow Never mind my comment. ;-). I'll merge in your PR to fix the colors