Skip to content

Commit

Permalink
fix(core): rebase on drawlib and TStringificaton
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
obrusvit committed Apr 11, 2024
1 parent 669cfc7 commit fd71de0
Show file tree
Hide file tree
Showing 27 changed files with 708 additions and 774 deletions.
12 changes: 6 additions & 6 deletions core/embed/rust/src/ui/constant.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Reexporting the `constant` module according to the
//! current feature (Trezor model)

#[cfg(feature = "model_mercury")]
pub use super::model_mercury::constant::*;
#[cfg(all(
feature = "model_tr",
not(feature = "model_tt"),
not(feature = "model_mercury")
feature = "model_mercury",
not(feature = "model_tr"),
not(feature = "model_tt")
))]
pub use super::model_mercury::constant::*;
#[cfg(all(feature = "model_tr", not(feature = "model_tt")))]
pub use super::model_tr::constant::*;
#[cfg(all(feature = "model_tt", not(feature = "model_mercury")))]
#[cfg(feature = "model_tt")]
pub use super::model_tt::constant::*;
83 changes: 36 additions & 47 deletions core/embed/rust/src/ui/model_mercury/component/address_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use heapless::Vec;

use crate::{
error::Error,
micropython::buffer::StrBuffer,
strutil::StringType,
strutil::TString,
translations::TR,
ui::{
component::{
Expand All @@ -19,58 +18,57 @@ use super::{theme, Frame, FrameMsg};

const MAX_XPUBS: usize = 16;

pub struct AddressDetails<T> {
qr_code: Frame<Qr, T>,
details: Frame<Paragraphs<ParagraphVecShort<StrBuffer>>, T>,
xpub_view: Frame<Paragraphs<Paragraph<T>>, T>,
xpubs: Vec<(T, T), MAX_XPUBS>,
pub struct AddressDetails {
qr_code: Frame<Qr>,
details: Frame<Paragraphs<ParagraphVecShort<'static>>>,
xpub_view: Frame<Paragraphs<Paragraph<'static>>>,
xpubs: Vec<(TString<'static>, TString<'static>), MAX_XPUBS>,
xpub_page_count: Vec<u8, MAX_XPUBS>,
current_page: usize,
}

impl<T> AddressDetails<T>
where
T: StringType,
{
impl AddressDetails {
pub fn new(
qr_title: T,
qr_address: T,
qr_title: TString<'static>,
qr_address: TString<'static>,
case_sensitive: bool,
details_title: T,
account: Option<StrBuffer>,
path: Option<StrBuffer>,
) -> Result<Self, Error>
where
T: From<&'static str>,
{
details_title: TString<'static>,
account: Option<TString<'static>>,
path: Option<TString<'static>>,
) -> Result<Self, Error> {
let mut para = ParagraphVecShort::new();
if let Some(a) = account {
para.add(Paragraph::new(
&theme::TEXT_NORMAL,
TR::words__account_colon.try_into()?,
TR::words__account_colon,
));
para.add(Paragraph::new(&theme::TEXT_MONO, a));
}
if let Some(p) = path {
para.add(Paragraph::new(
&theme::TEXT_NORMAL,
TR::address_details__derivation_path.try_into()?,
TR::address_details__derivation_path,
));
para.add(Paragraph::new(&theme::TEXT_MONO, p));
}
let result = Self {
qr_code: Frame::left_aligned(
qr_title,
Qr::new(qr_address, case_sensitive)?.with_border(7),
qr_address
.map(|s| Qr::new(s, case_sensitive))?
.with_border(7),
)
.with_cancel_button()
.with_border(theme::borders_horizontal_scroll()),
details: Frame::left_aligned(
details_title,
para.into_paragraphs(),
)
.with_cancel_button()
.with_border(theme::borders_horizontal_scroll()),
details: Frame::left_aligned(details_title, para.into_paragraphs())
.with_cancel_button()
.with_border(theme::borders_horizontal_scroll()),
xpub_view: Frame::left_aligned(
" \n ".into(),
Paragraph::new(&theme::TEXT_MONO, "".into()).into_paragraphs(),
Paragraph::new(&theme::TEXT_MONO, "").into_paragraphs(),
)
.with_cancel_button()
.with_border(theme::borders_horizontal_scroll()),
Expand All @@ -81,24 +79,24 @@ where
Ok(result)
}

pub fn add_xpub(&mut self, title: T, xpub: T) -> Result<(), Error> {
pub fn add_xpub(
&mut self,
title: TString<'static>,
xpub: TString<'static>,
) -> Result<(), Error> {
self.xpubs
.push((title, xpub))
.map_err(|_| Error::OutOfRange)
}

fn switch_xpub(&mut self, i: usize, page: usize) -> usize
where
T: Clone,
{
fn switch_xpub(&mut self, i: usize, page: usize) -> usize {
// Context is needed for updating child so that it can request repaint. In this
// case the parent component that handles paging always requests complete
// repaint after page change so we can use a dummy context here.
let mut dummy_ctx = EventCtx::new();
self.xpub_view
.update_title(&mut dummy_ctx, self.xpubs[i].0.clone());
self.xpub_view.update_title(&mut dummy_ctx, self.xpubs[i].0);
self.xpub_view.update_content(&mut dummy_ctx, |p| {
p.inner_mut().update(self.xpubs[i].1.clone());
p.inner_mut().update(self.xpubs[i].1);
let npages = p.page_count();
p.change_page(page);
npages
Expand All @@ -123,10 +121,7 @@ where
}
}

impl<T> Paginate for AddressDetails<T>
where
T: StringType + Clone,
{
impl Paginate for AddressDetails {
fn page_count(&mut self) -> usize {
let total_xpub_pages: u8 = self.xpub_page_count.iter().copied().sum();
2usize.saturating_add(total_xpub_pages.into())
Expand All @@ -142,10 +137,7 @@ where
}
}

impl<T> Component for AddressDetails<T>
where
T: StringType + Clone,
{
impl Component for AddressDetails {
type Msg = ();

fn place(&mut self, bounds: Rect) -> Rect {
Expand Down Expand Up @@ -201,10 +193,7 @@ where
}

#[cfg(feature = "ui_debug")]
impl<T> crate::trace::Trace for AddressDetails<T>
where
T: StringType,
{
impl crate::trace::Trace for AddressDetails {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("AddressDetails");
match self.current_page {
Expand Down
98 changes: 50 additions & 48 deletions core/embed/rust/src/ui/model_mercury/component/bl_confirm.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
use crate::ui::{
component::{Child, Component, ComponentExt, Event, EventCtx, Label, Pad},
constant,
constant::screen,
display::{Color, Icon},
geometry::{Alignment2D, Insets, Offset, Point, Rect},
model_mercury::{
component::{Button, ButtonMsg::Clicked, ButtonStyleSheet},
use crate::{
strutil::TString,
ui::{
component::{Child, Component, ComponentExt, Event, EventCtx, Label, Pad},
constant,
constant::WIDTH,
theme::{
bootloader::{
text_fingerprint, text_title, BUTTON_AREA_START, BUTTON_HEIGHT, CONTENT_PADDING,
CORNER_BUTTON_AREA, CORNER_BUTTON_TOUCH_EXPANSION, INFO32, TITLE_AREA, X32,
},
WHITE,
constant::screen,
display::{Color, Icon},
geometry::{Alignment2D, Insets, Offset, Point, Rect},
shape,
shape::Renderer,
},
};

use super::{
theme::{
bootloader::{
text_fingerprint, text_title, BUTTON_AREA_START, BUTTON_HEIGHT, CONTENT_PADDING,
CORNER_BUTTON_AREA, CORNER_BUTTON_TOUCH_EXPANSION, INFO32, TITLE_AREA, X32,
},
WHITE,
},
shape,
shape::Renderer,
Button,
ButtonMsg::Clicked,
ButtonStyleSheet,
};

const ICON_TOP: i16 = 17;
Expand All @@ -33,41 +39,38 @@ pub enum ConfirmMsg {
Confirm = 2,
}

pub enum ConfirmTitle<T> {
Text(Label<T>),
pub enum ConfirmTitle {
Text(Label<'static>),
Icon(Icon),
}

pub struct ConfirmInfo<T> {
pub title: Child<Label<T>>,
pub text: Child<Label<T>>,
pub info_button: Child<Button<&'static str>>,
pub close_button: Child<Button<&'static str>>,
pub struct ConfirmInfo<'a> {
pub title: Child<Label<'a>>,
pub text: Child<Label<'a>>,
pub info_button: Child<Button>,
pub close_button: Child<Button>,
}

pub struct Confirm<T> {
pub struct Confirm<'a> {
bg: Pad,
content_pad: Pad,
bg_color: Color,
title: ConfirmTitle<T>,
message: Child<Label<T>>,
alert: Option<Child<Label<T>>>,
left_button: Child<Button<T>>,
right_button: Child<Button<T>>,
info: Option<ConfirmInfo<T>>,
title: ConfirmTitle,
message: Child<Label<'a>>,
alert: Option<Child<Label<'static>>>,
left_button: Child<Button>,
right_button: Child<Button>,
info: Option<ConfirmInfo<'a>>,
show_info: bool,
}

impl<T> Confirm<T>
where
T: AsRef<str>,
{
impl<'a> Confirm<'a> {
pub fn new(
bg_color: Color,
left_button: Button<T>,
right_button: Button<T>,
title: ConfirmTitle<T>,
message: Label<T>,
left_button: Button,
right_button: Button,
title: ConfirmTitle,
message: Label<'a>,
) -> Self {
Self {
bg: Pad::with_background(bg_color).with_clear(),
Expand All @@ -83,12 +86,17 @@ where
}
}

pub fn with_alert(mut self, alert: Label<T>) -> Self {
pub fn with_alert(mut self, alert: Label<'static>) -> Self {
self.alert = Some(Child::new(alert.vertically_centered()));
self
}

pub fn with_info(mut self, title: T, text: T, menu_button: ButtonStyleSheet) -> Self {
pub fn with_info(
mut self,
title: TString<'a>,
text: TString<'a>,
menu_button: ButtonStyleSheet,
) -> Self {
self.info = Some(ConfirmInfo {
title: Child::new(
Label::left_aligned(title, text_title(self.bg_color)).vertically_centered(),
Expand All @@ -111,10 +119,7 @@ where
}
}

impl<T> Component for Confirm<T>
where
T: AsRef<str>,
{
impl Component for Confirm<'_> {
type Msg = ConfirmMsg;

fn place(&mut self, bounds: Rect) -> Rect {
Expand Down Expand Up @@ -278,10 +283,7 @@ where
}

#[cfg(feature = "ui_debug")]
impl<T> crate::trace::Trace for Confirm<T>
where
T: AsRef<str>,
{
impl crate::trace::Trace for Confirm<'_> {
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.component("BlConfirm");
}
Expand Down
Loading

0 comments on commit fd71de0

Please sign in to comment.