From cf4dcfcbd4e012fbd893a862c1e5ecbbdf66b9db Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Fri, 16 Jun 2023 15:43:50 +0200 Subject: [PATCH] refactor(core/ui): namespaced Alignment2D [no changelog] --- core/embed/rust/src/ui/component/image.rs | 17 ++++++++++---- core/embed/rust/src/ui/component/painter.rs | 4 ++-- core/embed/rust/src/ui/component/placed.rs | 4 ++-- .../rust/src/ui/component/text/layout.rs | 6 ++--- .../rust/src/ui/component/text/paragraphs.rs | 4 ++-- .../rust/src/ui/display/loader/starry.rs | 4 ++-- core/embed/rust/src/ui/display/mod.rs | 11 ++++++--- core/embed/rust/src/ui/display/toif.rs | 3 +-- core/embed/rust/src/ui/geometry.rs | 18 ++++++++------- .../rust/src/ui/model_tr/bootloader/intro.rs | 6 ++--- .../rust/src/ui/model_tr/bootloader/menu.rs | 10 +++++--- .../rust/src/ui/model_tr/bootloader/mod.rs | 4 ++-- .../rust/src/ui/model_tr/component/button.rs | 23 ++++++++++--------- .../rust/src/ui/model_tr/component/error.rs | 6 ++--- .../src/ui/model_tr/component/homescreen.rs | 17 +++++++++----- .../component/input_methods/choice_item.rs | 9 ++++++-- .../rust/src/ui/model_tr/component/result.rs | 4 ++-- .../ui/model_tr/component/welcome_screen.rs | 6 ++--- .../src/ui/model_tt/bootloader/confirm.rs | 4 ++-- .../rust/src/ui/model_tt/bootloader/mod.rs | 9 ++++++-- .../src/ui/model_tt/bootloader/welcome.rs | 4 ++-- .../rust/src/ui/model_tt/component/button.rs | 12 ++++++---- .../rust/src/ui/model_tt/component/error.rs | 4 ++-- .../ui/model_tt/component/keyboard/bip39.rs | 9 ++++++-- .../model_tt/component/keyboard/mnemonic.rs | 4 ++-- .../src/ui/model_tt/component/keyboard/pin.rs | 10 ++++---- .../ui/model_tt/component/keyboard/slip39.rs | 9 ++++++-- .../rust/src/ui/model_tt/component/result.rs | 4 ++-- .../rust/src/ui/model_tt/component/scroll.rs | 4 ++-- .../ui/model_tt/component/welcome_screen.rs | 11 ++++----- core/embed/rust/src/ui/util.rs | 4 ++-- 31 files changed, 145 insertions(+), 99 deletions(-) diff --git a/core/embed/rust/src/ui/component/image.rs b/core/embed/rust/src/ui/component/image.rs index c535453f9c..7a5b9d46ff 100644 --- a/core/embed/rust/src/ui/component/image.rs +++ b/core/embed/rust/src/ui/component/image.rs @@ -7,7 +7,7 @@ use crate::{ toif::{image, Toif}, Color, Icon, }, - geometry::{Alignment2D, Offset, Point, Rect, CENTER}, + geometry::{Alignment2D, Offset, Point, Rect}, }, }; @@ -48,7 +48,7 @@ impl Component for Image { } fn paint(&mut self) { - self.draw(self.area.center(), CENTER); + self.draw(self.area.center(), Alignment2D::CENTER); } #[cfg(feature = "ui_bounds")] @@ -110,9 +110,16 @@ impl Component for BlendedImage { type Msg = Never; fn place(&mut self, bounds: Rect) -> Rect { - self.bg_top_left = self.bg.toif.size().snap(bounds.center(), CENTER); - - let ft_top_left = self.fg.toif.size().snap(bounds.center(), CENTER); + self.bg_top_left = self + .bg + .toif + .size() + .snap(bounds.center(), Alignment2D::CENTER); + let ft_top_left = self + .fg + .toif + .size() + .snap(bounds.center(), Alignment2D::CENTER); self.fg_offset = ft_top_left - self.bg_top_left; Rect::from_top_left_and_size(self.bg_top_left, self.bg.toif.size()) diff --git a/core/embed/rust/src/ui/component/painter.rs b/core/embed/rust/src/ui/component/painter.rs index 6293544153..9d6b18e37c 100644 --- a/core/embed/rust/src/ui/component/painter.rs +++ b/core/embed/rust/src/ui/component/painter.rs @@ -3,7 +3,7 @@ use crate::ui::geometry::Offset; use crate::ui::{ component::{image::Image, Component, Event, EventCtx, Never}, display, - geometry::{Rect, CENTER}, + geometry::{Alignment2D, Rect}, }; pub struct Painter { @@ -53,7 +53,7 @@ impl crate::trace::Trace for Painter { } pub fn image_painter(image: Image) -> Painter { - let f = move |area: Rect| image.draw(area.center(), CENTER); + let f = move |area: Rect| image.draw(area.center(), Alignment2D::CENTER); Painter::new(f) } diff --git a/core/embed/rust/src/ui/component/placed.rs b/core/embed/rust/src/ui/component/placed.rs index 06652173ab..c4a7580452 100644 --- a/core/embed/rust/src/ui/component/placed.rs +++ b/core/embed/rust/src/ui/component/placed.rs @@ -1,6 +1,6 @@ use crate::ui::{ component::{Component, Event, EventCtx}, - geometry::{Alignment, Alignment2D, Axis, Grid, GridCellSpan, Insets, Offset, Rect, TOP_RIGHT}, + geometry::{Alignment, Alignment2D, Axis, Grid, GridCellSpan, Insets, Offset, Rect}, }; pub struct GridPlaced { @@ -140,7 +140,7 @@ impl Floating { pub const fn top_right(side: i16, border: i16, inner: T) -> Self { let size = Offset::uniform(side); let border = Offset::uniform(border); - Self::new(size, border, TOP_RIGHT, inner) + Self::new(size, border, Alignment2D::TOP_RIGHT, inner) } } diff --git a/core/embed/rust/src/ui/component/text/layout.rs b/core/embed/rust/src/ui/component/text/layout.rs index 87d535ce41..954cbcd066 100644 --- a/core/embed/rust/src/ui/component/text/layout.rs +++ b/core/embed/rust/src/ui/component/text/layout.rs @@ -1,7 +1,7 @@ use crate::ui::{ display, display::{toif::Icon, Color, Font, GlyphMetrics}, - geometry::{Alignment, Dimensions, Offset, Point, Rect, BOTTOM_LEFT}, + geometry::{Alignment, Alignment2D, Dimensions, Offset, Point, Rect}, }; const ELLIPSIS: &str = "..."; @@ -397,7 +397,7 @@ impl LayoutSink for TextRenderer { let bottom_left = cursor + Offset::x(margin); icon.draw( bottom_left, - BOTTOM_LEFT, + Alignment2D::BOTTOM_LEFT, layout.style.ellipsis_color, layout.style.background_color, ); @@ -416,7 +416,7 @@ impl LayoutSink for TextRenderer { if let Some((icon, _margin)) = layout.style.prev_page_ellipsis_icon { icon.draw( cursor, - BOTTOM_LEFT, + Alignment2D::BOTTOM_LEFT, layout.style.ellipsis_color, layout.style.background_color, ); diff --git a/core/embed/rust/src/ui/component/text/paragraphs.rs b/core/embed/rust/src/ui/component/text/paragraphs.rs index ee0479a94d..fbb26b55c7 100644 --- a/core/embed/rust/src/ui/component/text/paragraphs.rs +++ b/core/embed/rust/src/ui/component/text/paragraphs.rs @@ -5,7 +5,7 @@ use crate::{ ui::{ component::{Component, Event, EventCtx, Never, Paginate}, display::toif::Icon, - geometry::{Alignment, Insets, LinearPlacement, Offset, Point, Rect, TOP_LEFT}, + geometry::{Alignment, Alignment2D, Insets, LinearPlacement, Offset, Point, Rect}, }, }; @@ -570,7 +570,7 @@ impl Checklist { let top_left = Point::new(self.area.x0, layout.bounds.y0); icon.draw( top_left + offset, - TOP_LEFT, + Alignment2D::TOP_LEFT, layout.style.text_color, layout.style.background_color, ); diff --git a/core/embed/rust/src/ui/display/loader/starry.rs b/core/embed/rust/src/ui/display/loader/starry.rs index 345d63a943..59e498552c 100644 --- a/core/embed/rust/src/ui/display/loader/starry.rs +++ b/core/embed/rust/src/ui/display/loader/starry.rs @@ -1,7 +1,7 @@ use crate::ui::{ constant::{screen, LOADER_OUTER}, display::{rect_fill, rect_fill_rounded, Color, Icon}, - geometry::{Offset, Point, Rect, CENTER}, + geometry::{Alignment2D, Offset, Point, Rect}, }; use core::f32::consts::SQRT_2; @@ -62,6 +62,6 @@ pub fn loader_starry_indeterminate( } if let Some((icon, color)) = icon { - icon.draw(area.center(), CENTER, color, bg_color); + icon.draw(area.center(), Alignment2D::CENTER, color, bg_color); } } diff --git a/core/embed/rust/src/ui/display/mod.rs b/core/embed/rust/src/ui/display/mod.rs index efcbd2c1e4..51e7f4425f 100644 --- a/core/embed/rust/src/ui/display/mod.rs +++ b/core/embed/rust/src/ui/display/mod.rs @@ -21,7 +21,7 @@ use crate::trezorhal::{ use crate::ui::component::image::Image; #[cfg(not(feature = "dma2d"))] -use crate::ui::geometry::TOP_LEFT; +use crate::ui::geometry::Alignment2D; use crate::{ time::Duration, @@ -725,8 +725,13 @@ pub fn icon_over_icon( Point::from(offset_bg) }; - icon_bg.draw(pos_bg, TOP_LEFT, color_icon_bg, bg_color); - icon_fg.draw(pos_bg + offset_fg, TOP_LEFT, color_icon_fg, color_icon_bg); + icon_bg.draw(pos_bg, Alignment2D::TOP_LEFT, color_icon_bg, bg_color); + icon_fg.draw( + pos_bg + offset_fg, + Alignment2D::TOP_LEFT, + color_icon_fg, + color_icon_bg, + ); } /// Gets a color of a pixel on `p` coordinates of rounded rectangle with corner diff --git a/core/embed/rust/src/ui/display/toif.rs b/core/embed/rust/src/ui/display/toif.rs index 250bcbc29c..677c3d37b4 100644 --- a/core/embed/rust/src/ui/display/toif.rs +++ b/core/embed/rust/src/ui/display/toif.rs @@ -11,7 +11,6 @@ use crate::{ }, }; -use crate::ui::geometry::TOP_LEFT; #[cfg(feature = "dma2d")] use crate::{ trezorhal::{ @@ -73,7 +72,7 @@ extern "C" fn display_image( ) { let data_slice = unsafe { core::slice::from_raw_parts(data, data_len as usize) }; let image = Image::new(data_slice); - image.draw(Point::new(x, y), TOP_LEFT); + image.draw(Point::new(x, y), Alignment2D::TOP_LEFT); } #[cfg(feature = "dma2d")] diff --git a/core/embed/rust/src/ui/geometry.rs b/core/embed/rust/src/ui/geometry.rs index 9a84ea8cd1..cbc3e77f55 100644 --- a/core/embed/rust/src/ui/geometry.rs +++ b/core/embed/rust/src/ui/geometry.rs @@ -513,15 +513,17 @@ pub enum Alignment { End, } -pub type Alignment2D = (Alignment, Alignment); +pub struct Alignment2D(pub Alignment, pub Alignment); -pub const TOP_LEFT: Alignment2D = (Alignment::Start, Alignment::Start); -pub const TOP_RIGHT: Alignment2D = (Alignment::End, Alignment::Start); -pub const TOP_CENTER: Alignment2D = (Alignment::Center, Alignment::Start); -pub const CENTER: Alignment2D = (Alignment::Center, Alignment::Center); -pub const BOTTOM_LEFT: Alignment2D = (Alignment::Start, Alignment::End); -pub const BOTTOM_RIGHT: Alignment2D = (Alignment::End, Alignment::End); -pub const BOTTOM_CENTER: Alignment2D = (Alignment::Center, Alignment::End); +impl Alignment2D { + pub const TOP_LEFT: Alignment2D = Alignment2D(Alignment::Start, Alignment::Start); + pub const TOP_RIGHT: Alignment2D = Alignment2D(Alignment::End, Alignment::Start); + pub const TOP_CENTER: Alignment2D = Alignment2D(Alignment::Center, Alignment::Start); + pub const CENTER: Alignment2D = Alignment2D(Alignment::Center, Alignment::Center); + pub const BOTTOM_LEFT: Alignment2D = Alignment2D(Alignment::Start, Alignment::End); + pub const BOTTOM_RIGHT: Alignment2D = Alignment2D(Alignment::End, Alignment::End); + pub const BOTTOM_CENTER: Alignment2D = Alignment2D(Alignment::Center, Alignment::End); +} #[derive(Copy, Clone, PartialEq, Eq)] pub enum Axis { diff --git a/core/embed/rust/src/ui/model_tr/bootloader/intro.rs b/core/embed/rust/src/ui/model_tr/bootloader/intro.rs index c920f11dfe..367a1ecfd4 100644 --- a/core/embed/rust/src/ui/model_tr/bootloader/intro.rs +++ b/core/embed/rust/src/ui/model_tr/bootloader/intro.rs @@ -1,6 +1,6 @@ use crate::ui::{ component::{Child, Component, Event, EventCtx, Label, Pad}, - geometry::{Alignment, Rect, TOP_LEFT, TOP_RIGHT}, + geometry::{Alignment, Alignment2D, Rect}, }; use super::{ @@ -86,8 +86,8 @@ impl<'a> Component for Intro<'a> { self.bg.paint(); self.title.paint(); let area = self.bg.area; - ICON_WARN_TITLE.draw(area.top_left(), TOP_LEFT, BLD_FG, BLD_BG); - ICON_WARN_TITLE.draw(area.top_right(), TOP_RIGHT, BLD_FG, BLD_BG); + ICON_WARN_TITLE.draw(area.top_left(), Alignment2D::TOP_LEFT, BLD_FG, BLD_BG); + ICON_WARN_TITLE.draw(area.top_right(), Alignment2D::TOP_RIGHT, BLD_FG, BLD_BG); self.text.paint(); self.buttons.paint(); } diff --git a/core/embed/rust/src/ui/model_tr/bootloader/menu.rs b/core/embed/rust/src/ui/model_tr/bootloader/menu.rs index 250afc804b..488b6da64d 100644 --- a/core/embed/rust/src/ui/model_tr/bootloader/menu.rs +++ b/core/embed/rust/src/ui/model_tr/bootloader/menu.rs @@ -5,7 +5,7 @@ use crate::ui::{ constant::screen, display, display::{Font, Icon}, - geometry::{Offset, Point, Rect, CENTER}, + geometry::{Alignment2D, Offset, Point, Rect}, }; use super::{ @@ -49,8 +49,12 @@ impl MenuChoice { impl Choice<&'static str> for MenuChoice { fn paint_center(&self, _area: Rect, _inverse: bool) { // Icon on top and two lines of text below - self.icon - .draw(SCREEN_CENTER + Offset::y(-20), CENTER, BLD_FG, BLD_BG); + self.icon.draw( + SCREEN_CENTER + Offset::y(-20), + Alignment2D::CENTER, + BLD_FG, + BLD_BG, + ); display::text_center(SCREEN_CENTER, self.first_line, Font::NORMAL, BLD_FG, BLD_BG); display::text_center( diff --git a/core/embed/rust/src/ui/model_tr/bootloader/mod.rs b/core/embed/rust/src/ui/model_tr/bootloader/mod.rs index 75b8c7e5fe..077aaf4bc5 100644 --- a/core/embed/rust/src/ui/model_tr/bootloader/mod.rs +++ b/core/embed/rust/src/ui/model_tr/bootloader/mod.rs @@ -7,7 +7,7 @@ use crate::{ constant::SCREEN, display::{self, Color, Font, Icon}, event::ButtonEvent, - geometry::{Alignment, Alignment::Center, Offset, Rect, TOP_CENTER}, + geometry::{Alignment, Alignment::Center, Alignment2D, Offset, Rect}, util::{from_c_array, from_c_str}, }, }; @@ -316,7 +316,7 @@ extern "C" fn screen_boot_empty(_firmware_present: bool) { display::rect_fill(SCREEN, BLD_BG); LOGO_EMPTY.draw( SCREEN.top_center() + Offset::y(11), - TOP_CENTER, + Alignment2D::TOP_CENTER, BLD_FG, BLD_BG, ); diff --git a/core/embed/rust/src/ui/model_tr/component/button.rs b/core/embed/rust/src/ui/model_tr/component/button.rs index 35eeb5ab32..be1d25be8e 100644 --- a/core/embed/rust/src/ui/model_tr/component/button.rs +++ b/core/embed/rust/src/ui/model_tr/component/button.rs @@ -5,9 +5,7 @@ use crate::{ component::{Component, Event, EventCtx, Never}, constant, display::{self, Color, Font, Icon}, - geometry::{ - Insets, Offset, Point, Rect, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER, TOP_LEFT, TOP_RIGHT, - }, + geometry::{Alignment2D, Insets, Offset, Point, Rect}, }, }; @@ -215,13 +213,13 @@ where // 2 px because 1px might lead to odd coordinate which can't be render theme::ICON_ARM_LEFT.draw( area.left_center() - Offset::x(2), - TOP_RIGHT, + Alignment2D::TOP_RIGHT, text_color, background_color, ); theme::ICON_ARM_RIGHT.draw( area.right_center() + Offset::x(2), - TOP_LEFT, + Alignment2D::TOP_LEFT, text_color, background_color, ); @@ -254,25 +252,28 @@ where // Accounting for the 8*8 icon with empty left column and bottom row // (which fits the outline nicely and symmetrically) let center = area.center() + Offset::uniform(1); - icon.draw(center, CENTER, text_color, background_color); + icon.draw(center, Alignment2D::CENTER, text_color, background_color); } else { // Positioning the icon in the corresponding corner/center match self.pos { ButtonPos::Left => icon.draw( area.bottom_left(), - BOTTOM_LEFT, + Alignment2D::BOTTOM_LEFT, text_color, background_color, ), ButtonPos::Right => icon.draw( area.bottom_right(), - BOTTOM_RIGHT, + Alignment2D::BOTTOM_RIGHT, + text_color, + background_color, + ), + ButtonPos::Middle => icon.draw( + area.center(), + Alignment2D::CENTER, text_color, background_color, ), - ButtonPos::Middle => { - icon.draw(area.center(), CENTER, text_color, background_color) - } } } } diff --git a/core/embed/rust/src/ui/model_tr/component/error.rs b/core/embed/rust/src/ui/model_tr/component/error.rs index b6dd8ce7f6..e3cfe08700 100644 --- a/core/embed/rust/src/ui/model_tr/component/error.rs +++ b/core/embed/rust/src/ui/model_tr/component/error.rs @@ -2,7 +2,7 @@ use crate::ui::{ component::{Child, Component, Event, EventCtx, Label, Never, Pad}, constant::screen, display, - geometry::{Alignment::Center, Offset, Point, Rect, TOP_LEFT, TOP_RIGHT}, + geometry::{Alignment::Center, Alignment2D, Offset, Point, Rect}, }; use super::super::{ @@ -79,8 +79,8 @@ impl> Component for ErrorScreen { self.bg.paint(); if self.show_icons { - theme::ICON_WARN_TITLE.draw(screen().top_left(), TOP_LEFT, FG, BG); - theme::ICON_WARN_TITLE.draw(screen().top_right(), TOP_RIGHT, FG, BG); + theme::ICON_WARN_TITLE.draw(screen().top_left(), Alignment2D::TOP_LEFT, FG, BG); + theme::ICON_WARN_TITLE.draw(screen().top_right(), Alignment2D::TOP_RIGHT, FG, BG); } self.title.paint(); self.message.paint(); diff --git a/core/embed/rust/src/ui/model_tr/component/homescreen.rs b/core/embed/rust/src/ui/model_tr/component/homescreen.rs index 10f5aa3522..8e1818b740 100644 --- a/core/embed/rust/src/ui/model_tr/component/homescreen.rs +++ b/core/embed/rust/src/ui/model_tr/component/homescreen.rs @@ -5,7 +5,7 @@ use crate::{ component::{Child, Component, Event, EventCtx, Label}, display::{rect_fill, toif::Toif, Font}, event::USBEvent, - geometry::{self, Insets, Offset, Point, Rect}, + geometry::{Alignment2D, Insets, Offset, Point, Rect}, layout::util::get_user_custom_image, }, }; @@ -54,11 +54,11 @@ where fn paint_homescreen_image(&self) { if let Ok(user_custom_image) = get_user_custom_image() { let toif_data = unwrap!(Toif::new(user_custom_image.as_ref())); - toif_data.draw(TOP_CENTER, geometry::TOP_CENTER, theme::FG, theme::BG); + toif_data.draw(TOP_CENTER, Alignment2D::TOP_CENTER, theme::FG, theme::BG); } else { theme::ICON_LOGO.draw( TOP_CENTER + Offset::y(LOGO_ICON_TOP_MARGIN), - geometry::TOP_CENTER, + Alignment2D::TOP_CENTER, theme::FG, theme::BG, ); @@ -96,8 +96,13 @@ where fn paint_warning_icons_in_top_corners(&self) { let warning_icon = theme::ICON_WARNING; - warning_icon.draw(AREA.top_left(), geometry::TOP_LEFT, theme::FG, theme::BG); - warning_icon.draw(AREA.top_right(), geometry::TOP_RIGHT, theme::FG, theme::BG); + warning_icon.draw(AREA.top_left(), Alignment2D::TOP_LEFT, theme::FG, theme::BG); + warning_icon.draw( + AREA.top_right(), + Alignment2D::TOP_RIGHT, + theme::FG, + theme::BG, + ); } fn event_usb(&mut self, ctx: &mut EventCtx, event: Event) { @@ -188,7 +193,7 @@ where fn paint(&mut self) { theme::ICON_LOCK.draw( TOP_CENTER + Offset::y(LOCK_ICON_TOP_MARGIN), - geometry::TOP_CENTER, + Alignment2D::TOP_CENTER, theme::FG, theme::BG, ); diff --git a/core/embed/rust/src/ui/model_tr/component/input_methods/choice_item.rs b/core/embed/rust/src/ui/model_tr/component/input_methods/choice_item.rs index ebcd358413..1ed91cc42b 100644 --- a/core/embed/rust/src/ui/model_tr/component/input_methods/choice_item.rs +++ b/core/embed/rust/src/ui/model_tr/component/input_methods/choice_item.rs @@ -2,7 +2,7 @@ use crate::{ strutil::{ShortString, StringType}, ui::{ display::{self, rect_fill, rect_fill_corners, rect_outline_rounded, Font, Icon}, - geometry::{Offset, Rect, BOTTOM_LEFT}, + geometry::{Alignment2D, Offset, Rect}, }, }; @@ -160,7 +160,12 @@ fn paint_text_icon( if let Some(icon) = icon { let height_diff = font.text_height() - icon.toif.height(); let vertical_offset = Offset::y(-height_diff / 2); - icon.draw(baseline + vertical_offset, BOTTOM_LEFT, fg_color, bg_color); + icon.draw( + baseline + vertical_offset, + Alignment2D::BOTTOM_LEFT, + fg_color, + bg_color, + ); baseline = baseline + Offset::x(icon.toif.width() + ICON_RIGHT_PADDING); } diff --git a/core/embed/rust/src/ui/model_tr/component/result.rs b/core/embed/rust/src/ui/model_tr/component/result.rs index e529ea1fb8..86f07bb346 100644 --- a/core/embed/rust/src/ui/model_tr/component/result.rs +++ b/core/embed/rust/src/ui/model_tr/component/result.rs @@ -2,7 +2,7 @@ use crate::ui::{ component::{Child, Component, Event, EventCtx, Label, Never, Pad}, constant::{screen, HEIGHT, WIDTH}, display::{Color, Icon}, - geometry::{Offset, Point, Rect, CENTER}, + geometry::{Alignment2D, Offset, Point, Rect}, }; const MESSAGE_AREA_START: i16 = 26; @@ -76,7 +76,7 @@ impl<'a> Component for ResultScreen<'a> { self.icon.draw( screen().top_center() + Offset::y(ICON_TOP), - CENTER, + Alignment2D::CENTER, self.fg_color, self.bg_color, ); diff --git a/core/embed/rust/src/ui/model_tr/component/welcome_screen.rs b/core/embed/rust/src/ui/model_tr/component/welcome_screen.rs index e497e81919..d7cdef1673 100644 --- a/core/embed/rust/src/ui/model_tr/component/welcome_screen.rs +++ b/core/embed/rust/src/ui/model_tr/component/welcome_screen.rs @@ -1,6 +1,6 @@ use crate::ui::{ component::{Component, Event, EventCtx, Never}, - geometry::{self, Offset, Rect}, + geometry::{Alignment2D, Offset, Rect}, }; use super::super::theme; @@ -32,13 +32,13 @@ impl Component for WelcomeScreen { fn paint(&mut self) { theme::ICON_DEVICE_NAME.draw( self.area.bottom_center(), - geometry::BOTTOM_CENTER, + Alignment2D::BOTTOM_CENTER, theme::FG, theme::BG, ); theme::ICON_LOGO.draw( self.area.top_center() + Offset::y(ICON_TOP_MARGIN), - geometry::TOP_CENTER, + Alignment2D::TOP_CENTER, theme::FG, theme::BG, ); diff --git a/core/embed/rust/src/ui/model_tt/bootloader/confirm.rs b/core/embed/rust/src/ui/model_tt/bootloader/confirm.rs index 6427373151..37a1805b9c 100644 --- a/core/embed/rust/src/ui/model_tt/bootloader/confirm.rs +++ b/core/embed/rust/src/ui/model_tt/bootloader/confirm.rs @@ -3,7 +3,7 @@ use crate::ui::{ constant, constant::screen, display::{Color, Icon}, - geometry::{Alignment, Insets, Offset, Point, Rect, TOP_CENTER}, + geometry::{Alignment, Alignment2D, Insets, Offset, Point, Rect}, model_tt::{ bootloader::theme::{ button_bld_menu, BUTTON_AREA_START, BUTTON_HEIGHT, CONTENT_PADDING, CORNER_BUTTON_AREA, @@ -212,7 +212,7 @@ impl<'a> Component for Confirm<'a> { ConfirmTitle::Icon(icon) => { icon.draw( Point::new(screen().center().x, ICON_TOP), - TOP_CENTER, + Alignment2D::TOP_CENTER, WHITE, self.bg_color, ); diff --git a/core/embed/rust/src/ui/model_tt/bootloader/mod.rs b/core/embed/rust/src/ui/model_tt/bootloader/mod.rs index 9bfb87e621..a5bef7d697 100644 --- a/core/embed/rust/src/ui/model_tt/bootloader/mod.rs +++ b/core/embed/rust/src/ui/model_tt/bootloader/mod.rs @@ -6,7 +6,7 @@ use crate::{ constant::{screen, HEIGHT}, display::{self, Color, Font, Icon}, event::TouchEvent, - geometry::{Alignment, Point, TOP_CENTER}, + geometry::{Alignment, Alignment2D, Point}, model_tt::{ bootloader::{ confirm::ConfirmTitle, @@ -350,7 +350,12 @@ extern "C" fn screen_boot_empty(fading: bool) { display::rect_fill(constant::screen(), bg); let icon = Icon::new(LOGO_EMPTY); - icon.draw(Point::new(screen().center().x, 48), TOP_CENTER, fg, bg); + icon.draw( + Point::new(screen().center().x, 48), + Alignment2D::TOP_CENTER, + fg, + bg, + ); if fading { fadein(); diff --git a/core/embed/rust/src/ui/model_tt/bootloader/welcome.rs b/core/embed/rust/src/ui/model_tt/bootloader/welcome.rs index 3ec2050198..83c771236c 100644 --- a/core/embed/rust/src/ui/model_tt/bootloader/welcome.rs +++ b/core/embed/rust/src/ui/model_tt/bootloader/welcome.rs @@ -2,7 +2,7 @@ use crate::ui::{ component::{Component, Event, EventCtx, Never, Pad}, constant::screen, display::{self, Font, Icon}, - geometry::{Offset, Rect, TOP_CENTER}, + geometry::{Alignment2D, Offset, Rect}, model_tt::{ bootloader::theme::{START_URL, WELCOME_COLOR}, theme::{BLACK, GREY_MEDIUM, WHITE}, @@ -51,7 +51,7 @@ impl Component for Welcome { ); Icon::new(START_URL).draw( screen().top_center() + Offset::y(135), - TOP_CENTER, + Alignment2D::TOP_CENTER, WHITE, BLACK, ); diff --git a/core/embed/rust/src/ui/model_tt/component/button.rs b/core/embed/rust/src/ui/model_tt/component/button.rs index c6f96f590f..01354296fa 100644 --- a/core/embed/rust/src/ui/model_tt/component/button.rs +++ b/core/embed/rust/src/ui/model_tt/component/button.rs @@ -6,7 +6,7 @@ use crate::{ }, display::{self, toif::Icon, Color, Font}, event::TouchEvent, - geometry::{Insets, Offset, Point, Rect, CENTER}, + geometry::{Alignment2D, Insets, Offset, Point, Rect}, }, }; @@ -211,7 +211,7 @@ impl Button { ButtonContent::Icon(icon) => { icon.draw( self.area.center(), - CENTER, + Alignment2D::CENTER, style.text_color, style.button_color, ); @@ -585,8 +585,12 @@ impl IconText { } if use_icon { - self.icon - .draw(icon_pos, CENTER, style.text_color, style.button_color); + self.icon.draw( + icon_pos, + Alignment2D::CENTER, + style.text_color, + style.button_color, + ); } } } diff --git a/core/embed/rust/src/ui/model_tt/component/error.rs b/core/embed/rust/src/ui/model_tt/component/error.rs index e783a3ecd4..47d350ab55 100644 --- a/core/embed/rust/src/ui/model_tt/component/error.rs +++ b/core/embed/rust/src/ui/model_tt/component/error.rs @@ -1,7 +1,7 @@ use crate::ui::{ component::{Child, Component, Event, EventCtx, Label, Never, Pad}, constant::screen, - geometry::{Alignment::Center, Point, Rect, TOP_CENTER}, + geometry::{Alignment::Center, Alignment2D, Point, Rect}, }; use crate::ui::model_tt::{ @@ -75,7 +75,7 @@ impl> Component for ErrorScreen<'_, T> { let icon = ICON_WARNING40; icon.draw( Point::new(screen().center().x, ICON_TOP), - TOP_CENTER, + Alignment2D::TOP_CENTER, WHITE, FATAL_ERROR_COLOR, ); diff --git a/core/embed/rust/src/ui/model_tt/component/keyboard/bip39.rs b/core/embed/rust/src/ui/model_tt/component/keyboard/bip39.rs index fdd287f4e5..43beb89886 100644 --- a/core/embed/rust/src/ui/model_tt/component/keyboard/bip39.rs +++ b/core/embed/rust/src/ui/model_tt/component/keyboard/bip39.rs @@ -3,7 +3,7 @@ use crate::{ ui::{ component::{text::common::TextBox, Component, Event, EventCtx}, display, - geometry::{Offset, Rect, CENTER}, + geometry::{Alignment2D, Offset, Rect}, model_tt::{ component::{ keyboard::{ @@ -139,7 +139,12 @@ impl Component for Bip39Input { // Icon is painted in the right-center point, of expected size 16x16 pixels, and // 16px from the right edge. let icon_center = area.top_right().center(area.bottom_right()) - Offset::new(16 + 8, 0); - icon.draw(icon_center, CENTER, style.text_color, style.button_color); + icon.draw( + icon_center, + Alignment2D::CENTER, + style.text_color, + style.button_color, + ); } } diff --git a/core/embed/rust/src/ui/model_tt/component/keyboard/mnemonic.rs b/core/embed/rust/src/ui/model_tt/component/keyboard/mnemonic.rs index 6b74255286..f16709fb58 100644 --- a/core/embed/rust/src/ui/model_tt/component/keyboard/mnemonic.rs +++ b/core/embed/rust/src/ui/model_tt/component/keyboard/mnemonic.rs @@ -1,6 +1,6 @@ use crate::ui::{ component::{maybe::paint_overlapping, Child, Component, Event, EventCtx, Label, Maybe}, - geometry::{Grid, Offset, Rect, CENTER}, + geometry::{Alignment2D, Grid, Offset, Rect}, model_tt::{ component::{Button, ButtonMsg}, theme, @@ -104,7 +104,7 @@ where let prompt_center = grid.row_col(0, 0).union(grid.row_col(0, 3)).center(); let prompt_size = self.prompt.inner().inner().max_size(); - let prompt_area = Rect::snap(prompt_center, prompt_size, CENTER); + let prompt_area = Rect::snap(prompt_center, prompt_size, Alignment2D::CENTER); self.prompt.place(prompt_area); self.back.place(back_area); diff --git a/core/embed/rust/src/ui/model_tt/component/keyboard/pin.rs b/core/embed/rust/src/ui/model_tt/component/keyboard/pin.rs index a6711b3043..9f2ccde6e0 100644 --- a/core/embed/rust/src/ui/model_tt/component/keyboard/pin.rs +++ b/core/embed/rust/src/ui/model_tt/component/keyboard/pin.rs @@ -11,7 +11,7 @@ use crate::{ }, display::{self, Font}, event::TouchEvent, - geometry::{Grid, Insets, Offset, Rect, CENTER, TOP_LEFT}, + geometry::{Alignment2D, Grid, Insets, Offset, Rect}, model_tt::component::{ button::{Button, ButtonContent, ButtonMsg, ButtonMsg::Clicked}, theme, @@ -369,7 +369,7 @@ impl PinDots { } fn paint_dots(&self, area: Rect) { - let mut cursor = self.size().snap(area.center(), CENTER); + let mut cursor = self.size().snap(area.center(), Alignment2D::CENTER); let digits = self.digits.len(); let dots_visible = digits.min(MAX_VISIBLE_DOTS); @@ -384,7 +384,7 @@ impl PinDots { if digits > dots_visible + 1 { theme::DOT_SMALL.draw( cursor - Offset::x(2 * step), - TOP_LEFT, + Alignment2D::TOP_LEFT, self.style.text_color, self.style.background_color, ); @@ -394,7 +394,7 @@ impl PinDots { if digits > dots_visible { theme::DOT_ACTIVE.draw( cursor - Offset::x(step), - TOP_LEFT, + Alignment2D::TOP_LEFT, theme::GREY_LIGHT, self.style.background_color, ); @@ -404,7 +404,7 @@ impl PinDots { for _ in 0..dots_visible { theme::DOT_ACTIVE.draw( cursor, - TOP_LEFT, + Alignment2D::TOP_LEFT, self.style.text_color, self.style.background_color, ); diff --git a/core/embed/rust/src/ui/model_tt/component/keyboard/slip39.rs b/core/embed/rust/src/ui/model_tt/component/keyboard/slip39.rs index 45d65e9e51..b1671645fc 100644 --- a/core/embed/rust/src/ui/model_tt/component/keyboard/slip39.rs +++ b/core/embed/rust/src/ui/model_tt/component/keyboard/slip39.rs @@ -10,7 +10,7 @@ use crate::{ Component, Event, EventCtx, }, display, - geometry::{Offset, Rect, CENTER}, + geometry::{Alignment2D, Offset, Rect}, model_tt::{ component::{ keyboard::{ @@ -176,7 +176,12 @@ impl Component for Slip39Input { // Icon is painted in the right-center point, of expected size 16x16 pixels, and // 16px from the right edge. let icon_center = area.top_right().center(area.bottom_right()) - Offset::new(16 + 8, 0); - icon.draw(icon_center, CENTER, style.text_color, style.button_color); + icon.draw( + icon_center, + Alignment2D::CENTER, + style.text_color, + style.button_color, + ); } } diff --git a/core/embed/rust/src/ui/model_tt/component/result.rs b/core/embed/rust/src/ui/model_tt/component/result.rs index 71cf6956ee..18ec4c7b97 100644 --- a/core/embed/rust/src/ui/model_tt/component/result.rs +++ b/core/embed/rust/src/ui/model_tt/component/result.rs @@ -4,7 +4,7 @@ use crate::{ component::{text::TextStyle, Child, Component, Event, EventCtx, Label, Never, Pad}, constant::screen, display::{self, Color, Font, Icon}, - geometry::{Alignment::Center, Insets, Offset, Point, Rect, CENTER}, + geometry::{Alignment::Center, Alignment2D, Insets, Offset, Point, Rect}, model_tt::theme::FG, }, }; @@ -157,7 +157,7 @@ impl Component for ResultScreen<'_, T> { self.icon.draw( Point::new(screen().center().x, ICON_CENTER_Y), - CENTER, + Alignment2D::CENTER, self.style.fg_color, self.style.bg_color, ); diff --git a/core/embed/rust/src/ui/model_tt/component/scroll.rs b/core/embed/rust/src/ui/model_tt/component/scroll.rs index caaca72665..c17bb6607c 100644 --- a/core/embed/rust/src/ui/model_tt/component/scroll.rs +++ b/core/embed/rust/src/ui/model_tt/component/scroll.rs @@ -1,7 +1,7 @@ use crate::ui::{ component::{Component, Event, EventCtx, Never}, display::toif::Icon, - geometry::{LinearPlacement, Offset, Rect, CENTER}, + geometry::{Alignment2D, LinearPlacement, Offset, Rect}, }; use super::theme; @@ -110,7 +110,7 @@ impl Component for ScrollBar { } else { theme::DOT_INACTIVE }; - icon.draw(cursor, CENTER, theme::FG, theme::BG); + icon.draw(cursor, Alignment2D::CENTER, theme::FG, theme::BG); cursor = cursor + Offset::on_axis(self.layout.axis, Self::DOT_INTERVAL); } } diff --git a/core/embed/rust/src/ui/model_tt/component/welcome_screen.rs b/core/embed/rust/src/ui/model_tt/component/welcome_screen.rs index 9de44bb70e..0566166534 100644 --- a/core/embed/rust/src/ui/model_tt/component/welcome_screen.rs +++ b/core/embed/rust/src/ui/model_tt/component/welcome_screen.rs @@ -1,12 +1,11 @@ -#[cfg(feature = "bootloader")] -use crate::ui::model_tt::bootloader::theme::DEVICE_NAME; use crate::ui::{ component::{Component, Event, EventCtx, Never}, constant::MODEL_NAME, - display::Icon, - geometry::{self, Offset, Rect}, + geometry::{Alignment2D, Offset, Rect}, model_tt::theme, }; +#[cfg(feature = "bootloader")] +use crate::ui::{display::Icon, model_tt::bootloader::theme::DEVICE_NAME}; const TEXT_BOTTOM_MARGIN: i16 = 24; // matching the homescreen label margin const ICON_TOP_MARGIN: i16 = 48; @@ -40,7 +39,7 @@ impl Component for WelcomeScreen { fn paint(&mut self) { theme::ICON_LOGO.draw( self.area.top_center() + Offset::y(ICON_TOP_MARGIN), - geometry::TOP_CENTER, + Alignment2D::TOP_CENTER, theme::FG, theme::BG, ); @@ -55,7 +54,7 @@ impl Component for WelcomeScreen { #[cfg(feature = "bootloader")] Icon::new(DEVICE_NAME).draw( self.area.bottom_center() - Offset::y(TEXT_BOTTOM_MARGIN) + Offset::y(1), - geometry::BOTTOM_CENTER, + Alignment2D::BOTTOM_CENTER, theme::FG, theme::BG, ); diff --git a/core/embed/rust/src/ui/util.rs b/core/embed/rust/src/ui/util.rs index 88efa3c529..4bba2cb2b1 100644 --- a/core/embed/rust/src/ui/util.rs +++ b/core/embed/rust/src/ui/util.rs @@ -4,7 +4,7 @@ use crate::{ component::text::TextStyle, display, display::toif::Icon, - geometry::{Offset, Point, CENTER}, + geometry::{Alignment2D, Offset, Point}, }, }; @@ -121,7 +121,7 @@ pub fn icon_text_center( ); icon.draw( icon_center, - CENTER, + Alignment2D::CENTER, style.text_color, style.background_color, );