mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-19 12:58:13 +00:00
refactor(core): remove StringType
This commit removes the last usage of StringType. In the future, we use TString. [no changelog]
This commit is contained in:
parent
4e788aa2f5
commit
a01a787113
@ -9,19 +9,6 @@ use crate::micropython::{buffer::StrBuffer, obj::Obj};
|
|||||||
#[cfg(feature = "translations")]
|
#[cfg(feature = "translations")]
|
||||||
use crate::translations::TR;
|
use crate::translations::TR;
|
||||||
|
|
||||||
/// Trait for internal representation of strings. This is a legacy crutch before
|
|
||||||
/// we fully transition to `TString`. For now, it allows some manner of
|
|
||||||
/// compatibility between `&str` and `StrBuffer`. Implies the following
|
|
||||||
/// operations:
|
|
||||||
/// - dereference into a short-lived `&str` reference (AsRef<str>) (probably not
|
|
||||||
/// strictly necessary anymore)
|
|
||||||
/// - create a new string from a string literal (From<&'static str>)
|
|
||||||
/// - infallibly convert into a `TString` (Into<TString<'static>>), which is
|
|
||||||
/// then used for other operations.
|
|
||||||
pub trait StringType: AsRef<str> + From<&'static str> + Into<TString<'static>> {}
|
|
||||||
|
|
||||||
impl<T> StringType for T where T: AsRef<str> + From<&'static str> + Into<TString<'static>> {}
|
|
||||||
|
|
||||||
/// Unified-length String type, long enough for most simple use-cases.
|
/// Unified-length String type, long enough for most simple use-cases.
|
||||||
pub type ShortString = String<50>;
|
pub type ShortString = String<50>;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
strutil::{ShortString, StringType, TString},
|
strutil::{ShortString, TString},
|
||||||
translations::TR,
|
translations::TR,
|
||||||
ui::{
|
ui::{
|
||||||
component::{
|
component::{
|
||||||
@ -27,21 +27,15 @@ const INFO_TOP_OFFSET: i16 = 20;
|
|||||||
const MAX_WORDS: usize = 33; // super-shamir has 33 words, all other have less
|
const MAX_WORDS: usize = 33; // super-shamir has 33 words, all other have less
|
||||||
|
|
||||||
/// Showing the given share words.
|
/// Showing the given share words.
|
||||||
pub struct ShareWords<T>
|
pub struct ShareWords<'a> {
|
||||||
where
|
|
||||||
T: StringType,
|
|
||||||
{
|
|
||||||
area: Rect,
|
area: Rect,
|
||||||
scrollbar: Child<ScrollBar>,
|
scrollbar: Child<ScrollBar>,
|
||||||
share_words: Vec<T, MAX_WORDS>,
|
share_words: Vec<TString<'a>, MAX_WORDS>,
|
||||||
page_index: usize,
|
page_index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ShareWords<T>
|
impl<'a> ShareWords<'a> {
|
||||||
where
|
pub fn new(share_words: Vec<TString<'a>, MAX_WORDS>) -> Self {
|
||||||
T: StringType + Clone,
|
|
||||||
{
|
|
||||||
pub fn new(share_words: Vec<T, MAX_WORDS>) -> Self {
|
|
||||||
let mut instance = Self {
|
let mut instance = Self {
|
||||||
area: Rect::zero(),
|
area: Rect::zero(),
|
||||||
scrollbar: Child::new(ScrollBar::to_be_filled_later()),
|
scrollbar: Child::new(ScrollBar::to_be_filled_later()),
|
||||||
@ -117,11 +111,13 @@ where
|
|||||||
if index >= self.share_words.len() {
|
if index >= self.share_words.len() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let word = &self.share_words[index];
|
|
||||||
let baseline = self.area.top_left() + Offset::y(y_offset);
|
let baseline = self.area.top_left() + Offset::y(y_offset);
|
||||||
let ordinal = uformat!("{}.", index + 1);
|
let ordinal = uformat!("{}.", index + 1);
|
||||||
display_left(baseline + Offset::x(NUMBER_X_OFFSET), &ordinal, NUMBER_FONT);
|
display_left(baseline + Offset::x(NUMBER_X_OFFSET), &ordinal, NUMBER_FONT);
|
||||||
display_left(baseline + Offset::x(WORD_X_OFFSET), word, WORD_FONT);
|
let word = &self.share_words[index];
|
||||||
|
word.map(|w| {
|
||||||
|
display_left(baseline + Offset::x(WORD_X_OFFSET), w, WORD_FONT);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,18 +140,17 @@ where
|
|||||||
.with_fg(theme::FG)
|
.with_fg(theme::FG)
|
||||||
.render(target);
|
.render(target);
|
||||||
|
|
||||||
shape::Text::new(baseline + Offset::x(WORD_X_OFFSET), word.as_ref())
|
word.map(|w| {
|
||||||
.with_font(WORD_FONT)
|
shape::Text::new(baseline + Offset::x(WORD_X_OFFSET), w)
|
||||||
.with_fg(theme::FG)
|
.with_font(WORD_FONT)
|
||||||
.render(target);
|
.with_fg(theme::FG)
|
||||||
|
.render(target);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Component for ShareWords<T>
|
impl<'a> Component for ShareWords<'a> {
|
||||||
where
|
|
||||||
T: StringType + Clone,
|
|
||||||
{
|
|
||||||
type Msg = Never;
|
type Msg = Never;
|
||||||
|
|
||||||
fn place(&mut self, bounds: Rect) -> Rect {
|
fn place(&mut self, bounds: Rect) -> Rect {
|
||||||
@ -198,10 +193,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Paginate for ShareWords<T>
|
impl<'a> Paginate for ShareWords<'a> {
|
||||||
where
|
|
||||||
T: StringType + Clone,
|
|
||||||
{
|
|
||||||
fn page_count(&mut self) -> usize {
|
fn page_count(&mut self) -> usize {
|
||||||
// Not defining the logic here, as we do not want it to be `&mut`.
|
// Not defining the logic here, as we do not want it to be `&mut`.
|
||||||
self.total_page_count()
|
self.total_page_count()
|
||||||
@ -216,10 +208,7 @@ where
|
|||||||
// DEBUG-ONLY SECTION BELOW
|
// DEBUG-ONLY SECTION BELOW
|
||||||
|
|
||||||
#[cfg(feature = "ui_debug")]
|
#[cfg(feature = "ui_debug")]
|
||||||
impl<T> crate::trace::Trace for ShareWords<T>
|
impl<'a> crate::trace::Trace for ShareWords<'a> {
|
||||||
where
|
|
||||||
T: StringType + Clone,
|
|
||||||
{
|
|
||||||
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
|
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
|
||||||
t.component("ShareWords");
|
t.component("ShareWords");
|
||||||
let content = if self.is_final_page() {
|
let content = if self.is_final_page() {
|
||||||
@ -231,8 +220,8 @@ where
|
|||||||
if index >= self.share_words.len() {
|
if index >= self.share_words.len() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let word: TString = self.share_words[index].clone().into();
|
self.share_words[index]
|
||||||
unwrap!(uwrite!(content, "{}. {}\n", index + 1, word));
|
.map(|word| unwrap!(uwrite!(content, "{}. {}\n", index + 1, word)));
|
||||||
}
|
}
|
||||||
content
|
content
|
||||||
};
|
};
|
||||||
|
@ -6,7 +6,6 @@ use crate::{
|
|||||||
error::Error,
|
error::Error,
|
||||||
maybe_trace::MaybeTrace,
|
maybe_trace::MaybeTrace,
|
||||||
micropython::{
|
micropython::{
|
||||||
buffer::StrBuffer,
|
|
||||||
gc::Gc,
|
gc::Gc,
|
||||||
iter::IterBuf,
|
iter::IterBuf,
|
||||||
list::List,
|
list::List,
|
||||||
@ -1331,7 +1330,7 @@ extern "C" fn new_select_word(n_args: usize, args: *const Obj, kwargs: *mut Map)
|
|||||||
extern "C" fn new_show_share_words(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
extern "C" fn new_show_share_words(n_args: usize, args: *const Obj, kwargs: *mut Map) -> Obj {
|
||||||
let block = |_args: &[Obj], kwargs: &Map| {
|
let block = |_args: &[Obj], kwargs: &Map| {
|
||||||
let share_words_obj: Obj = kwargs.get(Qstr::MP_QSTR_share_words)?;
|
let share_words_obj: Obj = kwargs.get(Qstr::MP_QSTR_share_words)?;
|
||||||
let share_words: Vec<StrBuffer, 33> = util::iter_into_vec(share_words_obj)?;
|
let share_words: Vec<TString, 33> = util::iter_into_vec(share_words_obj)?;
|
||||||
|
|
||||||
let cancel_btn = Some(ButtonDetails::up_arrow_icon());
|
let cancel_btn = Some(ButtonDetails::up_arrow_icon());
|
||||||
let confirm_btn =
|
let confirm_btn =
|
||||||
|
Loading…
Reference in New Issue
Block a user