From 3f0ab537af6e34e56ab72bf367b927e4db88c9d0 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Thu, 16 May 2024 17:10:57 +0200 Subject: [PATCH] feat(core/ui): T3T1 passphrase keyboard [no changelog] --- .../component/keyboard/passphrase.rs | 304 ++++++++++-------- .../model_mercury/component/keyboard/pin.rs | 5 +- .../src/ui/model_mercury/component/mod.rs | 2 + .../ui/model_mercury/component/share_words.rs | 4 +- .../embed/rust/src/ui/model_mercury/layout.rs | 2 +- .../rust/src/ui/model_mercury/theme/mod.rs | 150 +++++---- 6 files changed, 277 insertions(+), 190 deletions(-) diff --git a/core/embed/rust/src/ui/model_mercury/component/keyboard/passphrase.rs b/core/embed/rust/src/ui/model_mercury/component/keyboard/passphrase.rs index ed7aa26c35..645882cee1 100644 --- a/core/embed/rust/src/ui/model_mercury/component/keyboard/passphrase.rs +++ b/core/embed/rust/src/ui/model_mercury/component/keyboard/passphrase.rs @@ -1,16 +1,17 @@ use crate::{ strutil::TString, + translations::TR, ui::{ component::{ - base::ComponentExt, text::common::TextBox, Child, Component, Event, EventCtx, Never, + base::ComponentExt, text::common::TextBox, Child, Component, Event, EventCtx, Label, + Maybe, Never, Swipe, SwipeDirection, }, display, - geometry::{Grid, Offset, Rect}, + geometry::{Alignment, Grid, Insets, Offset, Rect}, model_mercury::component::{ button::{Button, ButtonContent, ButtonMsg}, - keyboard::common::{paint_pending_marker, render_pending_marker, MultiTapKeyboard}, - swipe::{Swipe, SwipeDirection}, - theme, ScrollBar, + keyboard::common::{render_pending_marker, MultiTapKeyboard}, + theme, }, shape, shape::Renderer, @@ -19,57 +20,126 @@ use crate::{ }; use core::cell::Cell; +use num_traits::ToPrimitive; pub enum PassphraseKeyboardMsg { Confirmed, Cancelled, } +/// 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)] +#[derive(Copy, Clone, ToPrimitive)] +enum KeyboardLayout { + LettersLower = 0, + LettersUpper = 1, + Numeric = 2, + Special = 3, +} + +impl KeyboardLayout { + fn next(self) -> Self { + match self { + Self::LettersLower => Self::LettersUpper, + Self::LettersUpper => Self::Numeric, + Self::Numeric => Self::Special, + Self::Special => Self::LettersLower, + } + } + + fn prev(self) -> Self { + match self { + Self::LettersLower => Self::Special, + Self::LettersUpper => Self::LettersLower, + Self::Numeric => Self::LettersUpper, + Self::Special => Self::Numeric, + } + } +} + +impl From for ButtonContent { + /// Used to get content for the "next keyboard" button + fn from(kl: KeyboardLayout) -> Self { + match kl { + KeyboardLayout::LettersLower => ButtonContent::Text("abc".into()), + KeyboardLayout::LettersUpper => ButtonContent::Text("ABC".into()), + KeyboardLayout::Numeric => ButtonContent::Text("123".into()), + KeyboardLayout::Special => ButtonContent::Icon(theme::ICON_ASTERISK), + } + } +} + pub struct PassphraseKeyboard { page_swipe: Swipe, input: Child, - back: Child