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

Color class lacks Hue, Saturation, and Luminosity properties.

Open davidbritch opened this issue 4 years ago • 2 comments

The Xamarin.Forms Color struct has Hue, Saturation, and Luminosity properties. The Maui.Graphics Color class does not. This makes the upgrade path from Forms to MAUI that more frustrating.

I get that converting a Color to HSL every time the Color changes isn't efficient (which is what Forms did, IIRC), when the chances are that most users aren't interested in HSL. But for anyone who did use them, well, their apps are now broken until they rewrite to call GetSaturation() etc., and restructure their code to avoid keep calling GetSaturation() etc (which recalculates the value each time) rather than just accessing a property.

At the very least, I'd have hoped for Hue, Saturation, and Luminosity properties that are marked as obsolete for the first release. It's a bit annoying having to rewrite data binding code that bound to properties that no longer exist.

davidbritch avatar Jan 14 '22 17:01 davidbritch

thoughts 1

I ran into ~this same~ a similar issue last night.

I noticed GetLuminosity() and GetSaturation() exist but there is no matching GetValue() because function name means something else.

Even if there are Hue, Saturation, and Luminosity properties, I imagine a Value property will always be missing, making the case for calling a function with Hsv or Hsl in its name instead of interacting with these properties individually.

Resources:

thoughts 2

Actually, my naivety in the color space (pun) is showing here. HSL and HSV are clearly different https://en.wikipedia.org/wiki/HSL_and_HSV

image

hue, saturation, and luminosity can be obtained by calling Color.ToHsl() https://github.com/dotnet/Microsoft.Maui.Graphics/blob/a8feeb062040911360f922b571cbace57e078117/src/Microsoft.Maui.Graphics/Color.cs#L456-L505

... but there seems to be no Color.ToHsv()

swharden avatar Jan 14 '22 17:01 swharden

I implemented this suggestion in PR #281

swharden avatar Jan 14 '22 17:01 swharden