macroquad icon indicating copy to clipboard operation
macroquad copied to clipboard

Color::from_hex(u32) -> Color ignores alpha

Open asmodehn opened this issue 1 year ago • 3 comments

I stumbled upon this recently, lost in confusion coming from debugging colors when alpha was not being what was expected... https://docs.rs/macroquad/latest/src/macroquad/color.rs.html#95-99

I am guessing alpha should not be ignored here, unless there is a reason to do so (in which case the function should somehow make it explicit) ?

asmodehn avatar Feb 01 '24 19:02 asmodehn

Fair point, feel free to make a PR!

Tho I am not quite sure how it should work, 0x3CA7D5 should be a light blue, but with alpha being 0x00 it would a little harder to use from_hex for opaque objects? I do not know really

not-fl3 avatar Feb 01 '24 23:02 not-fl3

I thought a bit about this, and to avoid update problems, I'd like to:

  • implement std::convert::From<u32> for Color (with alpha)
  • modify from_hex to make obvious alpha is always 1... Not sure how though.

Anyway 0x3CA7D5 is 24 bits, so not u32. Not sure how that works... I ll try to take some time in the following weeks to explore what type conversion is possible safely in rust...

asmodehn avatar Feb 02 '24 09:02 asmodehn

Looking at SDL, there is a whole structure dedicated to this kind of conversions: https://wiki.libsdl.org/SDL2/SDL_PixelFormat

Not sure what to make of it in our case here... I guess from_hex is just too generic/confusing for me...

asmodehn avatar Feb 07 '24 16:02 asmodehn