Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI tweaks for ETH contract flow #4346

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/embed/rust/librust_qstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ static void _librust_qstrs(void) {
MP_QSTR_buttons__turn_on;
MP_QSTR_buttons__view_all_data;
MP_QSTR_can_go_back;
MP_QSTR_cancel;
MP_QSTR_cancel_arrow;
MP_QSTR_cancel_cross;
MP_QSTR_cancel_text;
Expand All @@ -193,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 @@ -357,7 +359,7 @@ static void _librust_qstrs(void) {
MP_QSTR_notification;
MP_QSTR_notification_level;
MP_QSTR_page_count;
MP_QSTR_page_limit;
MP_QSTR_page_counter;
MP_QSTR_pages;
MP_QSTR_paint;
MP_QSTR_passphrase__access_wallet;
Expand Down Expand Up @@ -1019,6 +1021,7 @@ static void _librust_qstrs(void) {
MP_QSTR_ethereum__token_contract;
MP_QSTR_ethereum__units_template;
MP_QSTR_ethereum__unknown_contract_address;
MP_QSTR_ethereum__unknown_contract_address_short;
MP_QSTR_ethereum__unknown_token;
MP_QSTR_ethereum__valid_signature;
MP_QSTR_fido__already_registered;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/embed/rust/src/ui/component/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ where
}

impl<T: Paginate> Paginate for Child<T> {
fn page_count(&mut self) -> usize {
fn page_count(&self) -> usize {
self.component.page_count()
}

Expand Down
2 changes: 1 addition & 1 deletion core/embed/rust/src/ui/component/paginated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum PageMsg<T> {

pub trait Paginate {
/// How many pages of content are there in total?
fn page_count(&mut self) -> usize;
fn page_count(&self) -> usize;
/// Navigate to the given page.
fn change_page(&mut self, active_page: usize);
}
28 changes: 14 additions & 14 deletions core/embed/rust/src/ui/component/text/formatted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ impl FormattedText {
}

pub(crate) fn layout_content(&self, sink: &mut dyn LayoutSink) -> LayoutFit {
self.layout_content_with_offset(sink, self.char_offset, self.y_offset)
}

fn layout_content_with_offset(
&self,
sink: &mut dyn LayoutSink,
char_offset: usize,
y_offset: i16,
) -> LayoutFit {
self.op_layout
.layout_ops(self.char_offset, Offset::y(self.y_offset), sink)
.layout_ops(char_offset, Offset::y(y_offset), sink)
}

fn align_vertically(&mut self, content_height: i16) {
Expand All @@ -53,20 +62,15 @@ impl FormattedText {

// Pagination
impl Paginate for FormattedText {
fn page_count(&mut self) -> usize {
fn page_count(&self) -> usize {
let mut page_count = 1; // There's always at least one page.

// Make sure we're starting page counting from the very beginning
// (but remembering the offsets not to change them).
let initial_y_offset = self.y_offset;
let initial_char_offset = self.char_offset;
self.char_offset = 0;
self.y_offset = 0;
let mut char_offset = 0;

// Looping through the content and counting pages
// until we finally fit.
loop {
let fit = self.layout_content(&mut TextNoOp);
let fit = self.layout_content_with_offset(&mut TextNoOp, char_offset, 0);
match fit {
LayoutFit::Fitting { .. } => {
break;
Expand All @@ -75,15 +79,11 @@ impl Paginate for FormattedText {
processed_chars, ..
} => {
page_count += 1;
self.char_offset += processed_chars;
char_offset += processed_chars;
}
}
}

// Setting the offsets back to the initial values.
self.char_offset = initial_char_offset;
self.y_offset = initial_y_offset;

page_count
}

Expand Down
6 changes: 3 additions & 3 deletions core/embed/rust/src/ui/component/text/paragraphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl<'a, T> Paginate for Paragraphs<T>
where
T: ParagraphSource<'a>,
{
fn page_count(&mut self) -> usize {
fn page_count(&self) -> usize {
// There's always at least one page.
self.break_pages().count().max(1)
}
Expand Down Expand Up @@ -374,7 +374,7 @@ struct PageOffset {
}

impl PageOffset {
/// Given an `PageOffset` and a `Rect` area, returns:
/// Given a `PageOffset` and a `Rect` area, returns:
///
/// - The next offset.
/// - Part of `area` that remains free after the current offset is rendered
Expand Down Expand Up @@ -690,7 +690,7 @@ impl<'a, T> Paginate for Checklist<T>
where
T: ParagraphSource<'a>,
{
fn page_count(&mut self) -> usize {
fn page_count(&self) -> usize {
1
}

Expand Down
8 changes: 8 additions & 0 deletions core/embed/rust/src/ui/flow/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ impl<T: Component + Paginate> SwipePage<T> {
self.limit = limit;
self
}

pub fn page_count(&self) -> usize {
self.pages
}

pub fn current_page(&self) -> usize {
self.current
}
}

impl<T: Component + Paginate> Component for SwipePage<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl AddressDetails {
}

impl Paginate for AddressDetails {
fn page_count(&mut self) -> usize {
fn page_count(&self) -> usize {
self.get_internal_page_count()
}

Expand Down
32 changes: 14 additions & 18 deletions core/embed/rust/src/ui/model_mercury/component/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ impl<'a> Footer<'a> {
)
}

pub fn with_page_counter(max_pages: u8, instruction: TString<'static>) -> Self {
Self::from_content(FooterContent::PageCounter(PageCounter::new(
max_pages,
instruction,
)))
pub fn with_page_counter(instruction: TString<'static>) -> Self {
Self::from_content(FooterContent::PageCounter(PageCounter::new(instruction)))
}

pub fn with_page_hint(
Expand Down Expand Up @@ -115,18 +112,18 @@ impl<'a> Footer<'a> {
}
}

pub fn update_page_counter(&mut self, ctx: &mut EventCtx, current: usize, max: Option<usize>) {
pub fn update_page_counter(&mut self, ctx: &mut EventCtx, current: usize, max: usize) {
match &mut self.content {
FooterContent::PageCounter(counter) => {
counter.update_current_page(current);
counter.update_current_page(current, max);
self.swipe_allow_down = counter.is_first_page();
self.swipe_allow_up = counter.is_last_page();
ctx.request_paint();
}
FooterContent::PageHint(page_hint) => {
page_hint.update_current_page(current, max);
self.swipe_allow_down = page_hint.is_first_page();
self.swipe_allow_up = page_hint.is_last_page();
FooterContent::PageHint(hint) => {
hint.update_current_page(current, max);
self.swipe_allow_down = hint.is_first_page();
self.swipe_allow_up = hint.is_last_page();
ctx.request_paint();
}
_ => {
Expand Down Expand Up @@ -322,16 +319,17 @@ struct PageCounter {
}

impl PageCounter {
fn new(page_max: u8, instruction: TString<'static>) -> Self {
fn new(instruction: TString<'static>) -> Self {
Self {
instruction,
page_curr: 0,
page_max,
page_max: 0,
font: Font::SUB,
}
}

fn update_current_page(&mut self, new_value: usize) {
fn update_current_page(&mut self, new_value: usize, max: usize) {
self.page_max = max as u8;
self.page_curr = (new_value as u8).clamp(0, self.page_max.saturating_sub(1));
}

Expand Down Expand Up @@ -410,11 +408,9 @@ struct PageHint {
}

impl PageHint {
fn update_current_page(&mut self, current: usize, max: Option<usize>) {
fn update_current_page(&mut self, current: usize, max: usize) {
self.page_num = max as u8;
self.page_curr = (current as u8).clamp(0, self.page_num.saturating_sub(1));
if let Some(max) = max {
self.page_num = max as u8;
}
}

fn update_max_page(&mut self, max: usize) {
Expand Down
27 changes: 21 additions & 6 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 @@ -195,8 +197,8 @@ where
}

#[inline(never)]
pub fn with_footer_counter(mut self, instruction: TString<'static>, max_value: u8) -> Self {
self.footer = Some(Footer::with_page_counter(max_value, instruction));
pub fn with_footer_counter(mut self, instruction: TString<'static>) -> Self {
self.footer = Some(Footer::with_page_counter(instruction));
self
}

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 @@ -347,9 +355,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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the real margin now SPACING + margin. It's quite confusing but probably fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. What could I do about it? Rename my parameter to extra_margin? Would that make more sense?

header_area = header_area.inset(Insets::sides(theme::SPACING));

header.place(header_area);
Expand All @@ -360,7 +375,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
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl<F: Fn(usize) -> TString<'static>> PagedVerticalMenu<F> {
}

impl<F: Fn(usize) -> TString<'static>> Paginate for PagedVerticalMenu<F> {
fn page_count(&mut self) -> usize {
fn page_count(&self) -> usize {
self.num_pages()
}

Expand Down
4 changes: 4 additions & 0 deletions core/embed/rust/src/ui/model_mercury/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::ui::geometry::{Offset, Point, Rect};

use crate::trezorhal::display::{DISPLAY_RESX, DISPLAY_RESY};

use crate::translations::TR;

pub const WIDTH: i16 = DISPLAY_RESX as _;
pub const HEIGHT: i16 = DISPLAY_RESY as _;
pub const LINE_SPACE: i16 = 4;
Expand All @@ -20,3 +22,5 @@ pub const fn screen() -> Rect {
Rect::from_top_left_and_size(Point::zero(), SIZE)
}
pub const SCREEN: Rect = screen();

pub const VERB_CANCEL_DEFAULT: TR = TR::buttons__cancel;
Loading
Loading