diff --git a/core/embed/rust/src/ui/display/mod.rs b/core/embed/rust/src/ui/display/mod.rs index 288000ece9..fff8e7da82 100644 --- a/core/embed/rust/src/ui/display/mod.rs +++ b/core/embed/rust/src/ui/display/mod.rs @@ -18,6 +18,9 @@ use crate::trezorhal::{ }, uzlib::UZLIB_WINDOW_SIZE, }; +#[cfg(feature = "dma2d")] +use crate::ui::component::image::Image; + #[cfg(not(feature = "dma2d"))] use crate::ui::geometry::TOP_LEFT; @@ -26,10 +29,8 @@ use crate::{ trezorhal::{buffers::get_text_buffer, display, time, uzlib::UzlibContext}, ui::lerp::Lerp, }; -use core::slice; -#[cfg(feature = "dma2d")] -use crate::ui::component::image::Image; +// Reexports pub use crate::ui::display::toif::Icon; pub use color::Color; pub use font::{Font, Glyph, GlyphMetrics}; @@ -62,6 +63,7 @@ pub fn fade_backlight_duration(target: u16, duration_ms: u32) { set_backlight(target as u16); } +/// Fill a whole rectangle with a specific color. pub fn rect_fill(r: Rect, fg_color: Color) { display::bar(r.x0, r.y0, r.width(), r.height(), fg_color.into()); } @@ -73,30 +75,53 @@ pub fn rect_stroke(r: Rect, fg_color: Color) { display::bar(r.x0 + r.width() - 1, r.y0, 1, r.height(), fg_color.into()); } +/// Draw a rectangle with rounded corners. pub fn rect_fill_rounded(r: Rect, fg_color: Color, bg_color: Color, radius: u8) { - assert!([2, 4, 8, 16].iter().any(|allowed| radius == *allowed)); - display::bar_radius( - r.x0, - r.y0, - r.width(), - r.height(), - fg_color.into(), - bg_color.into(), - radius, - ); + if radius == 1 { + rect_fill_rounded1(r, fg_color, bg_color); + } else { + assert!([2, 4, 8, 16].iter().any(|allowed| radius == *allowed)); + display::bar_radius( + r.x0, + r.y0, + r.width(), + r.height(), + fg_color.into(), + bg_color.into(), + radius, + ); + } } -// Used on T1 only. +/// Filling a rectangle with a rounding of 1 pixel - removing the corners. pub fn rect_fill_rounded1(r: Rect, fg_color: Color, bg_color: Color) { - display::bar(r.x0, r.y0, r.width(), r.height(), fg_color.into()); - let corners = [ - r.top_left(), - r.top_right() - Offset::x(1), - r.bottom_right() - Offset::uniform(1), - r.bottom_left() - Offset::y(1), - ]; - for p in corners.iter() { - display::bar(p.x, p.y, 1, 1, bg_color.into()); + rect_fill(r, fg_color); + rect_fill_corners(r, bg_color); +} + +/// Creating a rectangular outline with a given radius/rounding. +pub fn rect_outline_rounded(r: Rect, fg_color: Color, bg_color: Color, radius: u8) { + // Painting a bigger rectangle with FG and inner smaller with BG + // to create the outline. + let inner_r = r.shrink(1); + if radius == 1 { + rect_fill_rounded(r, fg_color, bg_color, 1); + rect_fill(inner_r, bg_color); + rect_fill_corners(inner_r, fg_color); + } else if radius == 2 { + rect_fill_rounded(r, fg_color, bg_color, 2); + rect_fill_rounded(inner_r, bg_color, fg_color, 1); + } else if radius == 4 { + rect_fill_rounded(r, fg_color, bg_color, 4); + rect_fill_rounded(inner_r, bg_color, fg_color, 2); + rect_fill_corners(inner_r, bg_color); + } +} + +/// Filling all four corners of a rectangle with a given color. +pub fn rect_fill_corners(r: Rect, fg_color: Color) { + for p in r.corner_points().iter() { + paint_point(p, fg_color); } } @@ -118,7 +143,7 @@ impl<'a> TextOverlay<'a> { text, font, max_height: font.max_height(), - baseline: font.baseline(), + baseline: font.text_baseline(), } } @@ -808,7 +833,13 @@ pub fn dotted_line(start: Point, width: i16, color: Color) { } } -pub fn text(baseline: Point, text: &str, font: Font, fg_color: Color, bg_color: Color) { +/// Paints a pixel with a specific color on a given point. +pub fn paint_point(point: &Point, color: Color) { + display::bar(point.x, point.y, 1, 1, color.into()); +} + +/// Display text left-aligned to a certain Point +pub fn text_left(baseline: Point, text: &str, font: Font, fg_color: Color, bg_color: Color) { display::text( baseline.x, baseline.y, @@ -819,6 +850,7 @@ pub fn text(baseline: Point, text: &str, font: Font, fg_color: Color, bg_color: ); } +/// Display text centered around a certain Point pub fn text_center(baseline: Point, text: &str, font: Font, fg_color: Color, bg_color: Color) { let w = font.text_width(text); display::text( @@ -831,6 +863,7 @@ pub fn text_center(baseline: Point, text: &str, font: Font, fg_color: Color, bg_ ); } +/// Display text right-alligned to a certain Point pub fn text_right(baseline: Point, text: &str, font: Font, fg_color: Color, bg_color: Color) { let w = font.text_width(text); display::text(