From 4d60c10330e30830e3bdfd4f9069c5987c5253d5 Mon Sep 17 00:00:00 2001 From: Martin Milata Date: Mon, 2 Aug 2021 22:23:19 +0200 Subject: [PATCH] feat(core/rust): add support for T1 UI [no changelog] --- core/SConscript.firmware | 7 ++- core/SConscript.unix | 7 ++- core/embed/rust/Cargo.toml | 3 + core/embed/rust/librust_qstr.h | 4 +- core/embed/rust/src/micropython/buffer.rs | 7 +++ core/embed/rust/src/micropython/map.rs | 2 + core/embed/rust/src/trezorhal/display.rs | 3 +- core/embed/rust/src/trezorhal/mod.rs | 1 + core/embed/rust/src/ui/component/base.rs | 6 +- .../src/ui/component/{model_tt => }/empty.rs | 0 .../src/ui/component/{model_tt => }/label.rs | 0 core/embed/rust/src/ui/component/mod.rs | 8 ++- .../rust/src/ui/component/model_t1/mod.rs | 2 + .../src/ui/component/{model_tt => }/text.rs | 2 +- core/embed/rust/src/ui/display.rs | 11 ++-- core/embed/rust/src/ui/layout/mod.rs | 3 +- core/embed/rust/src/ui/layout/obj.rs | 48 +++++---------- core/embed/rust/src/ui/macros.rs | 1 + core/embed/rust/src/ui/mod.rs | 3 + core/embed/rust/src/ui/model_t1/constant.rs | 4 ++ core/embed/rust/src/ui/model_t1/event.rs | 29 +++++++++ core/embed/rust/src/ui/model_t1/mod.rs | 3 + core/embed/rust/src/ui/model_t1/theme.rs | 61 +++++++++++++++++++ .../model_tt => model_tt/component}/button.rs | 9 ++- .../model_tt => model_tt/component}/dialog.rs | 0 .../model_tt => model_tt/component}/mod.rs | 10 +-- .../model_tt => model_tt/component}/page.rs | 0 .../component}/passphrase.rs | 0 .../model_tt => model_tt/component}/pin.rs | 6 +- .../model_tt => model_tt/component}/swipe.rs | 8 +-- core/embed/rust/src/ui/model_tt/constant.rs | 4 ++ core/embed/rust/src/ui/model_tt/event.rs | 24 ++++++++ .../{layout/example.rs => model_tt/layout.rs} | 11 ++-- core/embed/rust/src/ui/model_tt/mod.rs | 5 ++ .../src/ui/{component => }/model_tt/theme.rs | 4 +- core/src/trezor/ui/__init__.py | 10 ++- 36 files changed, 220 insertions(+), 86 deletions(-) rename core/embed/rust/src/ui/component/{model_tt => }/empty.rs (100%) rename core/embed/rust/src/ui/component/{model_tt => }/label.rs (100%) rename core/embed/rust/src/ui/component/{model_tt => }/text.rs (99%) create mode 100644 core/embed/rust/src/ui/model_t1/constant.rs create mode 100644 core/embed/rust/src/ui/model_t1/event.rs create mode 100644 core/embed/rust/src/ui/model_t1/mod.rs create mode 100644 core/embed/rust/src/ui/model_t1/theme.rs rename core/embed/rust/src/ui/{component/model_tt => model_tt/component}/button.rs (96%) rename core/embed/rust/src/ui/{component/model_tt => model_tt/component}/dialog.rs (100%) rename core/embed/rust/src/ui/{component/model_tt => model_tt/component}/mod.rs (57%) rename core/embed/rust/src/ui/{component/model_tt => model_tt/component}/page.rs (100%) rename core/embed/rust/src/ui/{component/model_tt => model_tt/component}/passphrase.rs (100%) rename core/embed/rust/src/ui/{component/model_tt => model_tt/component}/pin.rs (98%) rename core/embed/rust/src/ui/{component/model_tt => model_tt/component}/swipe.rs (93%) create mode 100644 core/embed/rust/src/ui/model_tt/constant.rs create mode 100644 core/embed/rust/src/ui/model_tt/event.rs rename core/embed/rust/src/ui/{layout/example.rs => model_tt/layout.rs} (95%) create mode 100644 core/embed/rust/src/ui/model_tt/mod.rs rename core/embed/rust/src/ui/{component => }/model_tt/theme.rs (95%) diff --git a/core/SConscript.firmware b/core/SConscript.firmware index 21afcf0fe..d5a5b28f0 100644 --- a/core/SConscript.firmware +++ b/core/SConscript.firmware @@ -701,7 +701,10 @@ def cargo_build(): profile = '--release' else: profile = '' - features = [] + if TREZOR_MODEL == "1": + features = ["model_t1"] + else: + features = ["model_tt"] if BITCOIN_ONLY == "1": features.append("bitcoin_only") if NEW_UI: @@ -709,7 +712,7 @@ def cargo_build(): if PYOPT == "0": features.append("ui_debug") - return f'cd embed/rust; cargo build {profile} --target={RUST_TARGET} --target-dir=../../build/firmware/rust --features "{" ".join(features)}"' + return f'cd embed/rust; cargo build {profile} --target={RUST_TARGET} --target-dir=../../build/firmware/rust --no-default-features --features "{" ".join(features)}"' rust = env.Command( target=RUST_LIBPATH, diff --git a/core/SConscript.unix b/core/SConscript.unix index 3601a0e17..6da55c542 100644 --- a/core/SConscript.unix +++ b/core/SConscript.unix @@ -653,7 +653,10 @@ def cargo_build(): profile = '--release' else: profile = '' - features = [] + if TREZOR_MODEL == "1": + features = ["model_t1"] + else: + features = ["model_tt"] if BITCOIN_ONLY == "1": features.append("bitcoin_only") if PYOPT == "0": @@ -662,7 +665,7 @@ def cargo_build(): elif NEW_UI: features.append("ui") - return f'cd embed/rust; cargo build {profile} --target-dir=../../build/unix/rust --features "{" ".join(features)}"' + return f'cd embed/rust; cargo build {profile} --target-dir=../../build/unix/rust --no-default-features --features "{" ".join(features)}"' rust = env.Command( target=RUST_LIBPATH, diff --git a/core/embed/rust/Cargo.toml b/core/embed/rust/Cargo.toml index 659cad4aa..e92087d98 100644 --- a/core/embed/rust/Cargo.toml +++ b/core/embed/rust/Cargo.toml @@ -7,7 +7,10 @@ resolver = "2" build = "build.rs" [features] +default = ["model_tt"] bitcoin_only = [] +model_tt = [] +model_t1 = [] ui = [] ui_debug = [] test = ["cc", "glob"] diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index f187369bc..5ba63f731 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -12,9 +12,7 @@ static void _librust_qstrs(void) { // layout MP_QSTR_Layout; MP_QSTR_set_timer_fn; - MP_QSTR_touch_start; - MP_QSTR_touch_move; - MP_QSTR_touch_end; + MP_QSTR_hid_event; MP_QSTR_timer; MP_QSTR_paint; MP_QSTR_trace; diff --git a/core/embed/rust/src/micropython/buffer.rs b/core/embed/rust/src/micropython/buffer.rs index 219b56d3d..27d672365 100644 --- a/core/embed/rust/src/micropython/buffer.rs +++ b/core/embed/rust/src/micropython/buffer.rs @@ -164,3 +164,10 @@ fn buffer_as_mut<'a>(ptr: *mut u8, len: usize) -> &'a mut [u8] { unsafe { slice::from_raw_parts_mut(ptr, len) } } } + +#[cfg(feature = "ui_debug")] +impl crate::trace::Trace for Buffer { + fn trace(&self, t: &mut dyn crate::trace::Tracer) { + self.as_ref().trace(t) + } +} diff --git a/core/embed/rust/src/micropython/map.rs b/core/embed/rust/src/micropython/map.rs index ab3c13884..9c20f838d 100644 --- a/core/embed/rust/src/micropython/map.rs +++ b/core/embed/rust/src/micropython/map.rs @@ -37,6 +37,8 @@ impl Map { value, } } + + pub const EMPTY: Map = Self::from_fixed_static::<0>(&[]); } impl Map { diff --git a/core/embed/rust/src/trezorhal/display.rs b/core/embed/rust/src/trezorhal/display.rs index b07044d67..4a4f8fd46 100644 --- a/core/embed/rust/src/trezorhal/display.rs +++ b/core/embed/rust/src/trezorhal/display.rs @@ -44,8 +44,7 @@ extern "C" { ) -> bool; } -const WIDTH: i32 = 240; -const HEIGHT: i32 = 240; +use crate::ui::component::model::constants::{HEIGHT, WIDTH}; pub struct ToifInfo { pub width: u16, diff --git a/core/embed/rust/src/trezorhal/mod.rs b/core/embed/rust/src/trezorhal/mod.rs index 3cf8ab10e..3bd5157b8 100644 --- a/core/embed/rust/src/trezorhal/mod.rs +++ b/core/embed/rust/src/trezorhal/mod.rs @@ -1,3 +1,4 @@ pub mod common; +#[cfg(feature = "ui")] pub mod display; pub mod random; diff --git a/core/embed/rust/src/ui/component/base.rs b/core/embed/rust/src/ui/component/base.rs index 3c593bba3..ddd32d6b6 100644 --- a/core/embed/rust/src/ui/component/base.rs +++ b/core/embed/rust/src/ui/component/base.rs @@ -2,7 +2,7 @@ use core::{mem, time::Duration}; use heapless::Vec; -use crate::ui::geometry::Point; +use crate::ui::{model_t1::event::ButtonEvent, model_tt::event::TouchEvent}; /// Type used by components that do not return any messages. /// @@ -81,9 +81,7 @@ where #[derive(Copy, Clone, PartialEq, Eq)] pub enum Event { - TouchStart(Point), - TouchMove(Point), - TouchEnd(Point), + HumanInput(HidEvent), Timer(TimerToken), } diff --git a/core/embed/rust/src/ui/component/model_tt/empty.rs b/core/embed/rust/src/ui/component/empty.rs similarity index 100% rename from core/embed/rust/src/ui/component/model_tt/empty.rs rename to core/embed/rust/src/ui/component/empty.rs diff --git a/core/embed/rust/src/ui/component/model_tt/label.rs b/core/embed/rust/src/ui/component/label.rs similarity index 100% rename from core/embed/rust/src/ui/component/model_tt/label.rs rename to core/embed/rust/src/ui/component/label.rs diff --git a/core/embed/rust/src/ui/component/mod.rs b/core/embed/rust/src/ui/component/mod.rs index 2159f31f9..49a0a40d8 100644 --- a/core/embed/rust/src/ui/component/mod.rs +++ b/core/embed/rust/src/ui/component/mod.rs @@ -1,5 +1,9 @@ mod base; -pub mod model_t1; -pub mod model_tt; +pub mod empty; +pub mod label; +pub mod text; pub use base::{Child, Component, Event, EventCtx, Never, TimerToken}; +pub use empty::Empty; +pub use label::{Label, LabelStyle}; +pub use text::{LineBreaking, PageBreaking, Text, TextLayout}; diff --git a/core/embed/rust/src/ui/component/model_t1/mod.rs b/core/embed/rust/src/ui/component/model_t1/mod.rs index 8b1378917..71f6f2a97 100644 --- a/core/embed/rust/src/ui/component/model_t1/mod.rs +++ b/core/embed/rust/src/ui/component/model_t1/mod.rs @@ -1 +1,3 @@ +pub mod constants; +pub mod theme; diff --git a/core/embed/rust/src/ui/component/model_tt/text.rs b/core/embed/rust/src/ui/component/text.rs similarity index 99% rename from core/embed/rust/src/ui/component/model_tt/text.rs rename to core/embed/rust/src/ui/component/text.rs index 0bc2f067a..aedfd168a 100644 --- a/core/embed/rust/src/ui/component/model_tt/text.rs +++ b/core/embed/rust/src/ui/component/text.rs @@ -12,7 +12,7 @@ use crate::ui::{ geometry::{Offset, Point, Rect}, }; -use super::theme; +use super::model::theme; pub const MAX_ARGUMENTS: usize = 6; diff --git a/core/embed/rust/src/ui/display.rs b/core/embed/rust/src/ui/display.rs index 5eb19e017..ad165363d 100644 --- a/core/embed/rust/src/ui/display.rs +++ b/core/embed/rust/src/ui/display.rs @@ -1,6 +1,9 @@ use crate::trezorhal::display; -use super::geometry::{Offset, Point, Rect}; +use super::{ + component::model::constants, + geometry::{Offset, Point, Rect}, +}; pub fn width() -> i32 { display::width() @@ -73,13 +76,11 @@ pub fn text_width(text: &[u8], font: Font) -> i32 { } pub fn text_height() -> i32 { - const TEXT_HEIGHT: i32 = 16; - TEXT_HEIGHT + constants::TEXT_HEIGHT } pub fn line_height() -> i32 { - const LINE_HEIGHT: i32 = 26; - LINE_HEIGHT + constants::LINE_HEIGHT } #[derive(Copy, Clone, PartialEq, Eq)] diff --git a/core/embed/rust/src/ui/layout/mod.rs b/core/embed/rust/src/ui/layout/mod.rs index d35a4ffe3..6c9971772 100644 --- a/core/embed/rust/src/ui/layout/mod.rs +++ b/core/embed/rust/src/ui/layout/mod.rs @@ -1,2 +1 @@ -mod example; -mod obj; +pub mod obj; diff --git a/core/embed/rust/src/ui/layout/obj.rs b/core/embed/rust/src/ui/layout/obj.rs index 9ccb3450a..d2fa82b07 100644 --- a/core/embed/rust/src/ui/layout/obj.rs +++ b/core/embed/rust/src/ui/layout/obj.rs @@ -13,10 +13,7 @@ use crate::{ qstr::Qstr, typ::Type, }, - ui::{ - component::{Child, Component, Event, EventCtx, Never, TimerToken}, - geometry::Point, - }, + ui::component::{model::HidEvent, Child, Component, Event, EventCtx, Never, TimerToken}, util, }; @@ -207,9 +204,7 @@ impl LayoutObj { name: Qstr::MP_QSTR_Layout, locals: &obj_dict!(obj_map! { Qstr::MP_QSTR_set_timer_fn => obj_fn_2!(ui_layout_set_timer_fn).as_obj(), - Qstr::MP_QSTR_touch_start => obj_fn_3!(ui_layout_touch_start).as_obj(), - Qstr::MP_QSTR_touch_move => obj_fn_3!(ui_layout_touch_move).as_obj(), - Qstr::MP_QSTR_touch_end => obj_fn_3!(ui_layout_touch_end).as_obj(), + Qstr::MP_QSTR_hid_event => obj_fn_var!(4, 4, ui_layout_hid_event).as_obj(), Qstr::MP_QSTR_timer => obj_fn_2!(ui_layout_timer).as_obj(), Qstr::MP_QSTR_paint => obj_fn_1!(ui_layout_paint).as_obj(), Qstr::MP_QSTR_trace => obj_fn_2!(ui_layout_trace).as_obj(), @@ -286,34 +281,21 @@ extern "C" fn ui_layout_set_timer_fn(this: Obj, timer_fn: Obj) -> Obj { unsafe { util::try_or_raise(block) } } -extern "C" fn ui_layout_touch_start(this: Obj, x: Obj, y: Obj) -> Obj { - let block = || { - let this: Gc = this.try_into()?; - let event = Event::TouchStart(Point::new(x.try_into()?, y.try_into()?)); - let msg = this.obj_event(event)?; - Ok(msg) - }; - unsafe { util::try_or_raise(block) } -} - -extern "C" fn ui_layout_touch_move(this: Obj, x: Obj, y: Obj) -> Obj { - let block = || { - let this: Gc = this.try_into()?; - let event = Event::TouchMove(Point::new(x.try_into()?, y.try_into()?)); - let msg = this.obj_event(event)?; - Ok(msg) - }; - unsafe { util::try_or_raise(block) } -} - -extern "C" fn ui_layout_touch_end(this: Obj, x: Obj, y: Obj) -> Obj { - let block = || { - let this: Gc = this.try_into()?; - let event = Event::TouchEnd(Point::new(x.try_into()?, y.try_into()?)); - let msg = this.obj_event(event)?; +extern "C" fn ui_layout_hid_event(n_args: usize, args: *const Obj) -> Obj { + let block = |args: &[Obj], _kwargs: &Map| { + if args.len() != 4 { + return Err(Error::TypeError); + } + let this: Gc = args[0].try_into()?; + let event = HidEvent::new( + args[1].try_into()?, + args[2].try_into()?, + args[3].try_into()?, + )?; + let msg = this.obj_event(Event::HumanInput(event))?; Ok(msg) }; - unsafe { util::try_or_raise(block) } + unsafe { util::try_with_args_and_kwargs(n_args, args, &Map::EMPTY, block) } } extern "C" fn ui_layout_timer(this: Obj, token: Obj) -> Obj { diff --git a/core/embed/rust/src/ui/macros.rs b/core/embed/rust/src/ui/macros.rs index da224781b..87f637049 100644 --- a/core/embed/rust/src/ui/macros.rs +++ b/core/embed/rust/src/ui/macros.rs @@ -1,3 +1,4 @@ +#[allow(unused_macros)] // T1 doesn't use icons (yet) macro_rules! include_res { ($filename:expr) => { include_bytes!(concat!( diff --git a/core/embed/rust/src/ui/mod.rs b/core/embed/rust/src/ui/mod.rs index 049971491..20c33d6fd 100644 --- a/core/embed/rust/src/ui/mod.rs +++ b/core/embed/rust/src/ui/mod.rs @@ -5,3 +5,6 @@ pub mod component; pub mod display; pub mod geometry; pub mod layout; + +pub mod model_t1; +pub mod model_tt; diff --git a/core/embed/rust/src/ui/model_t1/constant.rs b/core/embed/rust/src/ui/model_t1/constant.rs new file mode 100644 index 000000000..fae6622f0 --- /dev/null +++ b/core/embed/rust/src/ui/model_t1/constant.rs @@ -0,0 +1,4 @@ +pub const WIDTH: i32 = 128; +pub const HEIGHT: i32 = 64; +pub const TEXT_HEIGHT: i32 = 8; +pub const LINE_HEIGHT: i32 = 9; diff --git a/core/embed/rust/src/ui/model_t1/event.rs b/core/embed/rust/src/ui/model_t1/event.rs new file mode 100644 index 000000000..5676592e5 --- /dev/null +++ b/core/embed/rust/src/ui/model_t1/event.rs @@ -0,0 +1,29 @@ +use crate::error; + +#[derive(Copy, Clone, PartialEq, Eq)] +pub enum T1Button { + Left, + Right, +} + +#[derive(Copy, Clone, PartialEq, Eq)] +pub enum ButtonEvent { + ButtonPressed(T1Button), + ButtonReleased(T1Button), +} + +impl ButtonEvent { + pub fn new(event: u32, button: u32, _unused: u32) -> Result { + let button = match button { + 0 => T1Button::Left, + 1 => T1Button::Right, + _ => return Err(error::Error::OutOfRange), + }; + let result = match event { + 1 => Self::ButtonPressed(button), + 2 => Self::ButtonReleased(button), + _ => return Err(error::Error::OutOfRange), + }; + Ok(result) + } +} diff --git a/core/embed/rust/src/ui/model_t1/mod.rs b/core/embed/rust/src/ui/model_t1/mod.rs new file mode 100644 index 000000000..41cf659b4 --- /dev/null +++ b/core/embed/rust/src/ui/model_t1/mod.rs @@ -0,0 +1,3 @@ +pub mod constant; +pub mod event; +pub mod theme; diff --git a/core/embed/rust/src/ui/model_t1/theme.rs b/core/embed/rust/src/ui/model_t1/theme.rs new file mode 100644 index 000000000..7739ad96e --- /dev/null +++ b/core/embed/rust/src/ui/model_t1/theme.rs @@ -0,0 +1,61 @@ +use crate::ui::display::{Color, Font}; + +use super::component::{ButtonStyle, ButtonStyleSheet}; + +// Font constants. +pub const FONT_NORMAL: Font = Font::new(-1); +pub const FONT_BOLD: Font = Font::new(-2); +pub const FONT_MONO: Font = Font::new(-3); + +// Color palette. +pub const WHITE: Color = Color::rgb(255, 255, 255); +pub const BLACK: Color = Color::rgb(0, 0, 0); +pub const GREY_LIGHT: Color = WHITE; // Word/page break characters. +pub const FG: Color = WHITE; // Default foreground (text & icon) color. +pub const BG: Color = BLACK; // Default background color. + +pub fn button_default() -> ButtonStyleSheet { + ButtonStyleSheet { + normal: &ButtonStyle { + font: FONT_BOLD, + text_color: BG, + background_color: FG, + border_horiz: true, + }, + active: &ButtonStyle { + font: FONT_BOLD, + text_color: FG, + background_color: BG, + border_horiz: true, + }, + disabled: &ButtonStyle { + font: FONT_BOLD, + text_color: FG, + background_color: BG, + border_horiz: true, + }, + } +} + +pub fn button_cancel() -> ButtonStyleSheet { + ButtonStyleSheet { + normal: &ButtonStyle { + font: FONT_BOLD, + text_color: FG, + background_color: BG, + border_horiz: false, + }, + active: &ButtonStyle { + font: FONT_BOLD, + text_color: BG, + background_color: FG, + border_horiz: false, + }, + disabled: &ButtonStyle { + font: FONT_BOLD, + text_color: BG, + background_color: FG, + border_horiz: false, + }, + } +} diff --git a/core/embed/rust/src/ui/component/model_tt/button.rs b/core/embed/rust/src/ui/model_tt/component/button.rs similarity index 96% rename from core/embed/rust/src/ui/component/model_tt/button.rs rename to core/embed/rust/src/ui/model_tt/component/button.rs index a58700155..ba2e7f79c 100644 --- a/core/embed/rust/src/ui/component/model_tt/button.rs +++ b/core/embed/rust/src/ui/model_tt/component/button.rs @@ -3,8 +3,7 @@ use crate::ui::{ display::{self, Color, Font}, geometry::{Offset, Rect}, }; - -use super::theme; +use super::event::TouchEvent; pub enum ButtonMsg { Clicked, @@ -79,7 +78,7 @@ impl Component for Button { fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option { match event { - Event::TouchStart(pos) => { + Event::Touch(TouchEvent::TouchStart(pos)) => { match self.state { State::Disabled => { // Do nothing. @@ -92,7 +91,7 @@ impl Component for Button { } } } - Event::TouchMove(pos) => { + Event::Touch(TouchEvent::TouchMove(pos)) => { match self.state { State::Released if self.area.contains(pos) => { // Touch entered our area, transform to `Pressed` state. @@ -107,7 +106,7 @@ impl Component for Button { } } } - Event::TouchEnd(pos) => { + Event::Touch(TouchEvent::TouchEnd(pos)) => { match self.state { State::Initial | State::Disabled => { // Do nothing. diff --git a/core/embed/rust/src/ui/component/model_tt/dialog.rs b/core/embed/rust/src/ui/model_tt/component/dialog.rs similarity index 100% rename from core/embed/rust/src/ui/component/model_tt/dialog.rs rename to core/embed/rust/src/ui/model_tt/component/dialog.rs diff --git a/core/embed/rust/src/ui/component/model_tt/mod.rs b/core/embed/rust/src/ui/model_tt/component/mod.rs similarity index 57% rename from core/embed/rust/src/ui/component/model_tt/mod.rs rename to core/embed/rust/src/ui/model_tt/component/mod.rs index 46287cde8..2500dd5a0 100644 --- a/core/embed/rust/src/ui/component/model_tt/mod.rs +++ b/core/embed/rust/src/ui/model_tt/component/mod.rs @@ -1,17 +1,13 @@ mod button; mod dialog; -mod empty; -mod label; mod page; mod passphrase; mod pin; mod swipe; -pub mod text; -pub mod theme; pub use button::{Button, ButtonContent, ButtonMsg, ButtonStyle, ButtonStyleSheet}; pub use dialog::{Dialog, DialogMsg}; -pub use empty::Empty; -pub use label::{Label, LabelStyle}; pub use swipe::{Swipe, SwipeDirection}; -pub use text::{LineBreaking, PageBreaking, Text, TextLayout}; + +use super::event; +use super::theme; diff --git a/core/embed/rust/src/ui/component/model_tt/page.rs b/core/embed/rust/src/ui/model_tt/component/page.rs similarity index 100% rename from core/embed/rust/src/ui/component/model_tt/page.rs rename to core/embed/rust/src/ui/model_tt/component/page.rs diff --git a/core/embed/rust/src/ui/component/model_tt/passphrase.rs b/core/embed/rust/src/ui/model_tt/component/passphrase.rs similarity index 100% rename from core/embed/rust/src/ui/component/model_tt/passphrase.rs rename to core/embed/rust/src/ui/model_tt/component/passphrase.rs diff --git a/core/embed/rust/src/ui/component/model_tt/pin.rs b/core/embed/rust/src/ui/model_tt/component/pin.rs similarity index 98% rename from core/embed/rust/src/ui/component/model_tt/pin.rs rename to core/embed/rust/src/ui/model_tt/component/pin.rs index 21793ab03..5717fdf94 100644 --- a/core/embed/rust/src/ui/component/model_tt/pin.rs +++ b/core/embed/rust/src/ui/model_tt/component/pin.rs @@ -3,7 +3,10 @@ use heapless::Vec; use crate::{ trezorhal::random, ui::{ - component::{Child, Component, Event, EventCtx, Never}, + component::{ + label::{Label, LabelStyle}, + Child, Component, Event, EventCtx, Never, + }, display, geometry::{Grid, Offset, Point, Rect}, }, @@ -11,7 +14,6 @@ use crate::{ use super::{ button::{Button, ButtonContent, ButtonMsg::Clicked}, - label::{Label, LabelStyle}, theme, }; diff --git a/core/embed/rust/src/ui/component/model_tt/swipe.rs b/core/embed/rust/src/ui/model_tt/component/swipe.rs similarity index 93% rename from core/embed/rust/src/ui/component/model_tt/swipe.rs rename to core/embed/rust/src/ui/model_tt/component/swipe.rs index 6e9a89384..1835f3cd9 100644 --- a/core/embed/rust/src/ui/component/model_tt/swipe.rs +++ b/core/embed/rust/src/ui/model_tt/component/swipe.rs @@ -4,7 +4,7 @@ use crate::ui::{ geometry::{Point, Rect}, }; -use super::theme; +use super::{theme, event::TouchEvent}; pub enum SwipeDirection { Up, @@ -86,11 +86,11 @@ impl Component for Swipe { fn event(&mut self, _ctx: &mut EventCtx, event: Event) -> Option { match (event, self.origin) { - (Event::TouchStart(pos), _) if self.area.contains(pos) => { + (Event::Touch(TouchEvent::TouchStart(pos)), _) if self.area.contains(pos) => { // Mark the starting position of this touch. self.origin.replace(pos); } - (Event::TouchMove(pos), Some(origin)) => { + (Event::Touch(TouchEvent::TouchMove(pos)), Some(origin)) => { // Consider our allowed directions and the touch distance and modify the display // backlight accordingly. let ofs = pos - origin; @@ -107,7 +107,7 @@ impl Component for Swipe { } }; } - (Event::TouchEnd(pos), Some(origin)) => { + (Event::Touch(TouchEvent::TouchEnd(pos)), Some(origin)) => { // Touch interaction is over, reset the position. self.origin.take(); diff --git a/core/embed/rust/src/ui/model_tt/constant.rs b/core/embed/rust/src/ui/model_tt/constant.rs new file mode 100644 index 000000000..d43903b24 --- /dev/null +++ b/core/embed/rust/src/ui/model_tt/constant.rs @@ -0,0 +1,4 @@ +pub const WIDTH: i32 = 240; +pub const HEIGHT: i32 = 240; +pub const TEXT_HEIGHT: i32 = 16; +pub const LINE_HEIGHT: i32 = 26; diff --git a/core/embed/rust/src/ui/model_tt/event.rs b/core/embed/rust/src/ui/model_tt/event.rs new file mode 100644 index 000000000..cfc7192e6 --- /dev/null +++ b/core/embed/rust/src/ui/model_tt/event.rs @@ -0,0 +1,24 @@ +use core::convert::TryInto; + +use crate::{error, ui::geometry::Point}; + + +#[derive(Copy, Clone, PartialEq, Eq)] +pub enum TouchEvent { + TouchStart(Point), + TouchMove(Point), + TouchEnd(Point), +} + +impl TouchEvent { + pub fn new(event: u32, x: u32, y: u32) -> Result { + let point = Point::new(x.try_into()?, y.try_into()?); + let result = match event { + 1 => Self::TouchStart(point), + 2 => Self::TouchMove(point), + 4 => Self::TouchEnd(point), + _ => return Err(error::Error::OutOfRange), + }; + Ok(result) + } +} diff --git a/core/embed/rust/src/ui/layout/example.rs b/core/embed/rust/src/ui/model_tt/layout.rs similarity index 95% rename from core/embed/rust/src/ui/layout/example.rs rename to core/embed/rust/src/ui/model_tt/layout.rs index 03de67def..f03807c0a 100644 --- a/core/embed/rust/src/ui/layout/example.rs +++ b/core/embed/rust/src/ui/model_tt/layout.rs @@ -4,16 +4,17 @@ use crate::{ error::Error, micropython::{buffer::Buffer, obj::Obj}, ui::{ - component::{ - model_tt::{theme, Button, Dialog, DialogMsg, Text}, - Child, - }, + component::{Child, Text}, display, + layout::obj::LayoutObj, }, util, }; -use super::obj::LayoutObj; +use super::{ + component::{Button, Dialog, DialogMsg}, + theme, +}; impl TryFrom> for Obj where diff --git a/core/embed/rust/src/ui/model_tt/mod.rs b/core/embed/rust/src/ui/model_tt/mod.rs new file mode 100644 index 000000000..43d96a0f7 --- /dev/null +++ b/core/embed/rust/src/ui/model_tt/mod.rs @@ -0,0 +1,5 @@ +pub mod component; +pub mod constant; +pub mod event; +pub mod layout; +pub mod theme; diff --git a/core/embed/rust/src/ui/component/model_tt/theme.rs b/core/embed/rust/src/ui/model_tt/theme.rs similarity index 95% rename from core/embed/rust/src/ui/component/model_tt/theme.rs rename to core/embed/rust/src/ui/model_tt/theme.rs index cd8690e8e..41f26492f 100644 --- a/core/embed/rust/src/ui/component/model_tt/theme.rs +++ b/core/embed/rust/src/ui/model_tt/theme.rs @@ -1,8 +1,10 @@ use crate::ui::{ - component::model_tt::{ButtonStyle, ButtonStyleSheet, LabelStyle}, + component::{label::LabelStyle, text::DefaultTextTheme}, display::{Color, Font}, }; +use super::component::{ButtonStyle, ButtonStyleSheet}; + // Font constants. pub const FONT_NORMAL: Font = Font::new(-1); pub const FONT_BOLD: Font = Font::new(-2); diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py index 167d53592..bc1bc1931 100644 --- a/core/src/trezor/ui/__init__.py +++ b/core/src/trezor/ui/__init__.py @@ -456,11 +456,9 @@ if utils.MODEL == "1": msg = None if event is RENDER: self.layout.paint() - elif event is io.TOUCH_START: - msg = self.layout.touch_start(x, y) - elif event is io.TOUCH_MOVE: - msg = self.layout.touch_move(x, y) - elif event is io.TOUCH_END: - msg = self.layout.touch_end(x, y) + elif event in (io.BUTTON_PRESSED, io.BUTTON_RELEASED): + msg = self.layout.hid_event(event, x, 0) + # elif event in (io.TOUCH_START, io.TOUCH_MOVE, io.TOUCH_END): + # self.layout.hid_event(event, x, y) if msg is not None: raise Result(msg)