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:
parent
c3af3eafe2
commit
a9a18bf80d
@ -7,8 +7,7 @@ use crate::ui::{
|
||||
model_tt::{
|
||||
bootloader::theme::{
|
||||
button_bld_menu, BUTTON_AREA_START, BUTTON_HEIGHT, CONTENT_PADDING, CORNER_BUTTON_AREA,
|
||||
CORNER_BUTTON_TOUCH_EXPANSION, INFO32, TEXT_FINGERPRINT, TEXT_TITLE, TITLE_AREA,
|
||||
TITLE_Y_ADJUSTMENT, X32,
|
||||
CORNER_BUTTON_TOUCH_EXPANSION, INFO32, TEXT_FINGERPRINT, TEXT_TITLE, TITLE_AREA, X32,
|
||||
},
|
||||
component::{Button, ButtonMsg::Clicked},
|
||||
constant::WIDTH,
|
||||
@ -64,16 +63,19 @@ impl<'a> Confirm<'a> {
|
||||
content_pad: Pad::with_background(bg_color),
|
||||
bg_color,
|
||||
icon,
|
||||
title: title.map(Child::new),
|
||||
title: title.map(|title| Child::new(title.vertically_aligned(Alignment::Center))),
|
||||
message: Child::new(msg),
|
||||
alert: alert.map(Child::new),
|
||||
left_button: Child::new(left_button),
|
||||
right_button: Child::new(right_button),
|
||||
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(
|
||||
Label::new(text, Alignment::Start, TEXT_FINGERPRINT)
|
||||
.with_vertical_align(Alignment::Center),
|
||||
.vertically_aligned(Alignment::Center),
|
||||
),
|
||||
info_button: Child::new(
|
||||
Button::with_icon(Icon::new(INFO32))
|
||||
@ -156,34 +158,16 @@ impl<'a> Component for Confirm<'a> {
|
||||
|
||||
if let Some(title) = self.title.as_mut() {
|
||||
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() {
|
||||
info.info_button.place(CORNER_BUTTON_AREA);
|
||||
info.close_button.place(CORNER_BUTTON_AREA);
|
||||
info.title.place(TITLE_AREA);
|
||||
info.text.place(Rect::new(
|
||||
Point::new(CONTENT_PADDING, TITLE_AREA.y1),
|
||||
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
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use crate::ui::{
|
||||
model_tt::{
|
||||
bootloader::theme::{
|
||||
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},
|
||||
constant::WIDTH,
|
||||
@ -32,7 +32,10 @@ impl<'a> Intro<'a> {
|
||||
pub fn new(title: &'a str, content: &'a str) -> Self {
|
||||
Self {
|
||||
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(
|
||||
Button::with_icon(Icon::new(MENU32))
|
||||
.styled(button_bld_menu())
|
||||
@ -41,7 +44,7 @@ impl<'a> Intro<'a> {
|
||||
host: Child::new(Button::with_text("INSTALL FIRMWARE").styled(button_bld())),
|
||||
text: Child::new(
|
||||
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.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.host.place(Rect::new(
|
||||
Point::new(CONTENT_PADDING, BUTTON_AREA_START),
|
||||
|
@ -1,13 +1,13 @@
|
||||
use crate::ui::{
|
||||
component::{Child, Component, Event, EventCtx, Label, Pad},
|
||||
constant::{screen, HEIGHT, WIDTH},
|
||||
constant::{screen, WIDTH},
|
||||
display::Icon,
|
||||
geometry::{Alignment, Insets, Point, Rect},
|
||||
model_tt::{
|
||||
bootloader::theme::{
|
||||
button_bld, button_bld_menu, BLD_BG, BUTTON_HEIGHT, CONTENT_PADDING,
|
||||
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},
|
||||
},
|
||||
@ -39,7 +39,10 @@ impl Menu {
|
||||
|
||||
let mut instance = Self {
|
||||
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(
|
||||
Button::with_icon(Icon::new(X32))
|
||||
.styled(button_bld_menu())
|
||||
@ -59,14 +62,6 @@ impl Component for Menu {
|
||||
fn place(&mut self, bounds: Rect) -> Rect {
|
||||
self.bg.place(screen());
|
||||
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.reboot.place(Rect::new(
|
||||
Point::new(CONTENT_PADDING, BUTTON_AREA_START),
|
||||
|
@ -49,11 +49,8 @@ pub const CORNER_BUTTON_AREA: Rect = Rect::from_top_left_and_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_HEIGHT: i16 = 50;
|
||||
pub const TITLE_Y_ADJUSTMENT: i16 = 3;
|
||||
|
||||
// BLD icons
|
||||
pub const X24: &[u8] = include_res!("model_tt/res/x24.toif");
|
||||
|
Loading…
Reference in New Issue
Block a user