refactor(core/ui): namespaced Alignment2D

[no changelog]
pull/2966/head
Martin Milata 12 months ago
parent 3a5fdfedcc
commit cf4dcfcbd4

@ -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())

@ -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<F> {
@ -53,7 +53,7 @@ impl<F> crate::trace::Trace for Painter<F> {
}
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)
}

@ -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<T> {
@ -140,7 +140,7 @@ impl<T> Floating<T> {
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)
}
}

@ -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,
);

@ -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<T> Checklist<T> {
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,
);

@ -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);
}
}

@ -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

@ -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")]

@ -513,15 +513,17 @@ pub enum Alignment {
End,
}
pub type Alignment2D = (Alignment, 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);
pub struct Alignment2D(pub Alignment, pub Alignment);
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 {

@ -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();
}

@ -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(

@ -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,
);

@ -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)
}
}
}
}

@ -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<T: AsRef<str>> Component for ErrorScreen<T> {
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();

@ -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,
);

@ -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);
}

@ -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,
);

@ -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,
);

@ -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,
);

@ -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();

@ -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,
);

@ -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<T> Button<T> {
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,
);
}
}
}

@ -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<T: AsRef<str>> 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,
);

@ -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,
);
}
}

@ -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);

@ -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,
);

@ -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,
);
}
}

@ -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<T: StringType> 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,
);

@ -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);
}
}

@ -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,
);

@ -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,
);

Loading…
Cancel
Save