kornelski / rust-rgb

struct RGB for sharing pixels between crates
https://lib.rs/rgb
MIT License
97 stars 19 forks source link

Hex formatting is a mess for >8-bit pixels #114

Closed kornelski closed 1 month ago

kornelski commented 1 month ago

:02x assumes max 0xFF, but Rgba<u16> can need 4 digits.

ripytide commented 1 month ago

I think the simplest fix would be to make make an impl for each integer size rather than generically for all component types.

ripytide commented 1 month ago

We might have to pull in a dependency on const_format to make the macros easier though.

kornelski commented 1 month ago

I'm thinking about fudging it: lower hex assumes 2 digits, and upper hex puts spaces or commas between the numbers (as in: use big X for big numbers).

ripytide commented 1 month ago

Alternatively, we could just abandon the 2-digit padding entirely, that way it's simple to implement. The main use-case I can think of is CSS-compatable hex color format but that seems best implemented by a user via a custom trait anyway as discussed in #1 and #52.

kornelski commented 1 month ago

Oh, size_of<T>() == 1 could be used to select the CSS hex format!