Skip to content

Commit

Permalink
feat(core/ui): tweak blob first page appearance
Browse files Browse the repository at this point in the history
This commit adds a margin and footer description to the first page of
the paginated blobs to be confirmed on Mercury. It also extracts the
part of confirm_blob that deals with the first page to a separate
function in order to keep confirm_blob simple.

[no changelog]
  • Loading branch information
ibz committed Nov 15, 2024
1 parent 4f1442c commit 29da869
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 60 deletions.
2 changes: 1 addition & 1 deletion core/embed/rust/librust_qstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ static void _librust_qstrs(void) {
MP_QSTR_confirm_address;
MP_QSTR_confirm_backup;
MP_QSTR_confirm_blob;
MP_QSTR_confirm_blob_intro;
MP_QSTR_confirm_coinjoin;
MP_QSTR_confirm_emphasized;
MP_QSTR_confirm_fido;
Expand Down Expand Up @@ -359,7 +360,6 @@ static void _librust_qstrs(void) {
MP_QSTR_notification_level;
MP_QSTR_page_count;
MP_QSTR_page_counter;
MP_QSTR_page_limit;
MP_QSTR_pages;
MP_QSTR_paint;
MP_QSTR_passphrase__access_wallet;
Expand Down
23 changes: 19 additions & 4 deletions core/embed/rust/src/ui/model_mercury/component/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub struct Frame<T> {
swipe: SwipeConfig,
internal_page_cnt: usize,
horizontal_swipe: HorizontalSwipe,
margin: usize,
}

pub enum FrameMsg<T> {
Expand All @@ -111,6 +112,7 @@ where
swipe: SwipeConfig::new(),
internal_page_cnt: 1,
horizontal_swipe: HorizontalSwipe::new(),
margin: 0,
}
}

Expand Down Expand Up @@ -262,12 +264,18 @@ where
..self
}
}

pub fn with_vertical_pages(self) -> Self {
Self {
swipe: self.swipe.with_vertical_pages(),
..self
}
}

pub fn with_margin(mut self, margin: usize) -> Self {
self.margin = margin;
self
}
}

impl<T> Component for Frame<T>
Expand All @@ -278,7 +286,7 @@ where

fn place(&mut self, bounds: Rect) -> Rect {
self.bounds = bounds;
let content_area = frame_place(&mut self.header, &mut self.footer, bounds);
let content_area = frame_place(&mut self.header, &mut self.footer, bounds, self.margin);

self.content.place(content_area);

Expand Down Expand Up @@ -352,9 +360,16 @@ fn frame_event(
header.event(ctx, event)
}

fn frame_place(header: &mut Header, footer: &mut Option<Footer>, bounds: Rect) -> Rect {
fn frame_place(
header: &mut Header,
footer: &mut Option<Footer>,
bounds: Rect,
margin: usize,
) -> Rect {
let (mut header_area, mut content_area) = bounds.split_top(TITLE_HEIGHT);
content_area = content_area.inset(Insets::top(theme::SPACING));
content_area = content_area
.inset(Insets::top(theme::SPACING))
.inset(Insets::top(margin as i16));
header_area = header_area.inset(Insets::sides(theme::SPACING));

header.place(header_area);
Expand All @@ -365,7 +380,7 @@ fn frame_place(header: &mut Header, footer: &mut Option<Footer>, bounds: Rect) -
content_area = content_area.inset(Insets::bottom(theme::SPACING));
let (remaining, footer_area) = content_area.split_bottom(footer.height());
footer.place(footer_area);
content_area = remaining;
content_area = remaining.inset(Insets::bottom(margin as i16));
}
content_area
}
Expand Down
17 changes: 16 additions & 1 deletion core/embed/rust/src/ui/model_mercury/flow/confirm_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct ConfirmActionStrings {
subtitle: Option<TString<'static>>,
verb: Option<TString<'static>>,
prompt_screen: Option<TString<'static>>,
footer_description: Option<TString<'static>>,
}

impl ConfirmActionStrings {
Expand All @@ -62,8 +63,14 @@ impl ConfirmActionStrings {
subtitle,
verb,
prompt_screen,
footer_description: None,
}
}

pub fn with_footer_description(mut self, footer_description: Option<TString<'static>>) -> Self {
self.footer_description = footer_description;
self
}
}

