Microsoft.Maui.Graphics icon indicating copy to clipboard operation
Microsoft.Maui.Graphics copied to clipboard

Breaking changes between Forms Color and Maui Color

Open mattleibow opened this issue 3 years ago • 7 comments

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.

  1. #54 Going from R/G/B/A to Red/Green/Blue/Alpha is a bit new
  2. #55 The underlying components are now float and not double
  3. #57 Lack of Accent and Default (and Transparent, but that can be added to Colors)
  4. #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

mattleibow avatar Apr 09 '21 23:04 mattleibow

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.

jonlipsky avatar Apr 09 '21 23:04 jonlipsky

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?

jonlipsky avatar Apr 10 '21 00:04 jonlipsky

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.

hartez avatar Apr 10 '21 03:04 hartez

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...

Redth avatar Apr 13 '21 17:04 Redth

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 avatar Apr 19 '21 20:04 mattleibow

@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)

jonlipsky avatar Apr 19 '21 22:04 jonlipsky

@mattleibow Never mind my comment. ;-). I'll merge in your PR to fix the colors

jonlipsky avatar Apr 19 '21 22:04 jonlipsky