1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-19 14:08:11 +00:00

refactor(core/bootloader): make use of Label vertical alignment

This commit is contained in:
matejcik 2023-03-30 13:03:56 +02:00
parent c3af3eafe2
commit a9a18bf80d
4 changed files with 20 additions and 50 deletions

View File

@ -7,8 +7,7 @@ use crate::ui::{
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,
CORNER_BUTTON_TOUCH_EXPANSION, INFO32, TEXT_FINGERPRINT, TEXT_TITLE, TITLE_AREA, CORNER_BUTTON_TOUCH_EXPANSION, INFO32, TEXT_FINGERPRINT, TEXT_TITLE, TITLE_AREA, X32,
TITLE_Y_ADJUSTMENT, X32,
}, },
component::{Button, ButtonMsg::Clicked}, component::{Button, ButtonMsg::Clicked},
constant::WIDTH, constant::WIDTH,
@ -64,16 +63,19 @@ impl<'a> Confirm<'a> {
content_pad: Pad::with_background(bg_color), content_pad: Pad::with_background(bg_color),
bg_color, bg_color,
icon, icon,
title: title.map(Child::new), title: title.map(|title| Child::new(title.vertically_aligned(Alignment::Center))),
message: Child::new(msg), message: Child::new(msg),
alert: alert.map(Child::new), alert: alert.map(Child::new),
left_button: Child::new(left_button), left_button: Child::new(left_button),
right_button: Child::new(right_button), right_button: Child::new(right_button),
info: info.map(|(title, text)| ConfirmInfo { info: info.map(|(title, text)| ConfirmInfo {
title: Child::new(Label::new(title, Alignment::Start, TEXT_TITLE)), title: Child::new(
Label::new(title, Alignment::Start, TEXT_TITLE)
.vertically_aligned(Alignment::Center),
),
text: Child::new( text: Child::new(
Label::new(text, Alignment::Start, TEXT_FINGERPRINT) Label::new(text, Alignment::Start, TEXT_FINGERPRINT)
.with_vertical_align(Alignment::Center), .vertically_aligned(Alignment::Center),
), ),
info_button: Child::new( info_button: Child::new(
Button::with_icon(Icon::new(INFO32)) Button::with_icon(Icon::new(INFO32))
@ -156,34 +158,16 @@ impl<'a> Component for Confirm<'a> {
if let Some(title) = self.title.as_mut() { if let Some(title) = self.title.as_mut() {
title.place(TITLE_AREA); title.place(TITLE_AREA);
let title_height = title.inner().area().height();
title.place(Rect::new(
Point::new(
CONTENT_PADDING,
TITLE_AREA.center().y - (title_height / 2) - TITLE_Y_ADJUSTMENT,
),
Point::new(WIDTH - CONTENT_PADDING, BUTTON_AREA_START - CONTENT_PADDING),
));
} }
if let Some(info) = self.info.as_mut() { if let Some(info) = self.info.as_mut() {
info.info_button.place(CORNER_BUTTON_AREA); info.info_button.place(CORNER_BUTTON_AREA);
info.close_button.place(CORNER_BUTTON_AREA); info.close_button.place(CORNER_BUTTON_AREA);
info.title.place(TITLE_AREA);
info.text.place(Rect::new( info.text.place(Rect::new(
Point::new(CONTENT_PADDING, TITLE_AREA.y1), Point::new(CONTENT_PADDING, TITLE_AREA.y1),
Point::new(WIDTH - CONTENT_PADDING, BUTTON_AREA_START), Point::new(WIDTH - CONTENT_PADDING, BUTTON_AREA_START),
)); ));
info.title.place(TITLE_AREA);
let title_height = info.title.inner().area().height();
info.title.place(Rect::new(
Point::new(
CONTENT_PADDING,
TITLE_AREA.center().y - (title_height / 2) - TITLE_Y_ADJUSTMENT,
),
Point::new(WIDTH - CONTENT_PADDING, BUTTON_AREA_START - CONTENT_PADDING),
));
} }
bounds bounds
} }

View File

@ -6,7 +6,7 @@ use crate::ui::{
model_tt::{ model_tt::{
bootloader::theme::{ bootloader::theme::{
button_bld, button_bld_menu, BLD_BG, BUTTON_AREA_START, BUTTON_HEIGHT, CONTENT_PADDING, button_bld, button_bld_menu, BLD_BG, BUTTON_AREA_START, BUTTON_HEIGHT, CONTENT_PADDING,
CORNER_BUTTON_AREA, MENU32, TEXT_NORMAL, TEXT_TITLE, TITLE_AREA, TITLE_Y_ADJUSTMENT, CORNER_BUTTON_AREA, MENU32, TEXT_NORMAL, TEXT_TITLE, TITLE_AREA,
}, },
component::{Button, ButtonMsg::Clicked}, component::{Button, ButtonMsg::Clicked},
constant::WIDTH, constant::WIDTH,
@ -32,7 +32,10 @@ impl<'a> Intro<'a> {
pub fn new(title: &'a str, content: &'a str) -> Self { pub fn new(title: &'a str, content: &'a str) -> Self {
Self { Self {
bg: Pad::with_background(BLD_BG).with_clear(), bg: Pad::with_background(BLD_BG).with_clear(),
title: Child::new(Label::new(title, Alignment::Start, TEXT_TITLE)), title: Child::new(
Label::new(title, Alignment::Start, TEXT_TITLE)
.vertically_aligned(Alignment::Center),
),
menu: Child::new( menu: Child::new(
Button::with_icon(Icon::new(MENU32)) Button::with_icon(Icon::new(MENU32))
.styled(button_bld_menu()) .styled(button_bld_menu())
@ -41,7 +44,7 @@ impl<'a> Intro<'a> {
host: Child::new(Button::with_text("INSTALL FIRMWARE").styled(button_bld())), host: Child::new(Button::with_text("INSTALL FIRMWARE").styled(button_bld())),
text: Child::new( text: Child::new(
Label::new(content, Alignment::Start, TEXT_NORMAL) Label::new(content, Alignment::Start, TEXT_NORMAL)
.with_vertical_align(Alignment::Center), .vertically_aligned(Alignment::Center),
), ),
} }
} }
@ -54,15 +57,6 @@ impl<'a> Component for Intro<'a> {
self.bg.place(screen()); self.bg.place(screen());
self.title.place(TITLE_AREA); self.title.place(TITLE_AREA);
let title_height = self.title.inner().area().height();
self.title.place(Rect::new(
Point::new(
CONTENT_PADDING,
TITLE_AREA.center().y - (title_height / 2) - TITLE_Y_ADJUSTMENT,
),
Point::new(WIDTH - CONTENT_PADDING, BUTTON_AREA_START - CONTENT_PADDING),
));
self.menu.place(CORNER_BUTTON_AREA); self.menu.place(CORNER_BUTTON_AREA);
self.host.place(Rect::new( self.host.place(Rect::new(
Point::new(CONTENT_PADDING, BUTTON_AREA_START), Point::new(CONTENT_PADDING, BUTTON_AREA_START),

View File

@ -1,13 +1,13 @@
use crate::ui::{ use crate::ui::{
component::{Child, Component, Event, EventCtx, Label, Pad}, component::{Child, Component, Event, EventCtx, Label, Pad},
constant::{screen, HEIGHT, WIDTH}, constant::{screen, WIDTH},
display::Icon, display::Icon,
geometry::{Alignment, Insets, Point, Rect}, geometry::{Alignment, Insets, Point, Rect},
model_tt::{ model_tt::{
bootloader::theme::{ bootloader::theme::{
button_bld, button_bld_menu, BLD_BG, BUTTON_HEIGHT, CONTENT_PADDING, button_bld, button_bld_menu, BLD_BG, BUTTON_HEIGHT, CONTENT_PADDING,
CORNER_BUTTON_AREA, CORNER_BUTTON_TOUCH_EXPANSION, FIRE24, REFRESH24, TEXT_TITLE, CORNER_BUTTON_AREA, CORNER_BUTTON_TOUCH_EXPANSION, FIRE24, REFRESH24, TEXT_TITLE,
TITLE_AREA, TITLE_Y_ADJUSTMENT, X32, TITLE_AREA, X32,
}, },
component::{Button, ButtonMsg::Clicked, IconText}, component::{Button, ButtonMsg::Clicked, IconText},
}, },
@ -39,7 +39,10 @@ impl Menu {
let mut instance = Self { let mut instance = Self {
bg: Pad::with_background(BLD_BG), bg: Pad::with_background(BLD_BG),
title: Child::new(Label::new("BOOTLOADER", Alignment::Start, TEXT_TITLE)), title: Child::new(
Label::new("BOOTLOADER", Alignment::Start, TEXT_TITLE)
.vertically_aligned(Alignment::Center),
),
close: Child::new( close: Child::new(
Button::with_icon(Icon::new(X32)) Button::with_icon(Icon::new(X32))
.styled(button_bld_menu()) .styled(button_bld_menu())
@ -59,14 +62,6 @@ impl Component for Menu {
fn place(&mut self, bounds: Rect) -> Rect { fn place(&mut self, bounds: Rect) -> Rect {
self.bg.place(screen()); self.bg.place(screen());
self.title.place(TITLE_AREA); self.title.place(TITLE_AREA);
let title_height = self.title.inner().area().height();
self.title.place(Rect::new(
Point::new(
CONTENT_PADDING,
TITLE_AREA.center().y - (title_height / 2) - TITLE_Y_ADJUSTMENT,
),
Point::new(WIDTH - CONTENT_PADDING, HEIGHT),
));
self.close.place(CORNER_BUTTON_AREA); self.close.place(CORNER_BUTTON_AREA);
self.reboot.place(Rect::new( self.reboot.place(Rect::new(
Point::new(CONTENT_PADDING, BUTTON_AREA_START), Point::new(CONTENT_PADDING, BUTTON_AREA_START),

View File

@ -49,11 +49,8 @@ pub const CORNER_BUTTON_AREA: Rect = Rect::from_top_left_and_size(
), ),
Offset::uniform(CORNER_BUTTON_SIZE), Offset::uniform(CORNER_BUTTON_SIZE),
); );
pub const TITLE_AREA_HEIGHT: i16 = 16;
pub const TITLE_AREA_START_Y: i16 = 8;
pub const BUTTON_AREA_START: i16 = 184; pub const BUTTON_AREA_START: i16 = 184;
pub const BUTTON_HEIGHT: i16 = 50; pub const BUTTON_HEIGHT: i16 = 50;
pub const TITLE_Y_ADJUSTMENT: i16 = 3;
// BLD icons // BLD icons
pub const X24: &[u8] = include_res!("model_tt/res/x24.toif"); pub const X24: &[u8] = include_res!("model_tt/res/x24.toif");