/// The simplest form of the ConfirmAction flow:
Expand Down Expand Up @@ -215,6 +222,7 @@ fn new_confirm_action_obj(_args: &[Obj], kwargs: &Map) -> Result<Obj, error::Err
ConfirmActionStrings::new(title, subtitle, None, prompt_screen.then_some(prompt_title)),
hold,
None,
0,
false,
)
}
Expand All @@ -225,16 +233,21 @@ fn new_confirm_action_uni<T: Component + Paginate + MaybeTrace + 'static>(
extra: ConfirmActionExtra,
strings: ConfirmActionStrings,
hold: bool,
frame_margin: usize,
show_page_counter: bool,
) -> Result<Obj, error::Error> {
let (prompt_screen, prompt_pages, flow, page) =
create_flow(strings.title, strings.prompt_screen, hold, &extra);

let mut content = Frame::left_aligned(strings.title, content)
.with_margin(frame_margin)
.with_swipe(Direction::Up, SwipeSettings::default())
.with_swipe(Direction::Left, SwipeSettings::default())
.with_vertical_pages()
.with_footer(TR::instructions__swipe_up.into(), None);
.with_footer(
TR::instructions__swipe_up.into(),
strings.footer_description,
);

match extra {
ConfirmActionExtra::Menu { .. } => {
Expand Down Expand Up @@ -407,13 +420,15 @@ pub fn new_confirm_action_simple<T: Component + Paginate + MaybeTrace + 'static>
strings: ConfirmActionStrings,
hold: bool,
page_limit: Option<usize>,
frame_margin: usize,
show_page_counter: bool,
) -> Result<Obj, error::Error> {
new_confirm_action_uni(
SwipeContent::new(SwipePage::vertical(content).with_limit(page_limit)),
extra,
strings,
hold,
frame_margin,
show_page_counter,
)
}
98 changes: 81 additions & 17 deletions core/embed/rust/src/ui/model_mercury/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ use crate::{
},
};

const CONFIRM_BLOB_INTRO_MARGIN: usize = 24;

impl TryFrom<SelectWordCountMsg> for Obj {
type Error = Error;

Expand Down Expand Up @@ -249,6 +251,7 @@ extern "C" fn new_confirm_emphasized(n_args: usize, args: *const Obj, kwargs: *m
ConfirmActionStrings::new(title, None, None, Some(title)),
false,
None,
0,
false,
)
};
Expand All @@ -265,13 +268,15 @@ struct ConfirmBlobParams {
verb: Option<TString<'static>>,
verb_cancel: Option<TString<'static>>,
verb_info: Option<TString<'static>>,
footer_description: Option<TString<'static>>,
info_button: bool,
prompt: bool,
hold: bool,
chunkify: bool,
text_mono: bool,
page_counter: bool,
page_limit: Option<usize>,
frame_margin: usize,
cancel: bool,
}

Expand All @@ -295,13 +300,15 @@ impl ConfirmBlobParams {
verb,
verb_cancel: None,
verb_info,
footer_description: None,
info_button: false,
prompt,
hold,
chunkify: false,
text_mono: true,
page_counter: false,
page_limit: None,
frame_margin: 0,
cancel: false,
}
}
Expand Down Expand Up @@ -346,6 +353,16 @@ impl ConfirmBlobParams {
self
}

fn with_frame_margin(mut self, frame_margin: usize) -> Self {
self.frame_margin = frame_margin;
self
}

fn with_footer_description(mut self, footer_description: Option<TString<'static>>) -> Self {
self.footer_description = footer_description;
self
}

