1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-08-05 13:26:57 +00:00

fix(core): fix Caesar PinEntry to use Title

- Title component uses Marquee internally which scrolls longer prompt
texts
- this fixes e.g. czech translations not fitting the screen
This commit is contained in:
obrusvit 2025-03-11 16:55:29 +01:00 committed by Vít Obrusník
parent 60129f8369
commit 0cd64d6a08
5 changed files with 525 additions and 523 deletions

View File

@ -0,0 +1 @@
[T2B1,T3B1] Fix horizontal scroll of the title when setting Wipe code.

View File

@ -14,8 +14,8 @@ use crate::{
}; };
use super::super::{ use super::super::{
super::fonts, theme, ButtonDetails, ButtonLayout, CancelConfirmMsg, ChangingTextLine, super::fonts, theme, title::Title, ButtonDetails, ButtonLayout, CancelConfirmMsg,
ChoiceControls, ChoiceFactory, ChoiceItem, ChoiceMsg, ChoicePage, ChangingTextLine, ChoiceControls, ChoiceFactory, ChoiceItem, ChoiceMsg, ChoicePage,
}; };
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
@ -136,9 +136,9 @@ impl ChoiceFactory for ChoiceFactoryPIN {
/// Component for entering a PIN. /// Component for entering a PIN.
pub struct PinEntry<'a> { pub struct PinEntry<'a> {
choice_page: ChoicePage<ChoiceFactoryPIN, PinAction>, choice_page: ChoicePage<ChoiceFactoryPIN, PinAction>,
header_line: Child<ChangingTextLine>, header_line: Child<Title>,
pin_line: Child<ChangingTextLine>, pin_line: Child<ChangingTextLine>,
prompt: TString<'a>, prompt: TString<'static>,
subprompt: TString<'a>, subprompt: TString<'a>,
/// Whether we already show the "real" prompt (not the warning). /// Whether we already show the "real" prompt (not the warning).
showing_real_prompt: bool, showing_real_prompt: bool,
@ -149,7 +149,7 @@ pub struct PinEntry<'a> {
} }
impl<'a> PinEntry<'a> { impl<'a> PinEntry<'a> {
pub fn new(prompt: TString<'a>, subprompt: TString<'a>) -> Self { pub fn new(prompt: TString<'static>, subprompt: TString<'a>) -> Self {
// When subprompt is not empty, it means that the user has entered bad PIN // When subprompt is not empty, it means that the user has entered bad PIN
// before. In this case we show the warning together with the subprompt // before. In this case we show the warning together with the subprompt
// at the beginning. (WRONG PIN will be replaced by real prompt after // at the beginning. (WRONG PIN will be replaced by real prompt after
@ -172,12 +172,7 @@ impl<'a> PinEntry<'a> {
choice_page: ChoicePage::new(ChoiceFactoryPIN) choice_page: ChoicePage::new(ChoiceFactoryPIN)
.with_initial_page_counter(get_random_digit_position()) .with_initial_page_counter(get_random_digit_position())
.with_controls(ChoiceControls::Carousel), .with_controls(ChoiceControls::Carousel),
header_line: Child::new( header_line: Child::new(Title::new(header_line_content).with_centered()),
header_line_content
.map(|s| ChangingTextLine::center_bold(s, MAX_PIN_LENGTH))
.without_ellipsis()
.with_text_at_the_top(),
),
pin_line: Child::new(pin_line), pin_line: Child::new(pin_line),
subprompt, subprompt,
prompt, prompt,
@ -236,7 +231,7 @@ impl<'a> PinEntry<'a> {
/// Showing the real prompt instead of WRONG PIN /// Showing the real prompt instead of WRONG PIN
fn show_prompt(&mut self, ctx: &mut EventCtx) { fn show_prompt(&mut self, ctx: &mut EventCtx) {
self.header_line.mutate(ctx, |ctx, header_line| { self.header_line.mutate(ctx, |ctx, header_line| {
self.prompt.map(|s| header_line.update_text(s)); header_line.set_text(ctx, self.prompt);
header_line.request_complete_repaint(ctx); header_line.request_complete_repaint(ctx);
}); });
} }
@ -258,7 +253,8 @@ impl Component for PinEntry<'_> {
type Msg = CancelConfirmMsg; type Msg = CancelConfirmMsg;
fn place(&mut self, bounds: Rect) -> Rect { fn place(&mut self, bounds: Rect) -> Rect {
let header_height = self.header_line.inner().needed_height(); // same adjustment of height as in ChangingTextLine::needed_height()
let header_height = Title::height() + 2;
let (header_area, rest) = bounds.split_top(header_height); let (header_area, rest) = bounds.split_top(header_height);
let pin_height = self.pin_line.inner().needed_height(); let pin_height = self.pin_line.inner().needed_height();
let (pin_area, choice_area) = rest.split_top(pin_height); let (pin_area, choice_area) = rest.split_top(pin_height);
@ -269,6 +265,9 @@ impl Component for PinEntry<'_> {
} }
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> { fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
self.header_line.mutate(ctx, |ctx, title| {
title.event(ctx, event);
});
match event { match event {
// Timeout for showing the last digit. // Timeout for showing the last digit.
Event::Timer(_) if self.timeout_timer.expire(event) => { Event::Timer(_) if self.timeout_timer.expire(event) => {

View File

@ -51,14 +51,17 @@ impl Title {
} }
} }
pub fn height() -> i16 {
theme::FONT_HEADER.text_height()
}
/// Display title/header at the top left of the given area. /// Display title/header at the top left of the given area.
pub fn render_header_left<'s>( pub fn render_header_left<'s>(
target: &mut impl Renderer<'s>, target: &mut impl Renderer<'s>,
title: &TString<'static>, title: &TString<'static>,
area: Rect, area: Rect,
) { ) {
let text_height = theme::FONT_HEADER.text_height(); let title_baseline = area.top_left() + Offset::y(Self::height() - 1);
let title_baseline = area.top_left() + Offset::y(text_height - 1);
title.map(|s| { title.map(|s| {
shape::Text::new(title_baseline, s, theme::FONT_HEADER) shape::Text::new(title_baseline, s, theme::FONT_HEADER)
.with_fg(theme::FG) .with_fg(theme::FG)
@ -72,8 +75,7 @@ impl Title {
title: &TString<'static>, title: &TString<'static>,
area: Rect, area: Rect,
) { ) {
let text_height = theme::FONT_HEADER.text_height(); let title_baseline = area.top_center() + Offset::y(Self::height() - 1);
let title_baseline = area.top_center() + Offset::y(text_height - 1);
title.map(|s| { title.map(|s| {
shape::Text::new(title_baseline, s, theme::FONT_HEADER) shape::Text::new(title_baseline, s, theme::FONT_HEADER)
.with_align(Alignment::Center) .with_align(Alignment::Center)

File diff suppressed because it is too large Load Diff

2
vendor/fido2-tests vendored

@ -1 +1 @@
Subproject commit 737b4960c98b4877653c77ff97a0bb5cfc319213 Subproject commit 4e6d8f5b31a824f1f0270e66274e81bde72fabf1