Improve `Debug` format of `Sense`, `WidgetInfo` and `Id`

This commit is contained in:
Emil Ernerfeldt 2024-03-31 20:33:02 +02:00
parent 95b62ce144
commit a97134d66c
3 changed files with 28 additions and 3 deletions

View File

@ -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);

View File

@ -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)
}
}

View File

@ -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")]