1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-03-16 08:06:05 +00:00

fixup! chore(core): show the last passphrase character for a while

This commit is contained in:
Lukas Bielesch 2024-12-04 22:34:00 +01:00
parent dc65c00243
commit 260468fe83
6 changed files with 63 additions and 77 deletions

View File

@ -168,3 +168,13 @@ pub fn render_pill_shape<'s>(
.with_thickness(2)
.render(target);
}
/// `DisplayStyle` isused to determine whether the text is fully hidden, fully
/// shown, or partially visible.
#[derive(PartialEq, Debug, Copy, Clone)]
#[cfg_attr(feature = "ui_debug", derive(ufmt::derive::uDebug))]
pub(crate) enum DisplayStyle {
Hidden,
Shown,
LastOnly,
}

View File

@ -13,7 +13,7 @@ use crate::{
model_mercury::{
component::{
button::{Button, ButtonContent, ButtonMsg},
keyboard::common::{render_pending_marker, MultiTapKeyboard},
keyboard::common::{render_pending_marker, DisplayStyle, MultiTapKeyboard},
theme,
},
cshape,
@ -32,14 +32,6 @@ pub enum PassphraseKeyboardMsg {
Cancelled,
}
#[derive(PartialEq, Debug, Copy, Clone)]
#[cfg_attr(feature = "ui_debug", derive(ufmt::derive::uDebug))]
enum DisplayStyle {
Dots,
Chars,
LastChar,
}
/// Enum keeping track of which keyboard is shown and which comes next. Keep the
/// number of values and the constant PAGE_COUNT in synch.
#[repr(u32)]
@ -415,7 +407,7 @@ impl Component for PassphraseKeyboard {
// multi tap timer is runnig, the last digit timer should be stopped
self.input.last_char_timer.stop();
}
self.input.display_style = DisplayStyle::LastChar;
self.input.display_style = DisplayStyle::LastOnly;
return None;
}
}
@ -462,7 +454,7 @@ impl Input {
area: Rect::zero(),
textbox: TextBox::empty(MAX_LENGTH),
multi_tap: MultiTapKeyboard::new(),
display_style: DisplayStyle::LastChar,
display_style: DisplayStyle::LastOnly,
last_char_timer: Timer::new(),
}
}
@ -486,8 +478,8 @@ impl Input {
// Jiggle hidden passphrase when overflowed.
if chars > truncated.len()
&& chars % 2 == 0
&& (self.display_style == DisplayStyle::Dots
|| self.display_style == DisplayStyle::LastChar)
&& (self.display_style == DisplayStyle::Hidden
|| self.display_style == DisplayStyle::LastOnly)
{
text_baseline.x += Self::TWITCH;
}
@ -516,7 +508,7 @@ impl Input {
let bullet = theme::ICON_PIN_BULLET.toif;
let mut cursor = area.left_center();
let all_chars = self.textbox.content().len();
let last_char = self.display_style == DisplayStyle::LastChar;
let last_char = self.display_style == DisplayStyle::LastOnly;
if all_chars > 0 {
// Find out how much text can fit into the textbox.
@ -533,8 +525,8 @@ impl Input {
// Jiggle when overflowed.
if all_chars > visible_chars
&& all_chars % 2 == 0
&& (self.display_style == DisplayStyle::Dots
|| self.display_style == DisplayStyle::LastChar)
&& (self.display_style == DisplayStyle::Hidden
|| self.display_style == DisplayStyle::LastOnly)
{
cursor.x += Self::TWITCH;
}
@ -601,15 +593,15 @@ impl Component for Input {
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
match event {
Event::Timer(_) if self.last_char_timer.expire(event) => {
self.display_style = DisplayStyle::Dots;
self.display_style = DisplayStyle::Hidden;
ctx.request_paint();
}
Event::Touch(TouchEvent::TouchStart(pos)) if self.area.contains(pos) => {
self.display_style = DisplayStyle::Chars;
self.display_style = DisplayStyle::Shown;
ctx.request_paint();
}
Event::Touch(TouchEvent::TouchEnd(pos)) if self.area.contains(pos) => {
self.display_style = DisplayStyle::Dots;
self.display_style = DisplayStyle::Hidden;
ctx.request_paint();
}
_ => {}
@ -626,7 +618,7 @@ impl Component for Input {
// Paint the passphrase
if !self.textbox.content().is_empty() {
match self.display_style {
DisplayStyle::Chars => self.render_chars(text_area, target),
DisplayStyle::Shown => self.render_chars(text_area, target),
_ => self.render_dots(text_area, target),
}
}

View File

@ -19,6 +19,7 @@ use crate::{
Button, ButtonContent,
ButtonMsg::{self, Clicked},
},
keyboard::common::DisplayStyle,
theme,
},
cshape,
@ -431,7 +432,7 @@ impl Component for PinKeyboard<'_> {
}
// Timeout for showing the last digit.
Event::Timer(_) if self.timeout_timer.expire(event) => {
self.textbox.display_style = DisplayStyle::Dots;
self.textbox.display_style = DisplayStyle::Hidden;
self.textbox.request_complete_repaint(ctx);
ctx.request_paint();
}
@ -482,7 +483,7 @@ impl Component for PinKeyboard<'_> {
self.pin_modified(ctx);
self.timeout_timer
.start(ctx, Duration::from_secs(LAST_DIGIT_TIMEOUT_S));
self.textbox.display_style = DisplayStyle::LastDigit;
self.textbox.display_style = DisplayStyle::LastOnly;
self.textbox.request_complete_repaint(ctx);
ctx.request_paint();
return None;
@ -542,14 +543,6 @@ struct PinDots {
display_style: DisplayStyle,
}
#[derive(PartialEq, Debug, Copy, Clone)]
#[cfg_attr(feature = "ui_debug", derive(ufmt::derive::uDebug))]
enum DisplayStyle {
Dots,
Digits,
LastDigit,
}
impl PinDots {
const DOT: i16 = 6;
const PADDING: i16 = 7;
@ -561,7 +554,7 @@ impl PinDots {
pad: Pad::with_background(style.background_color),
style,
digits: ShortString::new(),
display_style: DisplayStyle::Dots,
display_style: DisplayStyle::Hidden,
}
}
@ -695,14 +688,15 @@ impl Component for PinDots {
match event {
Event::Touch(TouchEvent::TouchStart(pos)) => {
if self.area.contains(pos) {
self.display_style = DisplayStyle::Digits;
self.display_style = DisplayStyle::Shown;
self.pad.clear();
ctx.request_paint();
};
None
}
Event::Touch(TouchEvent::TouchEnd(_)) => {
if mem::replace(&mut self.display_style, DisplayStyle::Dots) == DisplayStyle::Digits
if mem::replace(&mut self.display_style, DisplayStyle::Hidden)
== DisplayStyle::Shown
{
self.pad.clear();
ctx.request_paint();
@ -717,9 +711,9 @@ impl Component for PinDots {
let dot_area = self.area.inset(HEADER_PADDING);
self.pad.render(target);
match self.display_style {
DisplayStyle::Digits => self.render_digits(dot_area, target),
DisplayStyle::Dots => self.render_dots(false, dot_area, target),
DisplayStyle::LastDigit => self.render_dots(true, dot_area, target),
DisplayStyle::Shown => self.render_digits(dot_area, target),
DisplayStyle::Hidden => self.render_dots(false, dot_area, target),
DisplayStyle::LastOnly => self.render_dots(true, dot_area, target),
}
}
}

View File

@ -137,3 +137,13 @@ pub fn render_pending_marker<'s>(
shape::Bar::new(marker_rect).with_bg(color).render(target);
}
}
/// `DisplayStyle` isused to determine whether the text is fully hidden, fully
/// shown, or partially visible.
#[derive(PartialEq, Debug, Copy, Clone)]
#[cfg_attr(feature = "ui_debug", derive(ufmt::derive::uDebug))]
pub(crate) enum DisplayStyle {
Hidden,
Shown,
LastOnly,
}

View File

@ -11,7 +11,7 @@ use crate::{
geometry::{Alignment, Grid, Offset, Rect},
model_tt::component::{
button::{Button, ButtonContent, ButtonMsg},
keyboard::common::{render_pending_marker, MultiTapKeyboard},
keyboard::common::{render_pending_marker, DisplayStyle, MultiTapKeyboard},
swipe::{Swipe, SwipeDirection},
theme, ScrollBar,
},
@ -27,14 +27,6 @@ pub enum PassphraseKeyboardMsg {
Cancelled,
}
#[derive(PartialEq, Debug, Copy, Clone)]
#[cfg_attr(feature = "ui_debug", derive(ufmt::derive::uDebug))]
enum DisplayStyle {
Dots,
Chars,
LastChar,
}
pub struct PassphraseKeyboard {
page_swipe: Swipe,
input: Child<Input>,
@ -324,7 +316,7 @@ impl Component for PassphraseKeyboard {
self.input.mutate(ctx, |_ctx, t| t.stop_timer());
}
self.input
.mutate(ctx, |_ctx, t| t.set_display_style(DisplayStyle::LastChar));
.mutate(ctx, |_ctx, t| t.set_display_style(DisplayStyle::LastOnly));
return None;
}
}
@ -364,7 +356,7 @@ impl Input {
area: Rect::zero(),
textbox: TextBox::empty(MAX_LENGTH),
multi_tap: MultiTapKeyboard::new(),
display_style: DisplayStyle::LastChar,
display_style: DisplayStyle::LastOnly,
last_char_timer: Timer::new(),
}
}
@ -394,15 +386,15 @@ impl Component for Input {
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
match event {
Event::Timer(_) if self.last_char_timer.expire(event) => {
self.display_style = DisplayStyle::Dots;
self.display_style = DisplayStyle::Hidden;
ctx.request_paint();
}
Event::Touch(TouchEvent::TouchStart(pos)) if self.area.contains(pos) => {
self.display_style = DisplayStyle::Chars;
self.display_style = DisplayStyle::Shown;
ctx.request_paint();
}
Event::Touch(TouchEvent::TouchEnd(pos)) if self.area.contains(pos) => {
self.display_style = DisplayStyle::Dots;
self.display_style = DisplayStyle::Hidden;
ctx.request_paint();
}
_ => {}
@ -435,15 +427,15 @@ impl Component for Input {
// Jiggle when overflowed.
if pp_len > pp_visible_len
&& pp_len % 2 == 0
&& !matches!(self.display_style, DisplayStyle::Chars)
&& !matches!(self.display_style, DisplayStyle::Shown)
{
cursor.x += Self::TWITCH;
}
let (visible_dots, visible_chars) = match self.display_style {
DisplayStyle::Dots => (pp_visible_len, 0),
DisplayStyle::Chars => (0, pp_visible_len),
DisplayStyle::LastChar => (pp_visible_len - 1, 1),
DisplayStyle::Hidden => (pp_visible_len, 0),
DisplayStyle::Shown => (0, pp_visible_len),
DisplayStyle::LastOnly => (pp_visible_len - 1, 1),
};
// Render dots if applicable
@ -479,13 +471,7 @@ impl Component for Input {
.render(target);
// Paint the pending marker.
if self.multi_tap.pending_key().is_some() {
render_pending_marker(
target,
cursor,
chars,
style.text_font,
style.text_color,
);
render_pending_marker(target, cursor, chars, style.text_font, style.text_color);
}
}
}

View File

@ -17,6 +17,7 @@ use crate::{
Button, ButtonContent,
ButtonMsg::{self, Clicked},
},
keyboard::common::DisplayStyle,
theme,
},
shape::{self, Renderer},
@ -218,7 +219,7 @@ impl Component for PinKeyboard<'_> {
// Timeout for showing the last digit.
Event::Timer(_) if self.timeout_timer.expire(event) => {
self.textbox
.mutate(ctx, |_ctx, t| t.set_display_style(DisplayStyle::Dots));
.mutate(ctx, |_ctx, t| t.set_display_style(DisplayStyle::Hidden));
self.textbox.request_complete_repaint(ctx);
ctx.request_paint();
}
@ -255,7 +256,7 @@ impl Component for PinKeyboard<'_> {
self.timeout_timer
.start(ctx, Duration::from_secs(LAST_DIGIT_TIMEOUT_S));
self.textbox
.mutate(ctx, |_ctx, t| t.set_display_style(DisplayStyle::LastDigit));
.mutate(ctx, |_ctx, t| t.set_display_style(DisplayStyle::LastOnly));
self.textbox.request_complete_repaint(ctx);
ctx.request_paint();
return None;
@ -294,14 +295,6 @@ struct PinDots {
display_style: DisplayStyle,
}
#[derive(PartialEq, Debug, Copy, Clone)]
#[cfg_attr(feature = "ui_debug", derive(ufmt::derive::uDebug))]
enum DisplayStyle {
Dots,
Digits,
LastDigit,
}
impl PinDots {
const DOT: i16 = 6;
const PADDING: i16 = 6;
@ -315,7 +308,7 @@ impl PinDots {
pad: Pad::with_background(style.background_color),
style,
digits,
display_style: DisplayStyle::Dots,
display_style: DisplayStyle::Hidden,
}
}
@ -450,14 +443,15 @@ impl Component for PinDots {
match event {
Event::Touch(TouchEvent::TouchStart(pos)) => {
if self.area.contains(pos) {
self.display_style = DisplayStyle::Digits;
self.display_style = DisplayStyle::Shown;
self.pad.clear();
ctx.request_paint();
};
None
}
Event::Touch(TouchEvent::TouchEnd(_)) => {
if mem::replace(&mut self.display_style, DisplayStyle::Dots) == DisplayStyle::Digits
if mem::replace(&mut self.display_style, DisplayStyle::Hidden)
== DisplayStyle::Shown
{
self.pad.clear();
ctx.request_paint();
@ -473,9 +467,9 @@ impl Component for PinDots {
self.pad.render(target);
match self.display_style {
DisplayStyle::Digits => self.render_digits(dot_area, target),
DisplayStyle::Dots => self.render_dots(false, dot_area, target),
DisplayStyle::LastDigit => self.render_dots(true, dot_area, target),
DisplayStyle::Shown => self.render_digits(dot_area, target),
DisplayStyle::Hidden => self.render_dots(false, dot_area, target),
DisplayStyle::LastOnly => self.render_dots(true, dot_area, target),
}
}
}