diff --git a/core/embed/rust/src/ui/component/text/layout.rs b/core/embed/rust/src/ui/component/text/layout.rs index fcbeb9dd7f..d8d2301c2b 100644 --- a/core/embed/rust/src/ui/component/text/layout.rs +++ b/core/embed/rust/src/ui/component/text/layout.rs @@ -506,18 +506,18 @@ impl<'a> Op<'a> { } #[derive(Debug, PartialEq, Eq)] -struct Span { +pub struct Span { /// How many characters from the input text this span is laying out. - length: usize, + pub length: usize, /// How many chars from the input text should we skip before fitting the /// next span? - skip_next_chars: usize, + pub skip_next_chars: usize, /// By how much to offset the cursor after this span. If the vertical offset /// is bigger than zero, it means we are breaking the line. - advance: Offset, + pub advance: Offset, /// If we are breaking the line, should we insert a hyphen right after this /// span to indicate a word-break? - insert_hyphen_before_line_break: bool, + pub insert_hyphen_before_line_break: bool, } impl Span { diff --git a/core/embed/rust/src/ui/debug.rs b/core/embed/rust/src/ui/debug.rs new file mode 100644 index 0000000000..e69efd1c7e --- /dev/null +++ b/core/embed/rust/src/ui/debug.rs @@ -0,0 +1,219 @@ +//! Including some useful debugging features, +//! like printing of the struct details. + +use heapless::String; + +use super::{ + component::{ + pad::Pad, + text::{ + common::TextBox, + layout::{Span, TextLayout}, + }, + }, + display::{Color, Font, Icon}, + geometry::{Grid, Insets, Offset, Point, Rect}, +}; +use crate::{micropython::buffer::StrBuffer, time::Duration}; + +// NOTE: not defining a common trait, like +// Debug {fn print(&self);}, so that the trait does +// not need to be imported when using the +// print() function. It suits the use-case of being quickly +// able to use the print() for debugging and then delete it. + +impl StrBuffer { + pub fn print(&self) { + println!("StrBuffer:: ", self.as_ref()); + } +} + +impl Duration { + pub fn print(&self) { + println!("Duration:: ", inttostr!(self.to_millis())); + } +} + +impl Point { + pub fn print(&self) { + println!( + "Point:: ", + "x: ", + inttostr!(self.x), + ", y: ", + inttostr!(self.y) + ); + } +} + +impl Rect { + pub fn print(&self) { + print!("Rect:: "); + println!(&self.corners_points()); + } + + pub fn corners_points(&self) -> String<30> { + build_string!( + 30, + "(", + inttostr!(self.x0), + ",", + inttostr!(self.y0), + "), (", + inttostr!(self.x1), + ",", + inttostr!(self.y1), + ")" + ) + } +} + +#[cfg(feature = "ui_debug")] +impl crate::trace::Trace for Rect { + fn trace(&self, t: &mut dyn crate::trace::Tracer) { + t.open("Rect"); + t.string(&self.corners_points()); + t.close(); + } +} + +impl Color { + pub fn print(&self) { + println!( + "Color:: ", + "R: ", + inttostr!(self.r()), + ", G: ", + inttostr!(self.g()), + ", B: ", + inttostr!(self.b()) + ); + } +} + +impl Font { + pub fn print(&self) { + println!("Font:: ", "text_height: ", inttostr!(self.text_height())); + } +} + +impl Offset { + pub fn print(&self) { + println!( + "Offset:: ", + "x: ", + inttostr!(self.x), + ", y: ", + inttostr!(self.y) + ); + } +} + +impl Insets { + pub fn print(&self) { + println!( + "Insets:: ", + "top: ", + inttostr!(self.top), + ", right: ", + inttostr!(self.right), + ", bottom: ", + inttostr!(self.bottom), + ", left: ", + inttostr!(self.left) + ); + } +} + +impl Grid { + pub fn print(&self) { + print!( + "Grid:: ", + "rows: ", + inttostr!(self.rows as i32), + ", cols: ", + inttostr!(self.cols as i32), + ", spacing: ", + inttostr!(self.spacing as i32) + ); + print!(", area: "); + self.area.print(); + } +} + +impl Icon { + pub fn dimension_str(&self) -> String<10> { + build_string!( + 10, + inttostr!(self.toif.width() as i32), + "x", + inttostr!(self.toif.height() as i32) + ) + } + + pub fn print(&self) { + println!( + "Icon:: ", + "width: ", + inttostr!(self.toif.width() as i32), + ", height: ", + inttostr!(self.toif.height() as i32) + ); + } +} + +#[cfg(feature = "ui_debug")] +impl crate::trace::Trace for Icon { + fn trace(&self, t: &mut dyn crate::trace::Tracer) { + t.open("Icon"); + t.string(&self.dimension_str()); + t.close(); + } +} + +impl TextLayout { + pub fn print(&self) { + print!( + "TextLayout:: ", + "padding_top: ", + inttostr!(self.padding_top as i32), + ", padding_bottom: ", + inttostr!(self.padding_bottom as i32) + ); + print!(", bounds: "); + self.bounds.print(); + } +} + +impl Span { + pub fn print(&self) { + print!( + "Span:: ", + "length: ", + inttostr!(self.length as i32), + ", skip_next_chars: ", + inttostr!(self.skip_next_chars as i32), + ", insert_hyphen_before_line_break: ", + if self.insert_hyphen_before_line_break { + "true" + } else { + "false" + } + ); + print!(", advance: "); + self.advance.print(); + } +} + +impl Pad { + pub fn print(&self) { + print!("Pad:: ", "area: "); + self.area.print(); + } +} + +impl TextBox { + pub fn print(&self) { + println!("TextBox:: ", "content: ", self.content()); + } +} diff --git a/core/embed/rust/src/ui/mod.rs b/core/embed/rust/src/ui/mod.rs index c44b24dd5c..59210e8a35 100644 --- a/core/embed/rust/src/ui/mod.rs +++ b/core/embed/rust/src/ui/mod.rs @@ -4,6 +4,8 @@ pub mod macros; pub mod animation; pub mod component; pub mod constant; +#[cfg(feature = "ui_debug")] +pub mod debug; pub mod display; pub mod event; pub mod geometry;