1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-05 12:21:16 +00:00

fix(core/rust/ui): polish confirm_fido

[no changelog]
This commit is contained in:
Martin Milata 2022-12-14 14:46:50 +01:00
parent 550e2a7951
commit bdec3f3979
4 changed files with 85 additions and 44 deletions

View File

@ -1,15 +1,14 @@
use super::theme; use super::theme;
use crate::ui::{ use crate::ui::{
component::{text::TextStyle, Child, Component, Event, EventCtx}, component::{label::Label, text::TextStyle, Child, Component, Event, EventCtx},
display::{self, Color, Font}, display::{self, Color, Font},
geometry::{Insets, Offset, Rect}, geometry::{Alignment, Insets, Offset, Rect},
util::icon_text_center, util::icon_text_center,
}; };
pub struct Frame<T, U> { pub struct Frame<T, U> {
area: Rect,
border: Insets, border: Insets,
title: U, title: Child<Label<U>>,
content: Child<T>, content: Child<T>,
} }
@ -18,15 +17,26 @@ where
T: Component, T: Component,
U: AsRef<str>, U: AsRef<str>,
{ {
pub fn new(title: U, content: T) -> Self { pub fn new(style: TextStyle, alignment: Alignment, title: U, content: T) -> Self {
Self { Self {
title, title: Child::new(Label::new(title, alignment, style)),
area: Rect::zero(),
border: theme::borders_scroll(), border: theme::borders_scroll(),
content: Child::new(content), content: Child::new(content),
} }
} }
pub fn left_aligned(style: TextStyle, title: U, content: T) -> Self {
Self::new(style, Alignment::Start, title, content)
}
pub fn right_aligned(style: TextStyle, title: U, content: T) -> Self {
Self::new(style, Alignment::End, title, content)
}
pub fn centered(style: TextStyle, title: U, content: T) -> Self {
Self::new(style, Alignment::Center, title, content)
}
pub fn with_border(mut self, border: Insets) -> Self { pub fn with_border(mut self, border: Insets) -> Self {
self.border = border; self.border = border;
self self
@ -50,31 +60,26 @@ where
let (title_area, content_area) = bounds let (title_area, content_area) = bounds
.inset(self.border) .inset(self.border)
.split_top(Font::BOLD.text_height()); .split_top(Font::BOLD.text_height());
let title_area = title_area.inset(Insets::left(theme::CONTENT_BORDER)); let title_area = title_area.inset(Insets::sides(theme::CONTENT_BORDER));
let content_area = content_area.inset(Insets::top(TITLE_SPACE)); let content_area = content_area.inset(Insets::top(TITLE_SPACE));
self.area = title_area; self.title.place(title_area);
self.content.place(content_area); self.content.place(content_area);
bounds bounds
} }
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> { fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
self.title.event(ctx, event);
self.content.event(ctx, event) self.content.event(ctx, event)
} }
fn paint(&mut self) { fn paint(&mut self) {
display::text( self.title.paint();
self.area.bottom_left(),
self.title.as_ref(),
Font::BOLD,
theme::GREY_LIGHT,
theme::BG,
);
self.content.paint(); self.content.paint();
} }
fn bounds(&self, sink: &mut dyn FnMut(Rect)) { fn bounds(&self, sink: &mut dyn FnMut(Rect)) {
sink(self.area); self.title.bounds(sink);
self.content.bounds(sink); self.content.bounds(sink);
} }
} }

View File

