feat(core,rust): TR PIN dialogue going to ENTER when user enters 4th digit

grdddj/tr_pin_entry_4_digits_enter
grdddj 12 months ago
parent 38ca5049f1
commit ff751d4b6e

@ -27,9 +27,12 @@ enum PinAction {
} }
const MAX_PIN_LENGTH: usize = 50; const MAX_PIN_LENGTH: usize = 50;
/// After how many digits the user will be brought to the "ENTER" choice.
const NUM_DIGITS_SWITCH_TO_ENTER: usize = 4;
const CHOICE_LENGTH: usize = 13; const CHOICE_LENGTH: usize = 13;
const NUMBER_START_INDEX: usize = 3; const NUMBER_START_INDEX: usize = 3;
const ENTER_INDEX: usize = 2;
const CHOICES: [(&str, PinAction, Option<Icon>); CHOICE_LENGTH] = [ const CHOICES: [(&str, PinAction, Option<Icon>); CHOICE_LENGTH] = [
("DELETE", PinAction::Delete, Some(theme::ICON_DELETE)), ("DELETE", PinAction::Delete, Some(theme::ICON_DELETE)),
("SHOW", PinAction::Show, Some(theme::ICON_EYE)), ("SHOW", PinAction::Show, Some(theme::ICON_EYE)),
@ -203,15 +206,19 @@ where
Some(PinAction::Enter) => Some(PinEntryMsg::Confirmed), Some(PinAction::Enter) => Some(PinEntryMsg::Confirmed),
Some(PinAction::Digit(ch)) if !self.is_full() => { Some(PinAction::Digit(ch)) if !self.is_full() => {
self.textbox.append(ctx, ch); self.textbox.append(ctx, ch);
// Choosing random digit to be shown next, but different let new_page_counter = if self.textbox.len() == NUM_DIGITS_SWITCH_TO_ENTER {
// from the current choice. // When user has reached certain amount of digits, offering "ENTER" to them
let new_page_counter = random::uniform_between_except( ENTER_INDEX
NUMBER_START_INDEX as u32, } else {
(CHOICE_LENGTH - 1) as u32, // Choosing random digit to be shown next, but different
self.choice_page.page_index() as u32, // from the current choice.
); random::uniform_between_except(
self.choice_page NUMBER_START_INDEX as u32,
.set_page_counter(ctx, new_page_counter as usize); (CHOICE_LENGTH - 1) as u32,
self.choice_page.page_index() as u32,
) as usize
};
self.choice_page.set_page_counter(ctx, new_page_counter);
self.update(ctx); self.update(ctx);
None None
} }

Loading…
Cancel
Save