fn with_cancel(mut self, cancel: bool) -> Self {
self.cancel = cancel;
self
Expand Down Expand Up @@ -392,9 +409,11 @@ impl ConfirmBlobParams {
self.subtitle,
self.verb,
self.prompt.then_some(self.title),
),
)
.with_footer_description(self.footer_description),
self.hold,
self.page_limit,
self.frame_margin,
self.page_counter,
)
}
Expand Down Expand Up @@ -434,21 +453,8 @@ extern "C" fn new_confirm_blob(n_args: usize, args: *const Obj, kwargs: *mut Map
let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?;
let page_counter: bool = kwargs.get_or(Qstr::MP_QSTR_page_counter, false)?;
let prompt_screen: bool = kwargs.get_or(Qstr::MP_QSTR_prompt_screen, true)?;
let page_limit: Option<usize> = kwargs
.get(Qstr::MP_QSTR_page_limit)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let cancel: bool = kwargs.get_or(Qstr::MP_QSTR_cancel, false)?;

let (description, description_font) = if page_limit == Some(1) {
(
Some(TR::instructions__view_all_data.into()),
&theme::TEXT_SUB_GREEN_LIME,
)
} else {
(description, &theme::TEXT_NORMAL)
};

ConfirmBlobParams::new(
title,
data,
Expand All @@ -458,21 +464,61 @@ extern "C" fn new_confirm_blob(n_args: usize, args: *const Obj, kwargs: *mut Map
prompt_screen,
hold,
)
.with_description_font(description_font)
.with_text_mono(text_mono)
.with_subtitle(subtitle)
.with_verb_cancel(verb_cancel)
.with_extra(extra)
.with_info_button(info)
.with_chunkify(chunkify)
.with_page_counter(page_counter)
.with_page_limit(page_limit)
.with_cancel(cancel)
.into_flow()
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}

extern "C" fn new_confirm_blob_intro(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
let data: Obj = kwargs.get(Qstr::MP_QSTR_data)?;
let subtitle: Option<TString> = kwargs
.get(Qstr::MP_QSTR_subtitle)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let verb: Option<TString> = kwargs
.get(Qstr::MP_QSTR_verb)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let verb_cancel: Option<TString> = kwargs
.get(Qstr::MP_QSTR_verb_cancel)
.unwrap_or_else(|_| Obj::const_none())
.try_into_option()?;
let chunkify: bool = kwargs.get_or(Qstr::MP_QSTR_chunkify, false)?;

ConfirmBlobParams::new(
title,
data,
Some(TR::instructions__view_all_data.into()),
verb,
Some(TR::buttons__view_all_data.into()),
false,
false,
)
.with_description_font(&theme::TEXT_SUB_GREEN_LIME)
.with_subtitle(subtitle)
.with_verb_cancel(verb_cancel)
.with_footer_description(Some(
TR::buttons__confirm.into(), /* or words__confirm?? */
))
.with_info_button(true)
.with_chunkify(chunkify)
.with_page_limit(Some(1))
.with_frame_margin(CONFIRM_BLOB_INTRO_MARGIN)
.into_flow()
};
unsafe { util::try_with_args_and_kwargs(n_args, args, kwargs, block) }
}

extern "C" fn new_confirm_address(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
let block = move |_args: &[Obj], kwargs: &Map| {
let title: TString = kwargs.get(Qstr::MP_QSTR_title)?.try_into()?;
Expand Down Expand Up @@ -509,6 +555,7 @@ extern "C" fn new_confirm_address(n_args: usize, args: *const Obj, kwargs: *mut
ConfirmActionStrings::new(title, None, None, None),
false,
None,
0,
false,
)
};
Expand Down Expand Up @@ -538,6 +585,7 @@ extern "C" fn new_confirm_properties(n_args: usize, args: *const Obj, kwargs: *m
ConfirmActionStrings::new(title, None, None, hold.then_some(title)),
hold,
None,
0,
false,
)
};
Expand Down Expand Up @@ -575,6 +623,7 @@ extern "C" fn new_confirm_homescreen(n_args: usize, args: *const Obj, kwargs: *m
),
false,
None,
0,
false,
)
} else {
Expand Down Expand Up @@ -687,6 +736,7 @@ extern "C" fn new_confirm_total(n_args: usize, args: *const Obj, kwargs: *mut Ma
ConfirmActionStrings::new(title, None, None, Some(title)),
true,
None,
0,
false,
)
};
Expand Down Expand Up @@ -981,6 +1031,7 @@ extern "C" fn new_confirm_coinjoin(n_args: usize, args: *const Obj, kwargs: *mut
),
true,
None,
0,
false,
)
};
Expand Down Expand Up @@ -1321,12 +1372,25 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// chunkify: bool = False,
/// page_counter: bool = False,
/// prompt_screen: bool = False,
/// page_limit: int | None = None,
/// cancel: bool = False,
/// ) -> LayoutObj[UiResult]:
/// """Confirm byte sequence data."""
Qstr::MP_QSTR_confirm_blob => obj_fn_kw!(0, new_confirm_blob).as_obj(),

/// def confirm_blob_intro(
/// *,
/// title: str,
/// data: str | bytes,
/// subtitle: str | None = None,
/// verb: str | None = None,
/// verb_cancel: str | None = None,
/// chunkify: bool = False,
/// ) -> LayoutObj[UiResult]:
/// """Confirm byte sequence data by showing only the first page of the data
/// and instructing the user to access the menu in order to view all the data,
/// which can then be confirmed using confirm_blob."""
Qstr::MP_QSTR_confirm_blob_intro => obj_fn_kw!(0, new_confirm_blob_intro).as_obj(),

/// def confirm_address(
/// *,
/// title: str,
Expand Down
1 change: 0 additions & 1 deletion core/embed/rust/src/ui/model_tr/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,6 @@ pub static mp_module_trezorui2: Module = obj_module! {
/// chunkify: bool = False,
/// page_counter: bool = False,
/// prompt_screen: bool = False,
/// page_limit: int | None = None,
/// cancel: bool = False,
/// ) -> LayoutObj[UiResult]:
/// """Confirm byte sequence data."""
Expand Down
Loading

0 comments on commit 29da869

Please sign in to comment.