@ -354,10 +354,11 @@ extern "C" fn new_confirm_action(n_args: usize, args: *const Obj, kwargs: *mut M
} else { } else {
SwipeHoldPage::new(paragraphs, theme::BG) SwipeHoldPage::new(paragraphs, theme::BG)
}; };
LayoutObj::new(Frame::new(title, page))? LayoutObj::new(Frame::left_aligned(theme::label_title(), title, page))?
} else { } else {
let buttons = Button::cancel_confirm_text(verb_cancel, verb); let buttons = Button::cancel_confirm_text(verb_cancel, verb);
LayoutObj::new(Frame::new( LayoutObj::new(Frame::left_aligned(
theme::label_title(),
title, title,
SwipePage::new(paragraphs, buttons, theme::BG), SwipePage::new(paragraphs, buttons, theme::BG),
))? ))?
@ -387,10 +388,15 @@ fn confirm_blob(
.into_paragraphs(); .into_paragraphs();
let obj = if hold { let obj = if hold {
LayoutObj::new(Frame::new(title, SwipeHoldPage::new(paragraphs, theme::BG)))? LayoutObj::new(Frame::left_aligned(
theme::label_title(),
title,
SwipeHoldPage::new(paragraphs, theme::BG),
))?
} else if let Some(verb) = verb { } else if let Some(verb) = verb {
let buttons = Button::cancel_confirm_text(verb_cancel, verb); let buttons = Button::cancel_confirm_text(verb_cancel, verb);
LayoutObj::new(Frame::new( LayoutObj::new(Frame::left_aligned(
theme::label_title(),
title, title,
SwipePage::new(paragraphs, buttons, theme::BG), SwipePage::new(paragraphs, buttons, theme::BG),
))? ))?
@ -441,13 +447,15 @@ extern "C" fn new_confirm_properties(n_args: usize, args: *const Obj, kwargs: *m
&theme::TEXT_MONO, &theme::TEXT_MONO,
)?; )?;
let obj = if hold { let obj = if hold {
LayoutObj::new(Frame::new( LayoutObj::new(Frame::left_aligned(
theme::label_title(),
title, title,
SwipeHoldPage::new(paragraphs.into_paragraphs(), theme::BG), SwipeHoldPage::new(paragraphs.into_paragraphs(), theme::BG),
))? ))?
} else { } else {
let buttons = Button::cancel_confirm_text(None, "CONFIRM"); let buttons = Button::cancel_confirm_text(None, "CONFIRM");
LayoutObj::new(Frame::new( LayoutObj::new(Frame::left_aligned(
theme::label_title(),
title, title,
SwipePage::new(paragraphs.into_paragraphs(), buttons, theme::BG), SwipePage::new(paragraphs.into_paragraphs(), buttons, theme::BG),
))? ))?
@ -471,7 +479,8 @@ extern "C" fn new_confirm_reset_device(n_args: usize, args: *const Obj, kwargs:
]); ]);
let buttons = Button::cancel_confirm_text(None, "CONTINUE"); let buttons = Button::cancel_confirm_text(None, "CONTINUE");
let obj = LayoutObj::new(Frame::new( let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
title, title,
SwipePage::new(paragraphs, buttons, theme::BG), SwipePage::new(paragraphs, buttons, theme::BG),
))?; ))?;
@ -494,7 +503,8 @@ extern "C" fn new_show_qr(n_args: usize, args: *const Obj, kwargs: *mut Map) ->
); );
let obj = LayoutObj::new( let obj = LayoutObj::new(
Frame::new( Frame::left_aligned(
theme::label_title(),
title, title,
Dialog::new( Dialog::new(
painter::qrcode_painter(address, theme::QR_SIDE_MAX, case_sensitive), painter::qrcode_painter(address, theme::QR_SIDE_MAX, case_sensitive),
@ -538,7 +548,8 @@ extern "C" fn new_confirm_joint_total(n_args: usize, args: *const Obj, kwargs: *
Paragraph::new(&theme::TEXT_MONO, total_amount), Paragraph::new(&theme::TEXT_MONO, total_amount),
]); ]);
let obj = LayoutObj::new(Frame::new( let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
"JOINT TRANSACTION", "JOINT TRANSACTION",
SwipeHoldPage::new(paragraphs, theme::BG), SwipeHoldPage::new(paragraphs, theme::BG),
))?; ))?;
@ -575,7 +586,8 @@ extern "C" fn new_confirm_modify_output(n_args: usize, args: *const Obj, kwargs:
2, 2,
); );
let obj = LayoutObj::new(Frame::new( let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
"MODIFY AMOUNT", "MODIFY AMOUNT",
SwipePage::new(paragraphs, buttons, theme::BG), SwipePage::new(paragraphs, buttons, theme::BG),
))?; ))?;
@ -609,7 +621,8 @@ extern "C" fn new_confirm_modify_fee(n_args: usize, args: *const Obj, kwargs: *m
2, 2,
); );
let obj = LayoutObj::new(Frame::new( let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
"MODIFY FEE", "MODIFY FEE",
SwipePage::new(paragraphs, buttons, theme::BG), SwipePage::new(paragraphs, buttons, theme::BG),
))?; ))?;
@ -712,14 +725,16 @@ extern "C" fn new_confirm_fido(n_args: usize, args: *const Obj, kwargs: *mut Map
}; };
let controls = Button::cancel_confirm( let controls = Button::cancel_confirm(
Button::with_icon(theme::ICON_CANCEL).styled(theme::button_cancel()), Button::with_icon(theme::ICON_CANCEL),
Button::with_text("CONFIRM").styled(theme::button_confirm()), Button::with_text("CONFIRM").styled(theme::button_confirm()),
2, 2,
); );
let fido_page = FidoConfirm::new(app_name, get_page, page_count, icon, controls); let fido_page = FidoConfirm::new(app_name, get_page, page_count, icon, controls);
let obj = LayoutObj::new(Frame::new(title, fido_page).with_border(theme::borders()))?; let obj = LayoutObj::new(
Frame::centered(theme::label_title(), title, fido_page).with_border(theme::borders()),
)?;
Ok(obj.into()) Ok(obj.into())
}; };
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) } unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
@ -775,7 +790,8 @@ extern "C" fn new_show_simple(n_args: usize, args: *const Obj, kwargs: *mut Map)
let button: StrBuffer = kwargs.get(Qstr::MP_QSTR_button)?.try_into()?; let button: StrBuffer = kwargs.get(Qstr::MP_QSTR_button)?.try_into()?;
let obj = if let Some(t) = title { let obj = if let Some(t) = title {
LayoutObj::new(Frame::new( LayoutObj::new(Frame::left_aligned(
theme::label_title(),
t, t,
Dialog::new( Dialog::new(
Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, description)]), Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, description)]),
@ -827,8 +843,12 @@ extern "C" fn new_confirm_with_info(n_args: usize, args: *const Obj, kwargs: *mu
let buttons = Button::cancel_info_confirm(button, info_button); let buttons = Button::cancel_info_confirm(button, info_button);
let obj = LayoutObj::new( let obj = LayoutObj::new(
Frame::new(title, Dialog::new(paragraphs.into_paragraphs(), buttons)) Frame::left_aligned(
.with_border(theme::borders()), theme::label_title(),
title,
Dialog::new(paragraphs.into_paragraphs(), buttons),
)
.with_border(theme::borders()),
)?; )?;
Ok(obj.into()) Ok(obj.into())
}; };
@ -857,7 +877,8 @@ extern "C" fn new_confirm_more(n_args: usize, args: *const Obj, kwargs: *mut Map
(matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed) (matches!(msg, ButtonMsg::Clicked)).then(|| CancelConfirmMsg::Confirmed)
})); }));
let obj = LayoutObj::new(Frame::new( let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
title, title,
SwipePage::new(paragraphs.into_paragraphs(), button, theme::BG).with_back_button(), SwipePage::new(paragraphs.into_paragraphs(), button, theme::BG).with_back_button(),
))?; ))?;
@ -878,7 +899,8 @@ extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut
Paragraph::new(&theme::TEXT_BOLD, max_feerate), Paragraph::new(&theme::TEXT_BOLD, max_feerate),
]); ]);
let obj = LayoutObj::new(Frame::new( let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
"AUTHORIZE COINJOIN", "AUTHORIZE COINJOIN",
SwipeHoldPage::new(paragraphs, theme::BG), SwipeHoldPage::new(paragraphs, theme::BG),
))?; ))?;
@ -937,7 +959,8 @@ extern "C" fn new_select_word(n_args: usize, args: *const Obj, kwargs: *mut Map)
let paragraphs = Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, description)]); let paragraphs = Paragraphs::new([Paragraph::new(&theme::TEXT_NORMAL, description)]);
let buttons = Button::select_word(words); let buttons = Button::select_word(words);
let obj = LayoutObj::new(Frame::new( let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
title, title,
SwipePage::new(paragraphs, buttons, theme::BG), SwipePage::new(paragraphs, buttons, theme::BG),
))?; ))?;
@ -959,7 +982,8 @@ extern "C" fn new_show_share_words(n_args: usize, args: *const Obj, kwargs: *mut
paragraphs.add(Paragraph::new(&theme::TEXT_MONO, text).break_after()); paragraphs.add(Paragraph::new(&theme::TEXT_MONO, text).break_after());
} }
let obj = LayoutObj::new(Frame::new( let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
title, title,
SwipeHoldPage::without_cancel(paragraphs.into_paragraphs(), theme::BG), SwipeHoldPage::without_cancel(paragraphs.into_paragraphs(), theme::BG),
))?; ))?;
@ -986,7 +1010,8 @@ extern "C" fn new_request_number(n_args: usize, args: *const Obj, kwargs: *mut M
}; };
let obj = LayoutObj::new( let obj = LayoutObj::new(
Frame::new( Frame::left_aligned(
theme::label_title(),
title, title,
NumberInputDialog::new(min_count, max_count, count, callback), NumberInputDialog::new(min_count, max_count, count, callback),
) )
@ -1018,7 +1043,8 @@ extern "C" fn new_show_checklist(n_args: usize, args: *const Obj, kwargs: *mut M
} }
let obj = LayoutObj::new( let obj = LayoutObj::new(
Frame::new( Frame::left_aligned(
theme::label_title(),
title, title,
Dialog::new( Dialog::new(
Checklist::from_paragraphs( Checklist::from_paragraphs(
@ -1109,8 +1135,12 @@ extern "C" fn new_select_word_count(n_args: usize, args: *const Obj, kwargs: *mu
); );
let obj = LayoutObj::new( let obj = LayoutObj::new(
Frame::new(title, Dialog::new(paragraphs, SelectWordCount::new())) Frame::left_aligned(
.with_border(theme::borders()), theme::label_title(),
title,
Dialog::new(paragraphs, SelectWordCount::new()),
)
.with_border(theme::borders()),
)?; )?;
Ok(obj.into()) Ok(obj.into())
}; };
@ -1151,7 +1181,8 @@ extern "C" fn new_show_remaining_shares(n_args: usize, args: *const Obj, kwargs:
.add(Paragraph::new(&theme::TEXT_NORMAL, description).break_after()); .add(Paragraph::new(&theme::TEXT_NORMAL, description).break_after());
} }
let obj = LayoutObj::new(Frame::new( let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
"REMAINING SHARES", "REMAINING SHARES",
SwipePage::new( SwipePage::new(
paragraphs.into_paragraphs(), paragraphs.into_paragraphs(),
@ -1227,7 +1258,8 @@ extern "C" fn new_show_busyscreen(n_args: usize, args: *const Obj, kwargs: *mut
let time_ms: u32 = kwargs.get(Qstr::MP_QSTR_time_ms)?.try_into()?; let time_ms: u32 = kwargs.get(Qstr::MP_QSTR_time_ms)?.try_into()?;
let skip_first_paint: bool = kwargs.get(Qstr::MP_QSTR_skip_first_paint)?.try_into()?; let skip_first_paint: bool = kwargs.get(Qstr::MP_QSTR_skip_first_paint)?.try_into()?;
let obj = LayoutObj::new(Frame::new( let obj = LayoutObj::new(Frame::left_aligned(
theme::label_title(),
title, title,
Dialog::new( Dialog::new(
Paragraphs::new(Paragraph::new(&theme::TEXT_NORMAL, description).centered()), Paragraphs::new(Paragraph::new(&theme::TEXT_NORMAL, description).centered()),

View File

@ -125,6 +125,10 @@ pub const fn label_progress() -> TextStyle {
TEXT_BOLD TEXT_BOLD
} }
pub const fn label_title() -> TextStyle {
TextStyle::new(Font::BOLD, GREY_LIGHT, BG, GREY_LIGHT, GREY_LIGHT)
}
pub fn button_default() -> ButtonStyleSheet { pub fn button_default() -> ButtonStyleSheet {
ButtonStyleSheet { ButtonStyleSheet {
normal: &ButtonStyle { normal: &ButtonStyle {

View File

@ -1684,7 +1684,7 @@
"TT_tezos-test_sign_tx.py::test_tezos_smart_contract_delegation": "8e87bb8ce0de9197f04e9059feeff5397be454b4cba6ca70ba2d6814f2583f14", "TT_tezos-test_sign_tx.py::test_tezos_smart_contract_delegation": "8e87bb8ce0de9197f04e9059feeff5397be454b4cba6ca70ba2d6814f2583f14",
"TT_tezos-test_sign_tx.py::test_tezos_smart_contract_transfer": "ce56ce9d3ae4d75cc14d4897352938ff52e9cf68f14dba1407a32c94c4110ca3", "TT_tezos-test_sign_tx.py::test_tezos_smart_contract_transfer": "ce56ce9d3ae4d75cc14d4897352938ff52e9cf68f14dba1407a32c94c4110ca3",
"TT_tezos-test_sign_tx.py::test_tezos_smart_contract_transfer_to_contract": "5776f71c1f1f6ccc81cfa941c82e544fa8f4c29cea7622d38bd82edd513137a6", "TT_tezos-test_sign_tx.py::test_tezos_smart_contract_transfer_to_contract": "5776f71c1f1f6ccc81cfa941c82e544fa8f4c29cea7622d38bd82edd513137a6",
"TT_webauthn-test_msg_webauthn.py::test_add_remove": "eba0b7596430b530df1440f35a33a713192da8e0433a53d3cc30b98a12dc2841", "TT_webauthn-test_msg_webauthn.py::test_add_remove": "7a74a2944c22536ed96568db71bfea1a3838b450f872fb26b907d9828b441d39",
"TT_webauthn-test_u2f_counter.py::test_u2f_counter": "6bf6db360292afbda963a1133152100a98378d05796a10fb505d757b39ede2aa", "TT_webauthn-test_u2f_counter.py::test_u2f_counter": "6bf6db360292afbda963a1133152100a98378d05796a10fb505d757b39ede2aa",
"TT_zcash-test_sign_tx.py::test_external_presigned": "cdb1416def8474959540b6312d77199ce7cd42ae2a2a44957eaaa977b8f21e23", "TT_zcash-test_sign_tx.py::test_external_presigned": "cdb1416def8474959540b6312d77199ce7cd42ae2a2a44957eaaa977b8f21e23",
"TT_zcash-test_sign_tx.py::test_one_two": "7f6911261bdd703469b0a32ed3d9d4e6abfdc6ba186b2975d6a12f130292ed18", "TT_zcash-test_sign_tx.py::test_one_two": "7f6911261bdd703469b0a32ed3d9d4e6abfdc6ba186b2975d6a12f130292ed18",