From a97134d66c30f876118e9eefef7686ee8645af27 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 31 Mar 2024 20:33:02 +0200 Subject: [PATCH] Improve `Debug` format of `Sense`, `WidgetInfo` and `Id` --- crates/egui/src/data/output.rs | 5 ++++- crates/egui/src/id.rs | 2 +- crates/egui/src/sense.rs | 24 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/crates/egui/src/data/output.rs b/crates/egui/src/data/output.rs index d1db5fc2a41..97794f4d13e 100644 --- a/crates/egui/src/data/output.rs +++ b/crates/egui/src/data/output.rs @@ -504,7 +504,10 @@ impl std::fmt::Debug for WidgetInfo { let mut s = f.debug_struct("WidgetInfo"); s.field("typ", typ); - s.field("enabled", enabled); + + if !enabled { + s.field("enabled", enabled); + } if let Some(label) = label { s.field("label", label); diff --git a/crates/egui/src/id.rs b/crates/egui/src/id.rs index 1cd96faec5f..0465c32d76c 100644 --- a/crates/egui/src/id.rs +++ b/crates/egui/src/id.rs @@ -85,7 +85,7 @@ impl Id { impl std::fmt::Debug for Id { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:016X}", self.0) + write!(f, "{:04X}", self.value() as u16) } } diff --git a/crates/egui/src/sense.rs b/crates/egui/src/sense.rs index ca216896aee..1b6394b2cc3 100644 --- a/crates/egui/src/sense.rs +++ b/crates/egui/src/sense.rs @@ -1,5 +1,5 @@ /// What sort of interaction is a widget sensitive to? -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Eq, PartialEq)] // #[cfg_attr(feature = "serde", derive(serde::Serialize))] pub struct Sense { /// Buttons, sliders, windows, … @@ -15,6 +15,28 @@ pub struct Sense { pub focusable: bool, } +impl std::fmt::Debug for Sense { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Self { + click, + drag, + focusable, + } = self; + + write!(f, "Sense {{")?; + if *click { + write!(f, " click")?; + } + if *drag { + write!(f, " drag")?; + } + if *focusable { + write!(f, " focusable")?; + } + write!(f, " }}") + } +} + impl Sense { /// Senses no clicks or drags. Only senses mouse hover. #[doc(alias = "none")]