From 9ef4d02ab85c0933826f75626e367015df2e42d2 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 25 Sep 2024 11:14:44 +0200 Subject: [PATCH] More compact `Debug` formatting of `Color32` (#5162) Especially when using the verbose `{:#?}`, which before would result in ``` Color32([ 255, 0, 0, 255 ]) ``` but now becomes `#ff_00_00_ff` --- crates/ecolor/src/color32.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/ecolor/src/color32.rs b/crates/ecolor/src/color32.rs index 9025b6ee548..d697be28273 100644 --- a/crates/ecolor/src/color32.rs +++ b/crates/ecolor/src/color32.rs @@ -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 for Color32 { type Output = u8;