bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Added a Grey trait, and implementations on baked-in colors. Fixes #13206

Open Earthmark opened this issue 9 months ago • 3 comments

Added a Grey trait to allow colors to create a generic "grey" color.

This currently assumes the color spaces follow the same gradient, which I'm pretty sure isn't true, but it should make a "grey-ish" color relative to the provided intensity.

Objective

  • Implements #13206

Solution

  • A small Grey trait was added and implemented for the common color kinds.

Testing

  • Currently untested, unit tests exposed the non-linear relation between colors. I am debating adding an example to show this, as I have no idea what color space represents what relation of grey, and I figure others may be similarly confused.

Changelog

  • The Grey trait was added, and the corresponding grey

BREAKING CHANGES

The const qualifier for LinearRGBA::gray was removed (the symbol still exists via a trait, it's just not const anymore)

Earthmark avatar May 04 '24 20:05 Earthmark

Some colors have const fn gray() already. The old method should probably be removed if this trait is kept, though currently trait methods are non-const.

BD103 avatar May 04 '24 20:05 BD103

Probably a good idea to include a little generic test.

bushrat011899 avatar May 07 '24 10:05 bushrat011899

I added a test to verify all the different colors implement white and black as gray(1) and gray(0) respectively.

I'm very tempted to add a trait for approximate equality on colors now, but for now this works. It's not approximate, so it may be error prone, but it seems to work for now...

Earthmark avatar May 08 '24 02:05 Earthmark

@Earthmark could you resolve the merge conflicts? I'll merge this in as soon as you do.

alice-i-cecile avatar May 23 '24 21:05 alice-i-cecile

Will do. I'll get the conflicts resolved later today, and verify this is in prelude.

Earthmark avatar May 23 '24 22:05 Earthmark

I forgot about this for a few days, but now it's here!

Earthmark avatar May 26 '24 03:05 Earthmark

Thanks!

alice-i-cecile avatar May 26 '24 12:05 alice-i-cecile