1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-06-02 22:28:45 +00:00

feat(core/rust): improve progress screen design

[no changelog]
This commit is contained in:
grdddj 2023-06-26 17:40:30 +02:00 committed by Jiří Musil
parent 64236e699f
commit f9f21176fd
3 changed files with 44 additions and 24 deletions

View File

@ -5,18 +5,22 @@ use crate::{
strutil::StringType, strutil::StringType,
ui::{ ui::{
component::{ component::{
base::ComponentExt,
paginated::Paginate, paginated::Paginate,
text::paragraphs::{Paragraph, Paragraphs}, text::paragraphs::{Paragraph, Paragraphs},
Child, Component, Event, EventCtx, Label, Never, Pad, Child, Component, Event, EventCtx, Label, Never, Pad,
}, },
constant,
display::{self, Font}, display::{self, Font},
geometry::Rect, geometry::Rect,
util::animation_disabled, util::animation_disabled,
}, },
}; };
use super::super::{constant, theme}; use super::super::theme;
const BOTTOM_DESCRIPTION_MARGIN: i16 = 10;
const LOADER_Y_OFFSET_TITLE: i16 = -10;
const LOADER_Y_OFFSET_NO_TITLE: i16 = -20;
pub struct Progress<T> pub struct Progress<T>
where where
@ -44,12 +48,13 @@ where
update_description: fn(&str) -> Result<T, Error>, update_description: fn(&str) -> Result<T, Error>,
) -> Self { ) -> Self {
Self { Self {
title: Label::centered(title, theme::TEXT_BOLD).into_child(), title: Child::new(Label::centered(title, theme::TEXT_BOLD)),
value: 0, value: 0,
loader_y_offset: 0, loader_y_offset: 0,
indeterminate, indeterminate,
description: Paragraphs::new(Paragraph::new(&theme::TEXT_BIG, description).centered()) description: Child::new(Paragraphs::new(
.into_child(), Paragraph::new(&theme::TEXT_NORMAL, description).centered(),
)),
description_pad: Pad::with_background(theme::BG), description_pad: Pad::with_background(theme::BG),
update_description, update_description,
} }
@ -72,10 +77,19 @@ where
.chars() .chars()
.filter(|c| *c == '\n') .filter(|c| *c == '\n')
.count() as i16; .count() as i16;
let (title, rest, loader_y_offset) = if self.title.inner().text().as_ref().is_empty() {
(Rect::zero(), Self::AREA, LOADER_Y_OFFSET_NO_TITLE)
} else {
let (title, rest) = Self::AREA.split_top(self.title.inner().max_size().y); let (title, rest) = Self::AREA.split_top(self.title.inner().max_size().y);
let (loader, description) = rest.split_bottom(Font::BIG.line_height() * description_lines); (title, rest, LOADER_Y_OFFSET_TITLE)
};
let (_loader, description) = rest.split_bottom(
BOTTOM_DESCRIPTION_MARGIN + Font::NORMAL.line_height() * description_lines,
);
self.title.place(title); self.title.place(title);
self.loader_y_offset = loader.center().y - constant::screen().center().y; self.loader_y_offset = loader_y_offset;
self.description.place(description); self.description.place(description);
self.description_pad.place(description); self.description_pad.place(description);
Self::AREA Self::AREA
@ -88,7 +102,11 @@ where
ctx.request_paint(); ctx.request_paint();
} }
self.description.mutate(ctx, |ctx, para| { self.description.mutate(ctx, |ctx, para| {
if para.inner_mut().content().as_ref() != new_description { // NOTE: not doing any change for empty new descriptions
// (currently, there is no use-case for deleting the description)
if !new_description.is_empty()
&& para.inner_mut().content().as_ref() != new_description
{
let new_description = unwrap!((self.update_description)(new_description)); let new_description = unwrap!((self.update_description)(new_description));
para.inner_mut().update(new_description); para.inner_mut().update(new_description);
para.change_page(0); // Recompute bounding box. para.change_page(0); // Recompute bounding box.
@ -112,7 +130,13 @@ where
None, None,
); );
} else { } else {
display::loader(self.value, self.loader_y_offset, theme::FG, theme::BG, None); display::loader(
self.value,
self.loader_y_offset,
theme::FG,
theme::BG,
Some((theme::ICON_TICK_FAT, theme::FG)),
);
} }
self.description_pad.paint(); self.description_pad.paint();
self.description.paint(); self.description.paint();

View File

@ -113,14 +113,10 @@ class Progress:
from trezor import workflow from trezor import workflow
from trezor.ui.layouts.progress import bitcoin_progress, coinjoin_progress from trezor.ui.layouts.progress import bitcoin_progress, coinjoin_progress
progress_layout = bitcoin_progress progress_layout = coinjoin_progress if self.is_coinjoin else bitcoin_progress
if self.is_coinjoin:
progress_layout = coinjoin_progress
workflow.close_others() workflow.close_others()
if self.signing: text = "Signing transaction..." if self.signing else "Loading transaction..."
self.progress_layout = progress_layout("Signing transaction") self.progress_layout = progress_layout(text)
else:
self.progress_layout = progress_layout("Loading transaction")
def report(self) -> None: def report(self) -> None:
from trezor import utils from trezor import utils

View File

@ -44,29 +44,29 @@ def progress(
) )
def bitcoin_progress(message: str) -> ProgressLayout: def bitcoin_progress(description: str) -> ProgressLayout:
return progress(message) return progress("", description)
def coinjoin_progress(message: str) -> ProgressLayout: def coinjoin_progress(message: str) -> ProgressLayout:
# TODO: create show_progress_coinjoin for TR # TODO: create show_progress_coinjoin for TR
return progress(message, description="Coinjoin") return progress("Coinjoin", message)
# return RustProgress( # return RustProgress(
# layout=trezorui2.show_progress_coinjoin(title=message, indeterminate=False) # layout=trezorui2.show_progress_coinjoin(title=message, indeterminate=False)
# ) # )
def pin_progress(message: str, description: str) -> ProgressLayout: def pin_progress(message: str, description: str) -> ProgressLayout:
return progress(message, description=description) return progress(message, description)
def monero_keyimage_sync_progress() -> ProgressLayout: def monero_keyimage_sync_progress() -> ProgressLayout:
return progress("SYNCING") return progress("", "Syncing...")
def monero_live_refresh_progress() -> ProgressLayout: def monero_live_refresh_progress() -> ProgressLayout:
return progress("REFRESHING", indeterminate=True) return progress("", "Refreshing...", indeterminate=True)
def monero_transaction_progress_inner() -> ProgressLayout: def monero_transaction_progress_inner() -> ProgressLayout:
return progress("SIGNING TRANSACTION") return progress("", "Signing transaction...")