Skip to content

Commit

Permalink
Improve Debug format of Sense, WidgetInfo and Id
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Mar 31, 2024
1 parent 95b62ce commit a97134d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 4 additions & 1 deletion crates/egui/src/data/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
24 changes: 23 additions & 1 deletion crates/egui/src/sense.rs
Original file line number Diff line number Diff line change
@@ -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, …
Expand All @@ -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")]
Expand Down

0 comments on commit a97134d

Please sign in to comment.