mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 12:00:59 +00:00
refactor(core/rust): replace Label::new with alignment-specific constructor
[no changelog]
This commit is contained in:
parent
c04cd19c6c
commit
3f6a55cc3a
@ -36,8 +36,8 @@ where
|
||||
Self::new(text, Alignment::Center, style)
|
||||
}
|
||||
|
||||
pub fn vertically_aligned(mut self, align: Alignment) -> Self {
|
||||
self.vertical = align;
|
||||
pub fn vertically_centered(mut self) -> Self {
|
||||
self.vertical = Alignment::Center;
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,8 @@ impl<T: StringType + Clone> FormattedText<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vertically_aligned(mut self, align: Alignment) -> Self {
|
||||
self.vertical = align;
|
||||
pub fn vertically_centered(mut self) -> Self {
|
||||
self.vertical = Alignment::Center;
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::ui::{
|
||||
component::{Child, Component, Event, EventCtx, Label, Pad},
|
||||
geometry::{Alignment, Alignment2D, Rect},
|
||||
geometry::{Alignment2D, Rect},
|
||||
};
|
||||
|
||||
use super::{
|
||||
@ -38,18 +38,12 @@ 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::Center, TEXT_NORMAL)
|
||||
.vertically_aligned(Alignment::Center),
|
||||
),
|
||||
title: Child::new(Label::centered(title, TEXT_NORMAL).vertically_centered()),
|
||||
buttons: Child::new(ButtonController::new(ButtonLayout::text_none_text(
|
||||
LEFT_BUTTON_TEXT,
|
||||
RIGHT_BUTTON_TEXT,
|
||||
))),
|
||||
text: Child::new(
|
||||
Label::new(content, Alignment::Start, TEXT_NORMAL)
|
||||
.vertically_aligned(Alignment::Center),
|
||||
),
|
||||
text: Child::new(Label::left_aligned(content, TEXT_NORMAL).vertically_centered()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use crate::{
|
||||
constant::SCREEN,
|
||||
display::{self, Color, Font, Icon},
|
||||
event::ButtonEvent,
|
||||
geometry::{Alignment, Alignment::Center, Alignment2D, Offset, Rect},
|
||||
geometry::{Alignment2D, Offset, Rect},
|
||||
util::{from_c_array, from_c_str},
|
||||
},
|
||||
};
|
||||
@ -137,18 +137,16 @@ extern "C" fn screen_install_confirm(
|
||||
"DOWNGRADE FW"
|
||||
};
|
||||
|
||||
let message = Label::new(version_str.as_str(), Alignment::Start, theme::TEXT_NORMAL)
|
||||
.vertically_aligned(Center);
|
||||
let fingerprint = Label::new(
|
||||
let message =
|
||||
Label::left_aligned(version_str.as_str(), theme::TEXT_NORMAL).vertically_centered();
|
||||
let fingerprint = Label::left_aligned(
|
||||
fingerprint_str,
|
||||
Alignment::Start,
|
||||
theme::TEXT_NORMAL.with_line_breaking(BreakWordsNoHyphen),
|
||||
)
|
||||
.vertically_aligned(Center);
|
||||
.vertically_centered();
|
||||
|
||||
let alert = (!should_keep_seed).then_some(Label::new(
|
||||
let alert = (!should_keep_seed).then_some(Label::left_aligned(
|
||||
"Seed will be erased!",
|
||||
Alignment::Start,
|
||||
theme::TEXT_NORMAL,
|
||||
));
|
||||
|
||||
@ -159,12 +157,8 @@ extern "C" fn screen_install_confirm(
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn screen_wipe_confirm() -> u32 {
|
||||
let message = Label::new(
|
||||
"Seed and firmware will be erased!",
|
||||
Alignment::Start,
|
||||
theme::TEXT_NORMAL,
|
||||
)
|
||||
.vertically_aligned(Center);
|
||||
let message = Label::left_aligned("Seed and firmware will be erased!", theme::TEXT_NORMAL)
|
||||
.vertically_centered();
|
||||
|
||||
let mut frame = Confirm::new(BLD_BG, "FACTORY RESET", message, None, "RESET");
|
||||
|
||||
@ -278,15 +272,10 @@ extern "C" fn screen_connect() {
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn screen_wipe_success() {
|
||||
let title = Label::new("Trezor Reset", Alignment::Center, theme::TEXT_BOLD)
|
||||
.vertically_aligned(Alignment::Center);
|
||||
let title = Label::centered("Trezor Reset", theme::TEXT_BOLD).vertically_centered();
|
||||
|
||||
let content = Label::new(
|
||||
"Reconnect\nthe device",
|
||||
Alignment::Center,
|
||||
theme::TEXT_NORMAL,
|
||||
)
|
||||
.vertically_aligned(Alignment::Center);
|
||||
let content =
|
||||
Label::centered("Reconnect\nthe device", theme::TEXT_NORMAL).vertically_centered();
|
||||
|
||||
let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_SPINNER, title, content, true);
|
||||
show(&mut frame);
|
||||
@ -294,15 +283,10 @@ extern "C" fn screen_wipe_success() {
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn screen_wipe_fail() {
|
||||
let title = Label::new("Reset failed", Alignment::Center, theme::TEXT_BOLD)
|
||||
.vertically_aligned(Alignment::Center);
|
||||
let title = Label::centered("Reset failed", theme::TEXT_BOLD).vertically_centered();
|
||||
|
||||
let content = Label::new(
|
||||
"Please reconnect\nthe device",
|
||||
Alignment::Center,
|
||||
theme::TEXT_NORMAL,
|
||||
)
|
||||
.vertically_aligned(Alignment::Center);
|
||||
let content =
|
||||
Label::centered("Please reconnect\nthe device", theme::TEXT_NORMAL).vertically_centered();
|
||||
|
||||
let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_ALERT, title, content, true);
|
||||
show(&mut frame);
|
||||
@ -325,15 +309,10 @@ extern "C" fn screen_boot_empty(_firmware_present: bool) {
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn screen_install_fail() {
|
||||
let title = Label::new("Install failed", Alignment::Center, theme::TEXT_BOLD)
|
||||
.vertically_aligned(Alignment::Center);
|
||||
let title = Label::centered("Install failed", theme::TEXT_BOLD).vertically_centered();
|
||||
|
||||
let content = Label::new(
|
||||
"Please reconnect\nthe device",
|
||||
Alignment::Center,
|
||||
theme::TEXT_NORMAL,
|
||||
)
|
||||
.vertically_aligned(Alignment::Center);
|
||||
let content =
|
||||
Label::centered("Please reconnect\nthe device", theme::TEXT_NORMAL).vertically_centered();
|
||||
|
||||
let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_ALERT, title, content, true);
|
||||
show(&mut frame);
|
||||
@ -347,11 +326,9 @@ extern "C" fn screen_install_success(
|
||||
) {
|
||||
let msg = unwrap!(unsafe { from_c_str(reboot_msg) });
|
||||
|
||||
let title = Label::new("Firmware installed", Alignment::Center, theme::TEXT_BOLD)
|
||||
.vertically_aligned(Alignment::Center);
|
||||
let title = Label::centered("Firmware installed", theme::TEXT_BOLD).vertically_centered();
|
||||
|
||||
let content = Label::new(msg, Alignment::Center, theme::TEXT_NORMAL)
|
||||
.vertically_aligned(Alignment::Center);
|
||||
let content = Label::centered(msg, theme::TEXT_NORMAL).vertically_centered();
|
||||
|
||||
let mut frame = ResultScreen::new(BLD_FG, BLD_BG, ICON_SPINNER, title, content, complete_draw);
|
||||
show(&mut frame);
|
||||
|
@ -2,7 +2,7 @@ use crate::ui::{
|
||||
component::{Child, Component, Event, EventCtx, Label, Never, Pad},
|
||||
constant::screen,
|
||||
display,
|
||||
geometry::{Alignment::Center, Alignment2D, Offset, Point, Rect},
|
||||
geometry::{Alignment2D, Offset, Point, Rect},
|
||||
};
|
||||
|
||||
use super::super::{
|
||||
@ -25,9 +25,9 @@ pub struct ErrorScreen<T> {
|
||||
|
||||
impl<T: AsRef<str>> ErrorScreen<T> {
|
||||
pub fn new(title: T, message: T, footer: T) -> Self {
|
||||
let title = Label::new(title, Center, theme::TEXT_BOLD);
|
||||
let message = Label::new(message, Center, theme::TEXT_NORMAL).vertically_aligned(Center);
|
||||
let footer = Label::new(footer, Center, theme::TEXT_NORMAL).vertically_aligned(Center);
|
||||
let title = Label::centered(title, theme::TEXT_BOLD);
|
||||
let message = Label::centered(message, theme::TEXT_NORMAL).vertically_centered();
|
||||
let footer = Label::centered(footer, theme::TEXT_NORMAL).vertically_centered();
|
||||
|
||||
Self {
|
||||
bg: Pad::with_background(BG).with_clear(),
|
||||
|
@ -8,7 +8,7 @@ use crate::{
|
||||
},
|
||||
constant::screen,
|
||||
display::toif::Icon,
|
||||
geometry::{Alignment, Insets, LinearPlacement, Rect},
|
||||
geometry::{Insets, LinearPlacement, Rect},
|
||||
},
|
||||
};
|
||||
|
||||
@ -65,7 +65,7 @@ where
|
||||
area: Rect::zero(),
|
||||
pad,
|
||||
result_anim: Child::new(ResultAnim::new(icon)),
|
||||
headline: headline.map(|a| Label::new(a, Alignment::Center, theme::TEXT_BOLD)),
|
||||
headline: headline.map(|a| Label::centered(a, theme::TEXT_BOLD)),
|
||||
text: Child::new(p1),
|
||||
buttons,
|
||||
autoclose: false,
|
||||
|
@ -549,8 +549,7 @@ extern "C" fn new_confirm_output(n_args: usize, args: *const Obj, kwargs: *mut M
|
||||
ops = ops.text_normal(address_label.clone()).newline();
|
||||
}
|
||||
ops = ops.text_mono(address.clone());
|
||||
let formatted =
|
||||
FormattedText::new(ops).vertically_aligned(geometry::Alignment::Center);
|
||||
let formatted = FormattedText::new(ops).vertically_centered();
|
||||
Page::new(btn_layout, btn_actions, formatted).with_title(address_title.clone())
|
||||
}
|
||||
1 => {
|
||||
@ -558,8 +557,7 @@ extern "C" fn new_confirm_output(n_args: usize, args: *const Obj, kwargs: *mut M
|
||||
let btn_layout = ButtonLayout::up_arrow_none_text("CONFIRM".into());
|
||||
let btn_actions = ButtonActions::prev_none_confirm();
|
||||
let ops = OpTextLayout::new(theme::TEXT_MONO).text_mono(amount.clone());
|
||||
let formatted =
|
||||
FormattedText::new(ops).vertically_aligned(geometry::Alignment::Center);
|
||||
let formatted = FormattedText::new(ops).vertically_centered();
|
||||
Page::new(btn_layout, btn_actions, formatted).with_title(amount_title.clone())
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
@ -3,7 +3,7 @@ use crate::ui::{
|
||||
constant,
|
||||
constant::screen,
|
||||
display::{Color, Icon},
|
||||
geometry::{Alignment, Alignment2D, Insets, Offset, Point, Rect},
|
||||
geometry::{Alignment2D, Insets, Offset, Point, Rect},
|
||||
model_tt::{
|
||||
bootloader::theme::{
|
||||
button_bld_menu, BUTTON_AREA_START, BUTTON_HEIGHT, CONTENT_PADDING, CORNER_BUTTON_AREA,
|
||||
@ -69,19 +69,13 @@ impl<'a> Confirm<'a> {
|
||||
content_pad: Pad::with_background(bg_color),
|
||||
bg_color,
|
||||
title,
|
||||
message: Child::new(message.vertically_aligned(Alignment::Center)),
|
||||
alert: alert.map(|alert| Child::new(alert.vertically_aligned(Alignment::Center))),
|
||||
message: Child::new(message.vertically_centered()),
|
||||
alert: alert.map(|alert| Child::new(alert.vertically_centered())),
|
||||
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)
|
||||
.vertically_aligned(Alignment::Center),
|
||||
),
|
||||
text: Child::new(
|
||||
Label::new(text, Alignment::Start, TEXT_FINGERPRINT)
|
||||
.vertically_aligned(Alignment::Center),
|
||||
),
|
||||
title: Child::new(Label::left_aligned(title, TEXT_TITLE).vertically_centered()),
|
||||
text: Child::new(Label::left_aligned(text, TEXT_FINGERPRINT).vertically_centered()),
|
||||
info_button: Child::new(
|
||||
Button::with_icon(Icon::new(INFO32))
|
||||
.styled(button_bld_menu())
|
||||
|
@ -2,7 +2,7 @@ use crate::ui::{
|
||||
component::{Child, Component, Event, EventCtx, Label, Pad},
|
||||
constant::screen,
|
||||
display::Icon,
|
||||
geometry::{Alignment, Insets, Point, Rect},
|
||||
geometry::{Insets, Point, Rect},
|
||||
model_tt::{
|
||||
bootloader::theme::{
|
||||
button_bld, button_bld_menu, BLD_BG, BUTTON_AREA_START, BUTTON_HEIGHT, CONTENT_PADDING,
|
||||
@ -32,20 +32,14 @@ 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)
|
||||
.vertically_aligned(Alignment::Center),
|
||||
),
|
||||
title: Child::new(Label::left_aligned(title, TEXT_TITLE).vertically_centered()),
|
||||
menu: Child::new(
|
||||
Button::with_icon(Icon::new(MENU32))
|
||||
.styled(button_bld_menu())
|
||||
.with_expanded_touch_area(Insets::uniform(13)),
|
||||
),
|
||||
host: Child::new(Button::with_text("INSTALL FIRMWARE").styled(button_bld())),
|
||||
text: Child::new(
|
||||
Label::new(content, Alignment::Start, TEXT_NORMAL)
|
||||
.vertically_aligned(Alignment::Center),
|
||||
),
|
||||
text: Child::new(Label::left_aligned(content, TEXT_NORMAL).vertically_centered()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use crate::ui::{
|
||||
component::{Child, Component, Event, EventCtx, Label, Pad},
|
||||
constant::{screen, WIDTH},
|
||||
display::Icon,
|
||||
geometry::{Alignment, Insets, Point, Rect},
|
||||
geometry::{Insets, Point, Rect},
|
||||
model_tt::{
|
||||
bootloader::theme::{
|
||||
button_bld, button_bld_menu, BLD_BG, BUTTON_HEIGHT, CONTENT_PADDING,
|
||||
@ -39,10 +39,7 @@ impl Menu {
|
||||
|
||||
let mut instance = Self {
|
||||
bg: Pad::with_background(BLD_BG),
|
||||
title: Child::new(
|
||||
Label::new("BOOTLOADER", Alignment::Start, TEXT_TITLE)
|
||||
.vertically_aligned(Alignment::Center),
|
||||
),
|
||||
title: Child::new(Label::left_aligned("BOOTLOADER", TEXT_TITLE).vertically_centered()),
|
||||
close: Child::new(
|
||||
Button::with_icon(Icon::new(X32))
|
||||
.styled(button_bld_menu())
|
||||
|
@ -6,7 +6,7 @@ use crate::{
|
||||
constant::{screen, HEIGHT},
|
||||
display::{self, Color, Font, Icon},
|
||||
event::TouchEvent,
|
||||
geometry::{Alignment, Alignment2D, Point},
|
||||
geometry::{Alignment2D, Point},
|
||||
model_tt::{
|
||||
bootloader::{
|
||||
confirm::ConfirmTitle,
|
||||
@ -162,12 +162,10 @@ extern "C" fn screen_install_confirm(
|
||||
} else {
|
||||
"DOWNGRADE FW"
|
||||
};
|
||||
let title = Label::new(title_str, Alignment::Start, theme::TEXT_BOLD)
|
||||
.vertically_aligned(Alignment::Center);
|
||||
let msg = Label::new(version_str.as_ref(), Alignment::Start, theme::TEXT_NORMAL);
|
||||
let alert = (!should_keep_seed).then_some(Label::new(
|
||||
let title = Label::left_aligned(title_str, theme::TEXT_BOLD).vertically_centered();
|
||||
let msg = Label::left_aligned(version_str.as_ref(), theme::TEXT_NORMAL);
|
||||
let alert = (!should_keep_seed).then_some(Label::left_aligned(
|
||||
"SEED WILL BE ERASED!",
|
||||
Alignment::Start,
|
||||
theme::TEXT_BOLD,
|
||||
));
|
||||
|
||||
@ -198,16 +196,11 @@ extern "C" fn screen_install_confirm(
|
||||
extern "C" fn screen_wipe_confirm() -> u32 {
|
||||
let icon = Icon::new(FIRE40);
|
||||
|
||||
let msg = Label::new(
|
||||
let msg = Label::centered(
|
||||
"Are you sure you want to factory reset the device?",
|
||||
Alignment::Center,
|
||||
TEXT_WIPE_NORMAL,
|
||||
);
|
||||
let alert = Label::new(
|
||||
"SEED AND FIRMWARE\nWILL BE ERASED!",
|
||||
Alignment::Center,
|
||||
TEXT_WIPE_BOLD,
|
||||
);
|
||||
let alert = Label::centered("SEED AND FIRMWARE\nWILL BE ERASED!", TEXT_WIPE_BOLD);
|
||||
|
||||
let right = Button::with_text("RESET").styled(button_wipe_confirm());
|
||||
let left = Button::with_text("CANCEL").styled(button_wipe_cancel());
|
||||
|
@ -8,7 +8,7 @@ use crate::{
|
||||
Split,
|
||||
},
|
||||
display::loader::{loader_circular_uncompress, LoaderDimensions},
|
||||
geometry::{Alignment, Insets, Rect},
|
||||
geometry::{Insets, Rect},
|
||||
util::animation_disabled,
|
||||
},
|
||||
};
|
||||
@ -43,8 +43,7 @@ where
|
||||
T: AsRef<str>,
|
||||
{
|
||||
let style = theme::label_coinjoin_progress();
|
||||
let label = Label::centered("DO NOT DISCONNECT YOUR TREZOR!", style)
|
||||
.vertically_aligned(Alignment::Center);
|
||||
let label = Label::centered("DO NOT DISCONNECT YOUR TREZOR!", style).vertically_centered();
|
||||
let bg = painter::rect_painter(style.background_color, theme::BG);
|
||||
let inner = (bg, label);
|
||||
CoinJoinProgress::with_background(text, inner, indeterminate)
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::ui::{
|
||||
component::{Child, Component, Event, EventCtx, Label, Never, Pad},
|
||||
constant::screen,
|
||||
geometry::{Alignment::Center, Alignment2D, Point, Rect},
|
||||
geometry::{Alignment2D, Point, Rect},
|
||||
};
|
||||
|
||||
use crate::ui::model_tt::{
|
||||
@ -28,8 +28,8 @@ pub struct ErrorScreen<'a, T> {
|
||||
|
||||
impl<T: AsRef<str>> ErrorScreen<'_, T> {
|
||||
pub fn new(title: T, message: T, footer: T) -> Self {
|
||||
let title = Label::new(title, Center, STYLE.title_style());
|
||||
let message = Label::new(message, Center, STYLE.message_style());
|
||||
let title = Label::centered(title, STYLE.title_style());
|
||||
let message = Label::centered(message, STYLE.message_style());
|
||||
let footer = ResultFooter::new(footer, STYLE);
|
||||
|
||||
Self {
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::ui::{
|
||||
component::{image::Image, Child, Component, Event, EventCtx, Label},
|
||||
display,
|
||||
geometry::{Alignment, Insets, Rect},
|
||||
geometry::{Insets, Rect},
|
||||
model_tt::component::{
|
||||
fido_icons::get_fido_icon_data,
|
||||
swipe::{Swipe, SwipeDirection},
|
||||
@ -60,8 +60,8 @@ where
|
||||
page_swipe.allow_left = scrollbar.has_next_page();
|
||||
|
||||
Self {
|
||||
app_name: Label::new(app_name, Alignment::Center, theme::TEXT_DEMIBOLD),
|
||||
account_name: Label::new("".into(), Alignment::Center, theme::TEXT_DEMIBOLD),
|
||||
app_name: Label::centered(app_name, theme::TEXT_DEMIBOLD),
|
||||
account_name: Label::centered("".into(), theme::TEXT_DEMIBOLD),
|
||||
page_swipe,
|
||||
icon: Child::new(Image::new(icon_data)),
|
||||
get_account,
|
||||
|
@ -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, Alignment2D, Insets, Offset, Point, Rect},
|
||||
geometry::{Alignment2D, Insets, Offset, Point, Rect},
|
||||
model_tt::theme::FG,
|
||||
},
|
||||
};
|
||||
@ -51,7 +51,7 @@ impl<'a, T: AsRef<str>> ResultFooter<'a, T> {
|
||||
pub fn new(text: T, style: &'a ResultStyle) -> Self {
|
||||
Self {
|
||||
style,
|
||||
text: Label::new(text, Center, style.title_style()).vertically_aligned(Center),
|
||||
text: Label::centered(text, style.title_style()).vertically_centered(),
|
||||
area: Rect::zero(),
|
||||
}
|
||||
}
|
||||
@ -117,7 +117,7 @@ impl<'a, T: StringType> ResultScreen<'a, T> {
|
||||
footer_pad: Pad::with_background(style.bg_color),
|
||||
style,
|
||||
icon,
|
||||
message: Child::new(Label::new(message, Center, style.message_style())),
|
||||
message: Child::new(Label::centered(message, style.message_style())),
|
||||
footer: Child::new(ResultFooter::new(footer, style)),
|
||||
};
|
||||
|
||||
|
@ -486,7 +486,7 @@ extern "C" fn new_confirm_emphasized(n_args: usize, args: *const Obj, kwargs: *m
|
||||
theme::label_title(),
|
||||
title,
|
||||
SwipePage::new(
|
||||
FormattedText::new(ops).vertically_aligned(geometry::Alignment::Center),
|
||||
FormattedText::new(ops).vertically_centered(),
|
||||
buttons,
|
||||
theme::BG,
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user