Skip to content

Commit

Permalink
More compact Debug formatting of Color32 (#5162)
Browse files Browse the repository at this point in the history
Especially when using the verbose `{:#?}`, which before would result in

```
Color32([
    255,
    0,
    0,
    255
])
```

but now becomes `#ff_00_00_ff`
  • Loading branch information
emilk authored Sep 25, 2024
1 parent 1603f05 commit 9ef4d02
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/ecolor/src/color32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ use crate::{fast_round, linear_f32_from_linear_u8, Rgba};
///
/// The special value of alpha=0 means the color is to be treated as an additive color.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Default, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
pub struct Color32(pub(crate) [u8; 4]);

impl std::fmt::Debug for Color32 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let [r, g, b, a] = self.0;
write!(f, "#{r:02X}_{g:02X}_{b:02X}_{a:02X}")
}
}

impl std::ops::Index<usize> for Color32 {
type Output = u8;

Expand Down

0 comments on commit 9ef4d02

Please sign in to comment.