mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-24 13:22:05 +00:00
feat(eckhart): implement confirm_value
This commit is contained in:
parent
9c982b86d2
commit
baceb7b1e4
@ -137,6 +137,12 @@ pub const TEXT_MONO_LIGHT: TextStyle = TextStyle::new(
|
|||||||
GREY_EXTRA_LIGHT,
|
GREY_EXTRA_LIGHT,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// Decide the text style of chunkified text according to its length.
|
||||||
|
pub fn get_chunkified_text_style(_character_length: usize) -> &'static TextStyle {
|
||||||
|
// TODO: implement properly for Eckhart, see Delizia implemenation
|
||||||
|
&TEXT_MONO_MEDIUM
|
||||||
|
}
|
||||||
|
|
||||||
pub const fn label_title_main() -> TextStyle {
|
pub const fn label_title_main() -> TextStyle {
|
||||||
TEXT_SMALL
|
TEXT_SMALL
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
error::Error,
|
error::Error,
|
||||||
io::BinaryData,
|
io::BinaryData,
|
||||||
micropython::{gc::Gc, list::List, obj::Obj},
|
micropython::{gc::Gc, iter::IterBuf, list::List, obj::Obj, util},
|
||||||
strutil::TString,
|
strutil::TString,
|
||||||
translations::TR,
|
translations::TR,
|
||||||
ui::{
|
ui::{
|
||||||
component::{
|
component::{
|
||||||
text::{
|
text::{
|
||||||
op::OpTextLayout,
|
op::OpTextLayout,
|
||||||
paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort},
|
paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, VecExt},
|
||||||
},
|
},
|
||||||
Empty, FormattedText,
|
Empty, FormattedText,
|
||||||
},
|
},
|
||||||
@ -24,7 +24,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
component::{ActionBar, Button, Header, Hint, TextScreen},
|
component::{ActionBar, Button, Header, HeaderMsg, Hint, TextScreen},
|
||||||
fonts, theme, UIEckhart,
|
fonts, theme, UIEckhart,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -188,22 +188,65 @@ impl FirmwareUI for UIEckhart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn confirm_value(
|
fn confirm_value(
|
||||||
_title: TString<'static>,
|
title: TString<'static>,
|
||||||
_value: Obj,
|
value: Obj,
|
||||||
_description: Option<TString<'static>>,
|
description: Option<TString<'static>>,
|
||||||
_is_data: bool,
|
is_data: bool,
|
||||||
_extra: Option<TString<'static>>,
|
extra: Option<TString<'static>>,
|
||||||
_subtitle: Option<TString<'static>>,
|
_subtitle: Option<TString<'static>>,
|
||||||
_verb: Option<TString<'static>>,
|
verb: Option<TString<'static>>,
|
||||||
_verb_cancel: Option<TString<'static>>,
|
_verb_cancel: Option<TString<'static>>,
|
||||||
_info: bool,
|
info: bool,
|
||||||
_hold: bool,
|
hold: bool,
|
||||||
_chunkify: bool,
|
chunkify: bool,
|
||||||
_page_counter: bool,
|
page_counter: bool,
|
||||||
_prompt_screen: bool,
|
_prompt_screen: bool,
|
||||||
_cancel: bool,
|
cancel: bool,
|
||||||
) -> Result<Gc<LayoutObj>, Error> {
|
) -> Result<Gc<LayoutObj>, Error> {
|
||||||
Err::<Gc<LayoutObj>, Error>(Error::ValueError(c"not implemented"))
|
let paragraphs = ConfirmValueParams {
|
||||||
|
description: description.unwrap_or("".into()),
|
||||||
|
extra: extra.unwrap_or("".into()),
|
||||||
|
value: if value != Obj::const_none() {
|
||||||
|
value.try_into()?
|
||||||
|
} else {
|
||||||
|
StrOrBytes::Str("".into())
|
||||||
|
},
|
||||||
|
font: if chunkify {
|
||||||
|
let value: TString = value.try_into()?;
|
||||||
|
theme::get_chunkified_text_style(value.len())
|
||||||
|
} else if is_data {
|
||||||
|
&theme::TEXT_MONO_MEDIUM
|
||||||
|
} else {
|
||||||
|
&theme::TEXT_MEDIUM
|
||||||
|
},
|
||||||
|
description_font: &theme::TEXT_SMALL,
|
||||||
|
extra_font: &theme::TEXT_SMALL,
|
||||||
|
}
|
||||||
|
.into_paragraphs();
|
||||||
|
|
||||||
|
let verb = verb.unwrap_or(TR::buttons__confirm.into());
|
||||||
|
let right_button = if hold {
|
||||||
|
Button::with_text(verb).with_long_press(theme::CONFIRM_HOLD_DURATION)
|
||||||
|
} else {
|
||||||
|
Button::with_text(verb)
|
||||||
|
};
|
||||||
|
let header = if info {
|
||||||
|
Header::new(title)
|
||||||
|
.with_right_button(Button::with_icon(theme::ICON_INFO), HeaderMsg::Menu)
|
||||||
|
} else {
|
||||||
|
Header::new(title)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut screen = TextScreen::new(paragraphs)
|
||||||
|
.with_header(header)
|
||||||
|
.with_action_bar(ActionBar::new_double(
|
||||||
|
Button::with_icon(theme::ICON_CROSS),
|
||||||
|
right_button,
|
||||||
|
));
|
||||||
|
if page_counter {
|
||||||
|
screen = screen.with_hint(Hint::new_page_counter());
|
||||||
|
}
|
||||||
|
LayoutObj::new(screen)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn confirm_value_intro(
|
fn confirm_value_intro(
|
||||||
@ -436,12 +479,31 @@ impl FirmwareUI for UIEckhart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_info_with_cancel(
|
fn show_info_with_cancel(
|
||||||
_title: TString<'static>,
|
title: TString<'static>,
|
||||||
_items: Obj,
|
items: Obj,
|
||||||
_horizontal: bool,
|
_horizontal: bool,
|
||||||
_chunkify: bool,
|
chunkify: bool,
|
||||||
) -> Result<impl LayoutMaybeTrace, Error> {
|
) -> Result<impl LayoutMaybeTrace, Error> {
|
||||||
Err::<RootComponent<Empty, ModelUI>, Error>(Error::ValueError(c"not implemented"))
|
let mut paragraphs = ParagraphVecShort::new();
|
||||||
|
for para in IterBuf::new().try_iterate(items)? {
|
||||||
|
let [key, value]: [Obj; 2] = util::iter_into_array(para)?;
|
||||||
|
let key: TString = key.try_into()?;
|
||||||
|
let value: TString = value.try_into()?;
|
||||||
|
paragraphs.add(Paragraph::new(&theme::TEXT_MEDIUM, key).no_break());
|
||||||
|
if chunkify {
|
||||||
|
paragraphs.add(Paragraph::new(
|
||||||
|
theme::get_chunkified_text_style(value.len()),
|
||||||
|
value,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
paragraphs.add(Paragraph::new(&theme::TEXT_MONO_MEDIUM, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let screen = TextScreen::new(paragraphs.into_paragraphs())
|
||||||
|
.with_header(Header::new(title).with_close_button());
|
||||||
|
let layout = RootComponent::new(screen);
|
||||||
|
Ok(layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_lockscreen(
|
fn show_lockscreen(
|
||||||
@ -495,7 +557,7 @@ impl FirmwareUI for UIEckhart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_simple(
|
fn show_simple(
|
||||||
text: TString<'static>,
|
_text: TString<'static>,
|
||||||
_title: Option<TString<'static>>,
|
_title: Option<TString<'static>>,
|
||||||
_button: Option<TString<'static>>,
|
_button: Option<TString<'static>>,
|
||||||
) -> Result<Gc<LayoutObj>, Error> {
|
) -> Result<Gc<LayoutObj>, Error> {
|
||||||
|
Loading…
Reference in New Issue
Block a user