1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

refactor(core/ui): namespaced Alignment2D

[no changelog]
This commit is contained in:
Martin Milata 2023-06-16 15:43:50 +02:00
parent 3a5fdfedcc
commit cf4dcfcbd4
31 changed files with 145 additions and 99 deletions

View File

@ -7,7 +7,7 @@ use crate::{
toif::{image, Toif}, toif::{image, Toif},
Color, Icon, 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) { fn paint(&mut self) {
self.draw(self.area.center(), CENTER); self.draw(self.area.center(), Alignment2D::CENTER);
} }
#[cfg(feature = "ui_bounds")] #[cfg(feature = "ui_bounds")]
@ -110,9 +110,16 @@ impl Component for BlendedImage {
type Msg = Never; type Msg = Never;
fn place(&mut self, bounds: Rect) -> Rect { fn place(&mut self, bounds: Rect) -> Rect {
self.bg_top_left = self.bg.toif.size().snap(bounds.center(), CENTER); self.bg_top_left = self
.bg
let ft_top_left = self.fg.toif.size().snap(bounds.center(), CENTER); .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; self.fg_offset = ft_top_left - self.bg_top_left;
Rect::from_top_left_and_size(self.bg_top_left, self.bg.toif.size()) Rect::from_top_left_and_size(self.bg_top_left, self.bg.toif.size())

View File

@ -3,7 +3,7 @@ use crate::ui::geometry::Offset;
use crate::ui::{ use crate::ui::{
component::{image::Image, Component, Event, EventCtx, Never}, component::{image::Image, Component, Event, EventCtx, Never},
display, display,
geometry::{Rect, CENTER}, geometry::{Alignment2D, Rect},
}; };
pub struct Painter<F> { pub struct Painter<F> {
@ -53,7 +53,7 @@ impl<F> crate::trace::Trace for Painter<F> {
} }
pub fn image_painter(image: Image) -> Painter<impl FnMut(Rect)> { pub fn image_painter(image: Image) -> Painter<impl FnMut(Rect)> {
let f = move |area: Rect| image.draw(area.center(), CENTER); let f = move |area: Rect| image.draw(area.center(), Alignment2D::CENTER);
Painter::new(f) Painter::new(f)
} }

View File

@ -1,6 +1,6 @@
use crate::ui::{ use crate::ui::{
component::{Component, Event, EventCtx}, 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<T> { pub struct GridPlaced<T> {
@ -140,7 +140,7 @@ impl<T> Floating<T> {
pub const fn top_right(side: i16, border: i16, inner: T) -> Self { pub const fn top_right(side: i16, border: i16, inner: T) -> Self {
let size = Offset::uniform(side); let size = Offset::uniform(side);
let border = Offset::uniform(border); let border = Offset::uniform(border);
Self::new(size, border, TOP_RIGHT, inner) Self::new(size, border, Alignment2D::TOP_RIGHT, inner)
} }
} }

View File

@ -1,7 +1,7 @@
use crate::ui::{ use crate::ui::{
display, display,
display::{toif::Icon, Color, Font, GlyphMetrics}, display::{toif::Icon, Color, Font, GlyphMetrics},
geometry::{Alignment, Dimensions, Offset, Point, Rect, BOTTOM_LEFT}, geometry::{Alignment, Alignment2D, Dimensions, Offset, Point, Rect},
}; };
const ELLIPSIS: &str = "..."; const ELLIPSIS: &str = "...";
@ -397,7 +397,7 @@ impl LayoutSink for TextRenderer {
let bottom_left = cursor + Offset::x(margin); let bottom_left = cursor + Offset::x(margin);
icon.draw( icon.draw(
bottom_left, bottom_left,
BOTTOM_LEFT, Alignment2D::BOTTOM_LEFT,
layout.style.ellipsis_color, layout.style.ellipsis_color,
layout.style.background_color, layout.style.background_color,
); );
@ -416,7 +416,7 @@ impl LayoutSink for TextRenderer {
if let Some((icon, _margin)) = layout.style.prev_page_ellipsis_icon { if let Some((icon, _margin)) = layout.style.prev_page_ellipsis_icon {
icon.draw( icon.draw(
cursor, cursor,
BOTTOM_LEFT, Alignment2D::BOTTOM_LEFT,
layout.style.ellipsis_color, layout.style.ellipsis_color,
layout.style.background_color, layout.style.background_color,
); );

View File

@ -5,7 +5,7 @@ use crate::{
ui::{ ui::{
component::{Component, Event, EventCtx, Never, Paginate}, component::{Component, Event, EventCtx, Never, Paginate},
display::toif::Icon, 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<T> Checklist<T> {
let top_left = Point::new(self.area.x0, layout.bounds.y0); let top_left = Point::new(self.area.x0, layout.bounds.y0);
icon.draw( icon.draw(
top_left + offset, top_left + offset,
TOP_LEFT, Alignment2D::TOP_LEFT,
layout.style.text_color, layout.style.text_color,
layout.style.background_color, layout.style.background_color,
); );

View File

@ -1,7 +1,7 @@
use crate::ui::{ use crate::ui::{
constant::{screen, LOADER_OUTER}, constant::{screen, LOADER_OUTER},
display::{rect_fill, rect_fill_rounded, Color, Icon}, display::{rect_fill, rect_fill_rounded, Color, Icon},
geometry::{Offset, Point, Rect, CENTER}, geometry::{Alignment2D, Offset, Point, Rect},
}; };
use core::f32::consts::SQRT_2; use core::f32::consts::SQRT_2;
@ -62,6 +62,6 @@ pub fn loader_starry_indeterminate(
} }
if let Some((icon, color)) = icon { if let Some((icon, color)) = icon {
icon.draw(area.center(), CENTER, color, bg_color); icon.draw(area.center(), Alignment2D::CENTER, color, bg_color);
} }
} }

View File

@ -21,7 +21,7 @@ use crate::trezorhal::{
use crate::ui::component::image::Image; use crate::ui::component::image::Image;
#[cfg(not(feature = "dma2d"))] #[cfg(not(feature = "dma2d"))]
use crate::ui::geometry::TOP_LEFT; use crate::ui::geometry::Alignment2D;
use crate::{ use crate::{
time::Duration, time::Duration,
@ -725,8 +725,13 @@ pub fn icon_over_icon(
Point::from(offset_bg) Point::from(offset_bg)
}; };
icon_bg.draw(pos_bg, TOP_LEFT, color_icon_bg, bg_color); icon_bg.draw(pos_bg, Alignment2D::TOP_LEFT, color_icon_bg, bg_color);
icon_fg.draw(pos_bg + offset_fg, TOP_LEFT, color_icon_fg, color_icon_bg); 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 /// Gets a color of a pixel on `p` coordinates of rounded rectangle with corner

View File

@ -11,7 +11,6 @@ use crate::{
}, },
}; };
use crate::ui::geometry::TOP_LEFT;
#[cfg(feature = "dma2d")] #[cfg(feature = "dma2d")]
use crate::{ use crate::{
trezorhal::{ 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 data_slice = unsafe { core::slice::from_raw_parts(data, data_len as usize) };
let image = Image::new(data_slice); 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")] #[cfg(feature = "dma2d")]

View File

@ -513,15 +513,17 @@ pub enum Alignment {
End, End,
} }
pub type Alignment2D = (Alignment, Alignment); pub struct Alignment2D(pub Alignment, pub Alignment);
pub const TOP_LEFT: Alignment2D = (Alignment::Start, Alignment::Start); impl Alignment2D {
pub const TOP_RIGHT: Alignment2D = (Alignment::End, Alignment::Start); pub const TOP_LEFT: Alignment2D = Alignment2D(Alignment::Start, Alignment::Start);
pub const TOP_CENTER: Alignment2D = (Alignment::Center, Alignment::Start); pub const TOP_RIGHT: Alignment2D = Alignment2D(Alignment::End, Alignment::Start);
pub const CENTER: Alignment2D = (Alignment::Center, Alignment::Center); pub const TOP_CENTER: Alignment2D = Alignment2D(Alignment::Center, Alignment::Start);
pub const BOTTOM_LEFT: Alignment2D = (Alignment::Start, Alignment::End); pub const CENTER: Alignment2D = Alignment2D(Alignment::Center, Alignment::Center);
pub const BOTTOM_RIGHT: Alignment2D = (Alignment::End, Alignment::End); pub const BOTTOM_LEFT: Alignment2D = Alignment2D(Alignment::Start, Alignment::End);
pub const BOTTOM_CENTER: Alignment2D = (Alignment::Center, 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)] #[derive(Copy, Clone, PartialEq, Eq)]
pub enum Axis { pub enum Axis {

View File

@ -1,6 +1,6 @@
use crate::ui::{ use crate::ui::{
component::{Child, Component, Event, EventCtx, Label, Pad}, component::{Child, Component, Event, EventCtx, Label, Pad},
geometry::{Alignment, Rect, TOP_LEFT, TOP_RIGHT}, geometry::{Alignment, Alignment2D, Rect},
}; };
use super::{ use super::{
@ -86,8 +86,8 @@ impl<'a> Component for Intro<'a> {
self.bg.paint(); self.bg.paint();
self.title.paint(); self.title.paint();
let area = self.bg.area; let area = self.bg.area;
ICON_WARN_TITLE.draw(area.top_left(), TOP_LEFT, 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(), TOP_RIGHT, BLD_FG, BLD_BG); ICON_WARN_TITLE.draw(area.top_right(), Alignment2D::TOP_RIGHT, BLD_FG, BLD_BG);
self.text.paint(); self.text.paint();
self.buttons.paint(); self.buttons.paint();
} }

View File

@ -5,7 +5,7 @@ use crate::ui::{
constant::screen, constant::screen,
display, display,
display::{Font, Icon}, display::{Font, Icon},
geometry::{Offset, Point, Rect, CENTER}, geometry::{Alignment2D, Offset, Point, Rect},
}; };
use super::{ use super::{
@ -49,8 +49,12 @@ impl MenuChoice {
impl Choice<&'static str> for MenuChoice { impl Choice<&'static str> for MenuChoice {
fn paint_center(&self, _area: Rect, _inverse: bool) { fn paint_center(&self, _area: Rect, _inverse: bool) {
// Icon on top and two lines of text below // Icon on top and two lines of text below
self.icon self.icon.draw(
.draw(SCREEN_CENTER + Offset::y(-20), CENTER, BLD_FG, BLD_BG); 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(SCREEN_CENTER, self.first_line, Font::NORMAL, BLD_FG, BLD_BG);
display::text_center( display::text_center(

View File

@ -7,7 +7,7 @@ use crate::{
constant::SCREEN, constant::SCREEN,
display::{self, Color, Font, Icon}, display::{self, Color, Font, Icon},
event::ButtonEvent, event::ButtonEvent,
geometry::{Alignment, Alignment::Center, Offset, Rect, TOP_CENTER}, geometry::{Alignment, Alignment::Center, Alignment2D, Offset, Rect},
util::{from_c_array, from_c_str}, 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); display::rect_fill(SCREEN, BLD_BG);
LOGO_EMPTY.draw( LOGO_EMPTY.draw(
SCREEN.top_center() + Offset::y(11), SCREEN.top_center() + Offset::y(11),
TOP_CENTER, Alignment2D::TOP_CENTER,
BLD_FG, BLD_FG,
BLD_BG, BLD_BG,
); );

View File

@ -5,9 +5,7 @@ use crate::{
component::{Component, Event, EventCtx, Never}, component::{Component, Event, EventCtx, Never},
constant, constant,
display::{self, Color, Font, Icon}, display::{self, Color, Font, Icon},
geometry::{ geometry::{Alignment2D, Insets, Offset, Point, Rect},
Insets, Offset, Point, Rect, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER, TOP_LEFT, TOP_RIGHT,
},
}, },
}; };
@ -215,13 +213,13 @@ where
// 2 px because 1px might lead to odd coordinate which can't be render // 2 px because 1px might lead to odd coordinate which can't be render
theme::ICON_ARM_LEFT.draw( theme::ICON_ARM_LEFT.draw(
area.left_center() - Offset::x(2), area.left_center() - Offset::x(2),
TOP_RIGHT, Alignment2D::TOP_RIGHT,
text_color, text_color,
background_color, background_color,
); );
theme::ICON_ARM_RIGHT.draw( theme::ICON_ARM_RIGHT.draw(
area.right_center() + Offset::x(2), area.right_center() + Offset::x(2),
TOP_LEFT, Alignment2D::TOP_LEFT,
text_color, text_color,
background_color, background_color,
); );
@ -254,25 +252,28 @@ where
// Accounting for the 8*8 icon with empty left column and bottom row // Accounting for the 8*8 icon with empty left column and bottom row
// (which fits the outline nicely and symmetrically) // (which fits the outline nicely and symmetrically)
let center = area.center() + Offset::uniform(1); 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 { } else {
// Positioning the icon in the corresponding corner/center // Positioning the icon in the corresponding corner/center
match self.pos { match self.pos {
ButtonPos::Left => icon.draw( ButtonPos::Left => icon.draw(
area.bottom_left(), area.bottom_left(),
BOTTOM_LEFT, Alignment2D::BOTTOM_LEFT,
text_color, text_color,
background_color, background_color,
), ),
ButtonPos::Right => icon.draw( ButtonPos::Right => icon.draw(
area.bottom_right(), area.bottom_right(),
BOTTOM_RIGHT, Alignment2D::BOTTOM_RIGHT,
text_color,
background_color,
),
ButtonPos::Middle => icon.draw(
area.center(),
Alignment2D::CENTER,
text_color, text_color,
background_color, background_color,
), ),
ButtonPos::Middle => {
icon.draw(area.center(), CENTER, text_color, background_color)
}
} }
} }
} }

View File

@ -2,7 +2,7 @@ use crate::ui::{
component::{Child, Component, Event, EventCtx, Label, Never, Pad}, component::{Child, Component, Event, EventCtx, Label, Never, Pad},
constant::screen, constant::screen,
display, display,
geometry::{Alignment::Center, Offset, Point, Rect, TOP_LEFT, TOP_RIGHT}, geometry::{Alignment::Center, Alignment2D, Offset, Point, Rect},
}; };
use super::super::{ use super::super::{
@ -79,8 +79,8 @@ impl<T: AsRef<str>> Component for ErrorScreen<T> {
self.bg.paint(); self.bg.paint();
if self.show_icons { if self.show_icons {
theme::ICON_WARN_TITLE.draw(screen().top_left(), TOP_LEFT, FG, BG); theme::ICON_WARN_TITLE.draw(screen().top_left(), Alignment2D::TOP_LEFT, FG, BG);
theme::ICON_WARN_TITLE.draw(screen().top_right(), TOP_RIGHT, FG, BG); theme::ICON_WARN_TITLE.draw(screen().top_right(), Alignment2D::TOP_RIGHT, FG, BG);
} }
self.title.paint(); self.title.paint();
self.message.paint(); self.message.paint();

View File

@ -5,7 +5,7 @@ use crate::{
component::{Child, Component, Event, EventCtx, Label}, component::{Child, Component, Event, EventCtx, Label},
display::{rect_fill, toif::Toif, Font}, display::{rect_fill, toif::Toif, Font},
event::USBEvent, event::USBEvent,
geometry::{self, Insets, Offset, Point, Rect}, geometry::{Alignment2D, Insets, Offset, Point, Rect},
layout::util::get_user_custom_image, layout::util::get_user_custom_image,
}, },
}; };
@ -54,11 +54,11 @@ where
fn paint_homescreen_image(&self) { fn paint_homescreen_image(&self) {
if let Ok(user_custom_image) = get_user_custom_image() { if let Ok(user_custom_image) = get_user_custom_image() {
let toif_data = unwrap!(Toif::new(user_custom_image.as_ref())); 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 { } else {
theme::ICON_LOGO.draw( theme::ICON_LOGO.draw(
TOP_CENTER + Offset::y(LOGO_ICON_TOP_MARGIN), TOP_CENTER + Offset::y(LOGO_ICON_TOP_MARGIN),
geometry::TOP_CENTER, Alignment2D::TOP_CENTER,
theme::FG, theme::FG,
theme::BG, theme::BG,
); );
@ -96,8 +96,13 @@ where
fn paint_warning_icons_in_top_corners(&self) { fn paint_warning_icons_in_top_corners(&self) {
let warning_icon = theme::ICON_WARNING; let warning_icon = theme::ICON_WARNING;
warning_icon.draw(AREA.top_left(), geometry::TOP_LEFT, theme::FG, theme::BG); warning_icon.draw(AREA.top_left(), Alignment2D::TOP_LEFT, theme::FG, theme::BG);
warning_icon.draw(AREA.top_right(), geometry::TOP_RIGHT, 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) { fn event_usb(&mut self, ctx: &mut EventCtx, event: Event) {
@ -188,7 +193,7 @@ where
fn paint(&mut self) { fn paint(&mut self) {
theme::ICON_LOCK.draw( theme::ICON_LOCK.draw(
TOP_CENTER + Offset::y(LOCK_ICON_TOP_MARGIN), TOP_CENTER + Offset::y(LOCK_ICON_TOP_MARGIN),
geometry::TOP_CENTER, Alignment2D::TOP_CENTER,
theme::FG, theme::FG,
theme::BG, theme::BG,
); );

View File

@ -2,7 +2,7 @@ use crate::{
strutil::{ShortString, StringType}, strutil::{ShortString, StringType},
ui::{ ui::{
display::{self, rect_fill, rect_fill_corners, rect_outline_rounded, Font, Icon}, 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 { if let Some(icon) = icon {
let height_diff = font.text_height() - icon.toif.height(); let height_diff = font.text_height() - icon.toif.height();
let vertical_offset = Offset::y(-height_diff / 2); 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); baseline = baseline + Offset::x(icon.toif.width() + ICON_RIGHT_PADDING);
} }

View File

@ -2,7 +2,7 @@ use crate::ui::{
component::{Child, Component, Event, EventCtx, Label, Never, Pad}, component::{Child, Component, Event, EventCtx, Label, Never, Pad},
constant::{screen, HEIGHT, WIDTH}, constant::{screen, HEIGHT, WIDTH},
display::{Color, Icon}, display::{Color, Icon},
geometry::{Offset, Point, Rect, CENTER}, geometry::{Alignment2D, Offset, Point, Rect},
}; };
const MESSAGE_AREA_START: i16 = 26; const MESSAGE_AREA_START: i16 = 26;
@ -76,7 +76,7 @@ impl<'a> Component for ResultScreen<'a> {
self.icon.draw( self.icon.draw(
screen().top_center() + Offset::y(ICON_TOP), screen().top_center() + Offset::y(ICON_TOP),
CENTER, Alignment2D::CENTER,
self.fg_color, self.fg_color,
self.bg_color, self.bg_color,
); );

View File

@ -1,6 +1,6 @@
use crate::ui::{ use crate::ui::{
component::{Component, Event, EventCtx, Never}, component::{Component, Event, EventCtx, Never},
geometry::{self, Offset, Rect}, geometry::{Alignment2D, Offset, Rect},
}; };
use super::super::theme; use super::super::theme;
@ -32,13 +32,13 @@ impl Component for WelcomeScreen {
fn paint(&mut self) { fn paint(&mut self) {
theme::ICON_DEVICE_NAME.draw( theme::ICON_DEVICE_NAME.draw(
self.area.bottom_center(), self.area.bottom_center(),
geometry::BOTTOM_CENTER, Alignment2D::BOTTOM_CENTER,
theme::FG, theme::FG,
theme::BG, theme::BG,
); );
theme::ICON_LOGO.draw( theme::ICON_LOGO.draw(
self.area.top_center() + Offset::y(ICON_TOP_MARGIN), self.area.top_center() + Offset::y(ICON_TOP_MARGIN),
geometry::TOP_CENTER, Alignment2D::TOP_CENTER,
theme::FG, theme::FG,
theme::BG, theme::BG,
); );

View File

@ -3,7 +3,7 @@ use crate::ui::{
constant, constant,
constant::screen, constant::screen,
display::{Color, Icon}, display::{Color, Icon},
geometry::{Alignment, Insets, Offset, Point, Rect, TOP_CENTER}, geometry::{Alignment, Alignment2D, Insets, Offset, Point, Rect},
model_tt::{ model_tt::{
bootloader::theme::{ bootloader::theme::{
button_bld_menu, BUTTON_AREA_START, BUTTON_HEIGHT, CONTENT_PADDING, CORNER_BUTTON_AREA, 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) => { ConfirmTitle::Icon(icon) => {
icon.draw( icon.draw(
Point::new(screen().center().x, ICON_TOP), Point::new(screen().center().x, ICON_TOP),
TOP_CENTER, Alignment2D::TOP_CENTER,
WHITE, WHITE,
self.bg_color, self.bg_color,
); );

View File

@ -6,7 +6,7 @@ use crate::{
constant::{screen, HEIGHT}, constant::{screen, HEIGHT},
display::{self, Color, Font, Icon}, display::{self, Color, Font, Icon},
event::TouchEvent, event::TouchEvent,
geometry::{Alignment, Point, TOP_CENTER}, geometry::{Alignment, Alignment2D, Point},
model_tt::{ model_tt::{
bootloader::{ bootloader::{
confirm::ConfirmTitle, confirm::ConfirmTitle,
@ -350,7 +350,12 @@ extern "C" fn screen_boot_empty(fading: bool) {
display::rect_fill(constant::screen(), bg); display::rect_fill(constant::screen(), bg);
let icon = Icon::new(LOGO_EMPTY); 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 { if fading {
fadein(); fadein();

View File

@ -2,7 +2,7 @@ use crate::ui::{
component::{Component, Event, EventCtx, Never, Pad}, component::{Component, Event, EventCtx, Never, Pad},
constant::screen, constant::screen,
display::{self, Font, Icon}, display::{self, Font, Icon},
geometry::{Offset, Rect, TOP_CENTER}, geometry::{Alignment2D, Offset, Rect},
model_tt::{ model_tt::{
bootloader::theme::{START_URL, WELCOME_COLOR}, bootloader::theme::{START_URL, WELCOME_COLOR},
theme::{BLACK, GREY_MEDIUM, WHITE}, theme::{BLACK, GREY_MEDIUM, WHITE},
@ -51,7 +51,7 @@ impl Component for Welcome {
); );
Icon::new(START_URL).draw( Icon::new(START_URL).draw(
screen().top_center() + Offset::y(135), screen().top_center() + Offset::y(135),
TOP_CENTER, Alignment2D::TOP_CENTER,
WHITE, WHITE,
BLACK, BLACK,
); );

View File

@ -6,7 +6,7 @@ use crate::{
}, },
display::{self, toif::Icon, Color, Font}, display::{self, toif::Icon, Color, Font},
event::TouchEvent, event::TouchEvent,
geometry::{Insets, Offset, Point, Rect, CENTER}, geometry::{Alignment2D, Insets, Offset, Point, Rect},
}, },
}; };
@ -211,7 +211,7 @@ impl<T> Button<T> {
ButtonContent::Icon(icon) => { ButtonContent::Icon(icon) => {
icon.draw( icon.draw(
self.area.center(), self.area.center(),
CENTER, Alignment2D::CENTER,
style.text_color, style.text_color,
style.button_color, style.button_color,
); );
@ -585,8 +585,12 @@ impl IconText {
} }
if use_icon { if use_icon {
self.icon self.icon.draw(
.draw(icon_pos, CENTER, style.text_color, style.button_color); icon_pos,
Alignment2D::CENTER,
style.text_color,
style.button_color,
);
} }
} }
} }

View File

@ -1,7 +1,7 @@
use crate::ui::{ use crate::ui::{
component::{Child, Component, Event, EventCtx, Label, Never, Pad}, component::{Child, Component, Event, EventCtx, Label, Never, Pad},
constant::screen, constant::screen,
geometry::{Alignment::Center, Point, Rect, TOP_CENTER}, geometry::{Alignment::Center, Alignment2D, Point, Rect},
}; };
use crate::ui::model_tt::{ use crate::ui::model_tt::{
@ -75,7 +75,7 @@ impl<T: AsRef<str>> Component for ErrorScreen<'_, T> {
let icon = ICON_WARNING40; let icon = ICON_WARNING40;
icon.draw( icon.draw(
Point::new(screen().center().x, ICON_TOP), Point::new(screen().center().x, ICON_TOP),
TOP_CENTER, Alignment2D::TOP_CENTER,
WHITE, WHITE,
FATAL_ERROR_COLOR, FATAL_ERROR_COLOR,
); );

View File

@ -3,7 +3,7 @@ use crate::{
ui::{ ui::{
component::{text::common::TextBox, Component, Event, EventCtx}, component::{text::common::TextBox, Component, Event, EventCtx},
display, display,
geometry::{Offset, Rect, CENTER}, geometry::{Alignment2D, Offset, Rect},
model_tt::{ model_tt::{
component::{ component::{
keyboard::{ keyboard::{
@ -139,7 +139,12 @@ impl Component for Bip39Input {
// Icon is painted in the right-center point, of expected size 16x16 pixels, and // Icon is painted in the right-center point, of expected size 16x16 pixels, and
// 16px from the right edge. // 16px from the right edge.
let icon_center = area.top_right().center(area.bottom_right()) - Offset::new(16 + 8, 0); 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,
);
} }
} }

View File

@ -1,6 +1,6 @@
use crate::ui::{ use crate::ui::{
component::{maybe::paint_overlapping, Child, Component, Event, EventCtx, Label, Maybe}, component::{maybe::paint_overlapping, Child, Component, Event, EventCtx, Label, Maybe},
geometry::{Grid, Offset, Rect, CENTER}, geometry::{Alignment2D, Grid, Offset, Rect},
model_tt::{ model_tt::{
component::{Button, ButtonMsg}, component::{Button, ButtonMsg},
theme, theme,
@ -104,7 +104,7 @@ where
let prompt_center = grid.row_col(0, 0).union(grid.row_col(0, 3)).center(); 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_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.prompt.place(prompt_area);
self.back.place(back_area); self.back.place(back_area);

View File

@ -11,7 +11,7 @@ use crate::{
}, },
display::{self, Font}, display::{self, Font},
event::TouchEvent, event::TouchEvent,
geometry::{Grid, Insets, Offset, Rect, CENTER, TOP_LEFT}, geometry::{Alignment2D, Grid, Insets, Offset, Rect},
model_tt::component::{ model_tt::component::{
button::{Button, ButtonContent, ButtonMsg, ButtonMsg::Clicked}, button::{Button, ButtonContent, ButtonMsg, ButtonMsg::Clicked},
theme, theme,
@ -369,7 +369,7 @@ impl PinDots {
} }
fn paint_dots(&self, area: Rect) { 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 digits = self.digits.len();
let dots_visible = digits.min(MAX_VISIBLE_DOTS); let dots_visible = digits.min(MAX_VISIBLE_DOTS);
@ -384,7 +384,7 @@ impl PinDots {
if digits > dots_visible + 1 { if digits > dots_visible + 1 {
theme::DOT_SMALL.draw( theme::DOT_SMALL.draw(
cursor - Offset::x(2 * step), cursor - Offset::x(2 * step),
TOP_LEFT, Alignment2D::TOP_LEFT,
self.style.text_color, self.style.text_color,
self.style.background_color, self.style.background_color,
); );
@ -394,7 +394,7 @@ impl PinDots {
if digits > dots_visible { if digits > dots_visible {
theme::DOT_ACTIVE.draw( theme::DOT_ACTIVE.draw(
cursor - Offset::x(step), cursor - Offset::x(step),
TOP_LEFT, Alignment2D::TOP_LEFT,
theme::GREY_LIGHT, theme::GREY_LIGHT,
self.style.background_color, self.style.background_color,
); );
@ -404,7 +404,7 @@ impl PinDots {
for _ in 0..dots_visible { for _ in 0..dots_visible {
theme::DOT_ACTIVE.draw( theme::DOT_ACTIVE.draw(
cursor, cursor,
TOP_LEFT, Alignment2D::TOP_LEFT,
self.style.text_color, self.style.text_color,
self.style.background_color, self.style.background_color,
); );

View File

@ -10,7 +10,7 @@ use crate::{
Component, Event, EventCtx, Component, Event, EventCtx,
}, },
display, display,
geometry::{Offset, Rect, CENTER}, geometry::{Alignment2D, Offset, Rect},
model_tt::{ model_tt::{
component::{ component::{
keyboard::{ keyboard::{
@ -176,7 +176,12 @@ impl Component for Slip39Input {
// Icon is painted in the right-center point, of expected size 16x16 pixels, and // Icon is painted in the right-center point, of expected size 16x16 pixels, and
// 16px from the right edge. // 16px from the right edge.
let icon_center = area.top_right().center(area.bottom_right()) - Offset::new(16 + 8, 0); 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,
);
} }
} }

View File

@ -4,7 +4,7 @@ use crate::{
component::{text::TextStyle, Child, Component, Event, EventCtx, Label, Never, Pad}, component::{text::TextStyle, Child, Component, Event, EventCtx, Label, Never, Pad},
constant::screen, constant::screen,
display::{self, Color, Font, Icon}, 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, model_tt::theme::FG,
}, },
}; };
@ -157,7 +157,7 @@ impl<T: StringType> Component for ResultScreen<'_, T> {
self.icon.draw( self.icon.draw(
Point::new(screen().center().x, ICON_CENTER_Y), Point::new(screen().center().x, ICON_CENTER_Y),
CENTER, Alignment2D::CENTER,
self.style.fg_color, self.style.fg_color,
self.style.bg_color, self.style.bg_color,
); );

View File

@ -1,7 +1,7 @@
use crate::ui::{ use crate::ui::{
component::{Component, Event, EventCtx, Never}, component::{Component, Event, EventCtx, Never},
display::toif::Icon, display::toif::Icon,
geometry::{LinearPlacement, Offset, Rect, CENTER}, geometry::{Alignment2D, LinearPlacement, Offset, Rect},
}; };
use super::theme; use super::theme;
@ -110,7 +110,7 @@ impl Component for ScrollBar {
} else { } else {
theme::DOT_INACTIVE 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); cursor = cursor + Offset::on_axis(self.layout.axis, Self::DOT_INTERVAL);
} }
} }

View File

@ -1,12 +1,11 @@
#[cfg(feature = "bootloader")]
use crate::ui::model_tt::bootloader::theme::DEVICE_NAME;
use crate::ui::{ use crate::ui::{
component::{Component, Event, EventCtx, Never}, component::{Component, Event, EventCtx, Never},
constant::MODEL_NAME, constant::MODEL_NAME,
display::Icon, geometry::{Alignment2D, Offset, Rect},
geometry::{self, Offset, Rect},
model_tt::theme, 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 TEXT_BOTTOM_MARGIN: i16 = 24; // matching the homescreen label margin
const ICON_TOP_MARGIN: i16 = 48; const ICON_TOP_MARGIN: i16 = 48;
@ -40,7 +39,7 @@ impl Component for WelcomeScreen {
fn paint(&mut self) { fn paint(&mut self) {
theme::ICON_LOGO.draw( theme::ICON_LOGO.draw(
self.area.top_center() + Offset::y(ICON_TOP_MARGIN), self.area.top_center() + Offset::y(ICON_TOP_MARGIN),
geometry::TOP_CENTER, Alignment2D::TOP_CENTER,
theme::FG, theme::FG,
theme::BG, theme::BG,
); );
@ -55,7 +54,7 @@ impl Component for WelcomeScreen {
#[cfg(feature = "bootloader")] #[cfg(feature = "bootloader")]
Icon::new(DEVICE_NAME).draw( Icon::new(DEVICE_NAME).draw(
self.area.bottom_center() - Offset::y(TEXT_BOTTOM_MARGIN) + Offset::y(1), self.area.bottom_center() - Offset::y(TEXT_BOTTOM_MARGIN) + Offset::y(1),
geometry::BOTTOM_CENTER, Alignment2D::BOTTOM_CENTER,
theme::FG, theme::FG,
theme::BG, theme::BG,
); );

View File

@ -4,7 +4,7 @@ use crate::{
component::text::TextStyle, component::text::TextStyle,
display, display,
display::toif::Icon, display::toif::Icon,
geometry::{Offset, Point, CENTER}, geometry::{Alignment2D, Offset, Point},
}, },
}; };
@ -121,7 +121,7 @@ pub fn icon_text_center(
); );
icon.draw( icon.draw(
icon_center, icon_center,
CENTER, Alignment2D::CENTER,
style.text_color, style.text_color,
style.background_color, style.background_color,
); );