mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-22 20:42:03 +00:00
rust: add debug.rs
This commit is contained in:
parent
d34c1eed75
commit
9f6e4b8c79
@ -506,18 +506,18 @@ impl<'a> Op<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
struct Span {
|
pub struct Span {
|
||||||
/// How many characters from the input text this span is laying out.
|
/// 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
|
/// How many chars from the input text should we skip before fitting the
|
||||||
/// next span?
|
/// 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
|
/// 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.
|
/// 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
|
/// If we are breaking the line, should we insert a hyphen right after this
|
||||||
/// span to indicate a word-break?
|
/// span to indicate a word-break?
|
||||||
insert_hyphen_before_line_break: bool,
|
pub insert_hyphen_before_line_break: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Span {
|
impl Span {
|
||||||
|
219
core/embed/rust/src/ui/debug.rs
Normal file
219
core/embed/rust/src/ui/debug.rs
Normal file
@ -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<const L: usize> TextBox<L> {
|
||||||
|
pub fn print(&self) {
|
||||||
|
println!("TextBox:: ", "content: ", self.content());
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,8 @@ pub mod macros;
|
|||||||
pub mod animation;
|
pub mod animation;
|
||||||
pub mod component;
|
pub mod component;
|
||||||
pub mod constant;
|
pub mod constant;
|
||||||
|
#[cfg(feature = "ui_debug")]
|
||||||
|
pub mod debug;
|
||||||
pub mod display;
|
pub mod display;
|
||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod geometry;
|
pub mod geometry;
|
||||||
|
Loading…
Reference in New Issue
Block a user