What changed, and why it matters
This commit is a routine user-interface feature: it adds a new on-device tutorial for the Trezor hardware wallet's 'Caesar' layout. It teaches users how to navigate menus, scroll, use the middle button, and the 'Shift' button combination. There is no security fix or vulnerability present in the change.
No security action required; review as normal UI feature code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit introduces a new Tutorial component for the Caesar UI layout, replacing the previous simpler tutorial implementation. It adds support for tutorial-specific button visuals (pressed-arm hints, ghost buttons, middle-button confirmation, shift labels) and a dedicated tutorial state machine. Existing Flow scrollbar/ignore-second-button options are removed because the new tutorial no longer uses them. The changes are purely presentational and instructional.
Changed components
core/embed/rust/src/ui/layout_caesar/component/button.rscore/embed/rust/src/ui/layout_caesar/component/flow.rscore/embed/rust/src/ui/layout_caesar/component/input_methods/simple_choice.rscore/embed/rust/src/ui/layout_caesar/component/mod.rscore/embed/rust/src/ui/layout_caesar/component/page.rscore/embed/rust/src/ui/layout_caesar/component/tutorial.rscore/embed/rust/src/ui/layout_caesar/component_msg_obj.rscore/embed/rust/src/ui/layout_caesar/ui_firmware.rstests/click_tests/test_tutorial_caesar.pyInspect captured patch +624 / −210
### core/embed/rust/src/ui/layout_caesar/component/button.rs
@@ -41,6 +41,7 @@ pub struct Button {
decoration: Option<Decoration>,
fixed_width: Option<i16>,
offset: Offset,
+ pressed_arm: Option<ButtonPos>,
state: State,
}
@@ -53,6 +54,7 @@ impl Button {
decoration: btn_details.decoration,
fixed_width: btn_details.fixed_width,
offset: btn_details.offset,
+ pressed_arm: btn_details.pressed_arm,
bounds: Rect::zero(),
state: State::Released,
}
@@ -191,14 +193,31 @@ impl Component for Button {
}
// Optionally display "arms" at both sides of content - always in FG and BG
- // colors (they are not inverted).
+ // colors (they are not inverted). A pressed arm is dotted and one pixel
+ // shorter on the outer side.
if matches!(self.decoration, Some(Decoration::Arms)) {
- shape::ToifImage::new(area.left_center(), theme::ICON_ARM_LEFT.toif)
+ let (left_arm, left_point) = if self.pressed_arm == Some(ButtonPos::Left) {
+ (
+ theme::ICON_MID_BUTTON_PRESSED_L,
+ area.left_center() - Offset::x(1),
+ )
+ } else {
+ (theme::ICON_ARM_LEFT, area.left_center())
+ };
+ shape::ToifImage::new(left_point, left_arm.toif)
.with_align(Alignment2D::TOP_RIGHT)
.with_fg(theme::FG)
.render(target);
- shape::ToifImage::new(area.right_center(), theme::ICON_ARM_RIGHT.toif)
+ let (right_arm, right_point) = if self.pressed_arm == Some(ButtonPos::Right) {
+ (
+ theme::ICON_MID_BUTTON_PRESSED_R,
+ area.right_center() + Offset::x(1),
+ )
+ } else {
+ (theme::ICON_ARM_RIGHT, area.right_center())
+ };
+ shape::ToifImage::new(right_point, right_arm.toif)
.with_align(Alignment2D::TOP_LEFT)
.with_fg(theme::FG)
.render(target);
@@ -285,6 +304,8 @@ pub struct ButtonDetails {
/// Holding this (left) button acts as "Shift", turning the right button
/// into its secondary function.
pub shift: bool,
+ /// Arm drawn dotted, see `with_pressed_arm`.
+ pressed_arm: Option<ButtonPos>,
}
impl ButtonDetails {
@@ -300,6 +321,7 @@ impl ButtonDetails {
send_long_press: false,
long_press_ms: None,
shift: false,
+ pressed_arm: None,
}
}
@@ -315,6 +337,7 @@ impl ButtonDetails {
send_long_press: false,
long_press_ms: None,
shift: false,
+ pressed_arm: None,
}
}
@@ -362,6 +385,13 @@ impl ButtonDetails {
.with_shift()
}
+ /// Dotted outline without content, showing that the right button does
+ /// nothing on its own. Used by the tutorial, on the screen teaching
+ /// "Shift".
+ pub fn ghost() -> Self {
+ Self::icon(theme::ICON_GHOST_BUTTON).with_fixed_width(theme::ICON_GHOST_BUTTON.toif.width())
+ }
+
/// Arrow glyph between arms, entering the selected menu item.
pub fn menu_select_icon() -> Self {
Self::icon(theme::ICON_MID_BUTTON_ARROW_DOWN)
@@ -464,6 +494,14 @@ impl ButtonDetails {
self
}
+ /// Drawing the arm on the `pos` side dotted (armed buttons only). Used by
+ /// the tutorial to show which button was pressed alone, when both should
+ /// be pressed.
+ pub fn with_pressed_arm(mut self, pos: Option<ButtonPos>) -> Self {
+ self.pressed_arm = pos;
+ self
+ }
+
/// Holding the (left) button engages "Shift" after `SHIFT_HOLD_MS`.
pub fn with_shift(mut self) -> Self {
self.shift = true;
@@ -563,15 +601,6 @@ impl ButtonLayout {
)
}
- /// Left and right arrow icons for navigation.
- pub fn arrow_none_arrow() -> Self {
- Self::new(
- Some(ButtonDetails::left_arrow_icon()),
- None,
- Some(ButtonDetails::right_arrow_icon()),
- )
- }
-
/// Left arrow and right text.
pub fn arrow_none_text(text: TString<'static>) -> Self {
Self::new(
@@ -581,15 +610,6 @@ impl ButtonLayout {
)
}
- /// Cancel cross on left and right arrow.
- pub fn cancel_none_arrow() -> Self {
- Self::new(
- Some(ButtonDetails::cancel_icon()),
- None,
- Some(ButtonDetails::right_arrow_icon()),
- )
- }
-
/// Cancel cross on left and right arrow facing down.
pub fn cancel_none_arrow_down() -> Self {
Self::new(
@@ -617,15 +637,6 @@ impl ButtonLayout {
)
}
- /// Arrow back on left and hold-to-confirm text on the right.
- pub fn arrow_none_htc(text: TString<'static>) -> Self {
- Self::new(
- Some(ButtonDetails::left_arrow_icon()),
- None,
- Some(ButtonDetails::text(text).with_default_duration()),
- )
- }
-
/// Only armed text in the middle.
pub fn none_armed_none(text: TString<'static>) -> Self {
Self::new(None, Some(ButtonDetails::armed_text(text)), None)
@@ -693,15 +704,6 @@ impl ButtonActions {
}
}
- /// Going back with left, going further with right
- pub fn prev_none_next() -> Self {
- Self::new(
- Some(ButtonAction::PrevPage),
- None,
- Some(ButtonAction::NextPage),
- )
- }
-
/// Going back with left, going further with middle
pub fn prev_next_none() -> Self {
Self::new(
@@ -725,15 +727,6 @@ impl ButtonActions {
Self::new(None, Some(ButtonAction::Confirm), None)
}
- /// Going to last page with left, to the next page with right
- pub fn last_none_next() -> Self {
- Self::new(
- Some(ButtonAction::LastPage),
- None,
- Some(ButtonAction::NextPage),
- )
- }
-
/// Going to last page with left, to the next page with right and confirm
/// with middle
pub fn last_confirm_next() -> Self {
@@ -759,11 +752,6 @@ impl ButtonActions {
Self::new(None, None, Some(ButtonAction::NextPage))
}
- /// Only going to the next page with middle
- pub fn none_next_none() -> Self {
- Self::new(None, Some(ButtonAction::NextPage), None)
- }
-
/// Cancelling with left, confirming with right
pub fn cancel_none_confirm() -> Self {
Self::new(
@@ -782,24 +770,6 @@ impl ButtonActions {
)
}
- /// Going to the beginning with left, confirming with right
- pub fn beginning_none_confirm() -> Self {
- Self::new(
- Some(ButtonAction::FirstPage),
- None,
- Some(ButtonAction::Confirm),
- )
- }
-
- /// Going to the beginning with left, cancelling with right
- pub fn beginning_none_cancel() -> Self {
- Self::new(
- Some(ButtonAction::FirstPage),
- None,
- Some(ButtonAction::Cancel),
- )
- }
-
/// Having access to appropriate action based on the `ButtonPos`
pub fn get_action(&self, pos: ButtonPos) -> Option<ButtonAction> {
match pos {
### core/embed/rust/src/ui/layout_caesar/component/flow.rs
@@ -28,10 +28,6 @@ where
buttons: Child<ButtonController>,
page_counter: usize,
return_confirmed_index: bool,
- show_scrollbar: bool,
- /// Possibly enforcing the second button to be ignored after some time after
- /// pressing the first button
- ignore_second_button_ms: Option<u32>,
}
impl<F> Flow<F>
@@ -56,8 +52,6 @@ where
buttons: Child::new(ButtonController::new(ButtonLayout::empty())),
page_counter: 0,
return_confirmed_index: false,
- show_scrollbar: true,
- ignore_second_button_ms: None,
}
}
@@ -75,18 +69,6 @@ where
self
}
- /// Show scrollbar or not.
- pub fn with_scrollbar(mut self, show_scrollbar: bool) -> Self {
- self.show_scrollbar = show_scrollbar;
- self
- }
-
- /// Ignoring the second button duration
- pub fn with_ignore_second_button_ms(mut self, ignore_second_button_ms: u32) -> Self {
- self.ignore_second_button_ms = Some(ignore_second_button_ms);
- self
- }
-
pub fn confirmed_index(&self) -> Option<usize> {
self.return_confirmed_index.then_some(self.page_counter)
}
@@ -225,11 +207,8 @@ where
// (scrollbar will be active - counting pages - even when not placed and
// painted)
if self.title.is_some() {
- let (title_area, scrollbar_area) = if self.show_scrollbar {
- title_area.split_right(self.scrollbar.inner().overall_width() + SCROLLBAR_SPACE)
- } else {
- (title_area, Rect::zero())
- };
+ let (title_area, scrollbar_area) =
+ title_area.split_right(self.scrollbar.inner().overall_width() + SCROLLBAR_SPACE);
self.title.place(title_area);
self.title_area = title_area;
@@ -238,14 +217,7 @@ where
// We finally found how long is the first page, and can set its button layout.
self.current_page.place(content_area);
- if let Some(ignore_ms) = self.ignore_second_button_ms {
- self.buttons = Child::new(
- ButtonController::new(self.current_page.btn_layout())
- .with_ignore_btn_delay(ignore_ms),
- );
- } else {
- self.buttons = Child::new(ButtonController::new(self.current_page.btn_layout()));
- }
+ self.buttons = Child::new(ButtonController::new(self.current_page.btn_layout()));
self.pad.place(title_content_area);
self.buttons.place(button_area);
@@ -296,11 +268,9 @@ where
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
self.pad.render(target);
- // Scrollbars are painted only with a title and when requested
+ // Scrollbars are painted only with a title
if self.title.is_some() {
- if self.show_scrollbar {
- self.scrollbar.render(target);
- }
+ self.scrollbar.render(target);
self.title.render(target);
}
self.buttons.render(target);
### core/embed/rust/src/ui/layout_caesar/component/input_methods/simple_choice.rs
@@ -116,6 +116,23 @@ impl SimpleChoice {
}
}
+ /// Context menu: menu buttons, page counter and the neighbouring items
+ /// shown. Returns the index of the selected item, closing it is not
+ /// reported as cancelling to MicroPython. Shared by `select_menu` and the
+ /// tutorial menu.
+ pub fn menu(
+ labels: Vec<TString<'static>, MAX_LENGTH>,
+ danger_items: Vec<bool, MAX_LENGTH>,
+ current: usize,
+ ) -> Self {
+ Self::new(labels, ChoiceControls::Cancellable, TString::empty())
+ .with_menu_buttons(danger_items)
+ .with_initial_page_counter(current)
+ .with_show_incomplete()
+ .with_return_index()
+ .with_ignore_cancelled()
+ }
+
/// Set the page counter at the very beginning.
pub fn with_initial_page_counter(mut self, page_counter: usize) -> Self {
self.choice_page = self.choice_page.with_initial_page_counter(page_counter);
### core/embed/rust/src/ui/layout_caesar/component/mod.rs
@@ -64,6 +64,8 @@ mod scrollbar;
mod share_words;
#[cfg(not(feature = "bootloader"))]
mod title;
+#[cfg(feature = "translations")]
+mod tutorial;
#[cfg(all(feature = "micropython", feature = "translations"))]
pub use address_details::AddressDetails;
@@ -95,3 +97,5 @@ pub use progress::Progress;
pub use scrollbar::ScrollBar;
#[cfg(feature = "translations")]
pub use share_words::ShareWords;
+#[cfg(feature = "translations")]
+pub use tutorial::Tutorial;
### core/embed/rust/src/ui/layout_caesar/component/page.rs
@@ -1,6 +1,8 @@
+use super::super::fonts;
use super::{
constant, theme, ButtonController, ButtonControllerMsg, ButtonDetails, ButtonLayout, ButtonPos,
};
+use crate::strutil::TString;
use crate::translations::TR;
use crate::ui::component::{
Child, Component, ComponentExt, Event, EventCtx, Pad, PageMsg, Paginate,
@@ -35,6 +37,8 @@ where
pad: Pad,
cancel_btn_details: Option<ButtonDetails>,
confirm_btn_details: Option<ButtonDetails>,
+ /// Middle button, confirming (without menu navigation only).
+ middle_btn_details: Option<ButtonDetails>,
back_btn_details: Option<ButtonDetails>,
next_btn_details: Option<ButtonDetails>,
/// Menu navigation, replacing the cancel/back/next buttons.
@@ -44,6 +48,9 @@ where
back_on_first_page: bool,
/// Whether the left button is being held as "Shift" (menu navigation only).
shift_active: bool,
+ /// Text shown on the left button while "Shift" is held, see
+ /// `with_shift_label`.
+ shift_label: Option<TString<'static>>,
buttons: Child<ButtonController>,
}
@@ -57,11 +64,13 @@ where
pad: Pad::with_background(background).with_clear(),
cancel_btn_details: Some(ButtonDetails::cancel_icon()),
confirm_btn_details: Some(ButtonDetails::text(TR::buttons__confirm.into())),
+ middle_btn_details: None,
back_btn_details: Some(ButtonDetails::up_arrow_icon()),
next_btn_details: Some(ButtonDetails::down_arrow_icon_wide()),
menu_nav: None,
back_on_first_page: false,
shift_active: false,
+ shift_label: None,
// Setting empty layout for now, we do not yet know the page count.
// Initial button layout will be set in `place()` after we can call
// `content.page_count()`.
@@ -79,6 +88,14 @@ where
self
}
+ /// Middle button (pressing both buttons) confirming the screen. Only
+ /// without the menu navigation. Used by the tutorial, on the screen
+ /// teaching the middle button.
+ pub fn with_middle_btn(mut self, btn_details: Option<ButtonDetails>) -> Self {
+ self.middle_btn_details = btn_details;
+ self
+ }
+
/// Navigation with the left button opening a context menu (or closing the
/// screen), and the right button scrolling down and finally confirming
/// (when there is a confirm button).
@@ -100,6 +117,14 @@ where
self
}
+ /// While "Shift" is held, the left button shows `label` instead of the
+ /// bracketed icon (menu navigation only). Used by the tutorial, on the
+ /// screen teaching "Shift".
+ pub fn with_shift_label(mut self, label: TString<'static>) -> Self {
+ self.shift_label = Some(label);
+ self
+ }
+
pub fn with_back_btn(mut self, btn_details: Option<ButtonDetails>) -> Self {
self.back_btn_details = btn_details;
self
@@ -165,7 +190,7 @@ where
} else {
self.confirm_btn_details.clone()
};
- ButtonLayout::new(btn_left, None, btn_right)
+ ButtonLayout::new(btn_left, self.middle_btn_details.clone(), btn_right)
}
fn get_menu_nav_button_layout(
@@ -178,11 +203,14 @@ where
// there is somewhere to go back to. It stays while "Shift" is held.
let can_go_back = has_prev || self.back_on_first_page;
let shift = can_go_back || self.shift_active;
- let btn_left = match (menu_nav, shift) {
- (MenuNav::Menu | MenuNav::ChoiceMenu, false) => ButtonDetails::menu_icon(),
- (MenuNav::Menu | MenuNav::ChoiceMenu, true) => ButtonDetails::menu_shift_icon(),
- (MenuNav::Close, false) => ButtonDetails::cancel_icon(),
- (MenuNav::Close, true) => ButtonDetails::cancel_shift_icon(),
+ let btn_left = match (menu_nav, shift, self.shift_label) {
+ (_, _, Some(label)) if self.shift_active => ButtonDetails::text(label)
+ .with_font(fonts::FONT_NORMAL)
+ .with_shift(),
+ (MenuNav::Menu | MenuNav::ChoiceMenu, false, _) => ButtonDetails::menu_icon(),
+ (MenuNav::Menu | MenuNav::ChoiceMenu, true, _) => ButtonDetails::menu_shift_icon(),
+ (MenuNav::Close, false, _) => ButtonDetails::cancel_icon(),
+ (MenuNav::Close, true, _) => ButtonDetails::cancel_shift_icon(),
};
let btn_right = if self.shift_active {
can_go_back.then(ButtonDetails::scroll_up_wide)
### core/embed/rust/src/ui/layout_caesar/component/tutorial.rs
@@ -0,0 +1,379 @@
+use heapless::Vec;
+
+use super::super::fonts;
+use super::{
+ theme, ButtonDetails, ButtonPage, ButtonPos, CancelConfirmMsg, ChoiceMsg, MenuNav,
+ ScrollableFrame, SimpleChoice,
+};
+use crate::strutil::TString;
+use crate::translations::TR;
+use crate::ui::component::base::AttachType;
+use crate::ui::component::text::op::OpTextLayout;
+use crate::ui::component::{Component, Event, EventCtx, FormattedText, Never, Pad, PageMsg};
+use crate::ui::event::{ButtonEvent, PhysicalButton};
+use crate::ui::geometry::Rect;
+use crate::ui::shape::Renderer;
+
+/// Screens of the tutorial, in the order they are shown.
+#[derive(Clone, Copy, PartialEq, Eq)]
+enum Screen {
+ Welcome,
+ /// "Skip tutorial?", from the cross on `Welcome`
+ Skip,
+ Buttons,
+ HoldToConfirm,
+ /// Pressing both buttons. `hint` is the button that was pressed and
+ /// released alone.
+ MiddleButton {
+ hint: Option<ButtonPos>,
+ },
+ Scroll,
+ /// Teaching "Shift" - the right button alone does nothing.
+ GoBack,
+ Remember,
+ MenuIntro,
+ /// The tutorial context menu, see `MENU_COMPLETE` and `MENU_RESTART`
+ Menu,
+ Complete,
+ /// Information about the menu, from the menu button of the other screens.
+ /// Goes back to `Tutorial::info_from`.
+ MenuInfo,
+}
+
+/// Items of the tutorial menu
+const MENU_COMPLETE: usize = 0;
+const MENU_RESTART: usize = 1;
+
+type TutorialPage = ScrollableFrame<ButtonPage<FormattedText>>;
+
+// Most of the screens are pages, boxing them would not save anything.
+#[allow(clippy::large_enum_variant)]
+enum Content {
+ Page(TutorialPage),
+ Menu(SimpleChoice),
+}
+
+enum ContentMsg {
+ Page(PageMsg<Never>),
+ Menu(ChoiceMsg<usize>),
+}
+
+/// Caesar device tutorial (Figma "ExternalMenu / Tutorial update").
+///
+/// One layout switching between the screens (`Screen`). Each screen is a
+/// `ButtonPage` in a `ScrollableFrame`, the tutorial menu is the regular
+/// context menu (`SimpleChoice::menu`). Finishing it is `Confirmed`, skipping
+/// it `Cancelled`.
+///
+/// The menu button on the screens is `MenuNav::ChoiceMenu`, so that the
+/// automated tests do not try to visit it as an information menu - it opens
+/// the information screen or the tutorial menu instead.
+///
+/// Added elsewhere only for the tutorial: `ButtonPage::with_middle_btn`,
+/// `ButtonPage::with_shift_label`, `ButtonDetails::ghost` and
+/// `ButtonDetails::with_pressed_arm`.
+pub struct Tutorial {
+ screen: Screen,
+ /// Where `Screen::MenuInfo` goes back to
+ info_from: Screen,
+ content: Content,
+ pad: Pad,
+ bounds: Rect,
+ single_press: SinglePress,
+}
+
+impl Tutorial {
+ pub fn new() -> Self {
+ Self {
+ screen: Screen::Welcome,
+ info_from: Screen::Welcome,
+ content: Self::content(Screen::Welcome),
+ pad: Pad::with_background(theme::BG),
+ bounds: Rect::zero(),
+ single_press: SinglePress::default(),
+ }
+ }
+
+ fn go_to(&mut self, ctx: &mut EventCtx, screen: Screen) {
+ self.screen = screen;
+ self.content = Self::content(screen);
+ self.place(self.bounds);
+ // Like a newly shown layout, e.g. for the title marquee to start
+ let attach = Event::Attach(AttachType::Initial);
+ match &mut self.content {
+ Content::Page(page) => {
+ page.event(ctx, attach);
+ }
+ Content::Menu(menu) => {
+ menu.event(ctx, attach);
+ }
+ }
+ // Buttons still held from the previous screen are not a single press
+ self.single_press = SinglePress::default();
+ self.pad.clear();
+ ctx.request_paint();
+ }
+
+ /// The screen following `self.screen` after `msg`, `Err` when the
+ /// tutorial ends.
+ fn next(&mut self, msg: ContentMsg) -> Result<Option<Screen>, CancelConfirmMsg> {
+ use ContentMsg as Msg;
+ use Screen::*;
+
+ let next = match (self.screen, msg) {
+ // Cross on the first screen
+ (Welcome, Msg::Page(PageMsg::Cancelled)) => Skip,
+ (Skip, Msg::Page(PageMsg::Confirmed)) => return Err(CancelConfirmMsg::Cancelled),
+ (Skip, Msg::Page(PageMsg::Cancelled)) => Welcome,
+
+ (Welcome, Msg::Page(PageMsg::Confirmed)) => Buttons,
+ (Buttons, Msg::Page(PageMsg::Confirmed)) => HoldToConfirm,
+ (HoldToConfirm, Msg::Page(PageMsg::Confirmed)) => MiddleButton { hint: None },
+ (MiddleButton { .. }, Msg::Page(PageMsg::Confirmed)) => Scroll,
+ (Scroll, Msg::Page(PageMsg::Confirmed)) => GoBack,
+ // The right button alone does nothing when teaching "Shift"
+ (GoBack, Msg::Page(PageMsg::Confirmed)) => return Ok(None),
+ (Remember, Msg::Page(PageMsg::Confirmed)) => MenuIntro,
+ (Complete, Msg::Page(PageMsg::Confirmed)) => return Err(CancelConfirmMsg::Confirmed),
+
+ // "Shift" + right button. On `GoBack` it continues, the screen is
+ // teaching it.
+ (GoBack, Msg::Page(PageMsg::Cancelled)) => Remember,
+ (Remember, Msg::Page(PageMsg::Cancelled)) => GoBack,
+ (MenuIntro, Msg::Page(PageMsg::Cancelled)) => Remember,
+
+ // Menu button
+ (MenuIntro, Msg::Page(PageMsg::Info)) => Menu,
+ (screen, Msg::Page(PageMsg::Info)) => {
+ self.info_from = screen;
+ MenuInfo
+ }
+ (MenuInfo, Msg::Page(PageMsg::Cancelled)) => self.info_from,
+
+ (Menu, Msg::Menu(ChoiceMsg::Choice { item, .. })) if item == MENU_COMPLETE => Complete,
+ (Menu, Msg::Menu(ChoiceMsg::Choice { item, .. })) if item == MENU_RESTART => Welcome,
+ (Menu, Msg::Menu(ChoiceMsg::Cancel)) => MenuIntro,
+
+ // "Again"
+ (Complete, Msg::Page(PageMsg::Cancelled)) => Welcome,
+ _ => return Ok(None),
+ };
+ Ok(Some(next))
+ }
+
+ fn content(screen: Screen) -> Content {
+ let page = match screen {
+ Screen::Welcome => framed(
+ Some(TR::tutorial__title_welcome),
+ text(&[TR::tutorial__lets_begin])
+ .with_menu_nav(MenuNav::Close)
+ .with_confirm_btn(Some(ButtonDetails::scroll_down_wide())),
+ ),
+ Screen::Skip => framed(
+ Some(TR::tutorial__title_skip),
+ text(&[TR::tutorial__sure_you_want_skip])
+ .with_cancel_btn(Some(ButtonDetails::left_arrow_icon()))
+ .with_confirm_btn(Some(button_text(TR::buttons__skip))),
+ ),
+ Screen::Buttons => framed(
+ None,
+ text(&[TR::tutorial__use_trezor])
+ .with_menu_nav(MenuNav::ChoiceMenu)
+ .with_confirm_btn(Some(button_text(TR::buttons__continue))),
+ ),
+ Screen::HoldToConfirm => framed(
+ Some(TR::instructions__hold_to_confirm),
+ text(&[TR::tutorial__press_and_hold])
+ .with_menu_nav(MenuNav::ChoiceMenu)
+ .with_confirm_btn(Some(
+ button_text(TR::buttons__hold_to_confirm).with_default_duration(),
+ )),
+ ),
+ Screen::MiddleButton { hint } => framed(
+ Some(TR::tutorial__title_middle_button),
+ text(&[if hint.is_some() {
+ TR::tutorial__press_both
+ } else {
+ TR::tutorial__middle_click
+ }])
+ .with_cancel_btn(None)
+ .with_confirm_btn(None)
+ .with_middle_btn(Some(
+ ButtonDetails::armed_text(TR::buttons__view.into()).with_pressed_arm(hint),
+ )),
+ ),
+ Screen::Scroll => framed(
+ Some(TR::tutorial__title_screen_scroll),
+ text(&[TR::tutorial__scroll_down])
+ .with_menu_nav(MenuNav::ChoiceMenu)
+ .with_confirm_btn(Some(ButtonDetails::scroll_down_wide())),
+ ),
+ Screen::GoBack => framed(
+ Some(TR::tutorial__title_go_back),
+ text(&[TR::tutorial__hold_left_press_right])
+ .with_menu_nav(MenuNav::ChoiceMenu)
+ .with_back_on_first_page()
+ .with_shift_label(TR::buttons__shift.into())
+ .with_confirm_btn(Some(ButtonDetails::ghost())),
+ ),
+ Screen::Remember => framed(
+ Some(TR::tutorial__title_remember),
+ text(&[TR::tutorial__scroll_up])
+ .with_menu_nav(MenuNav::ChoiceMenu)
+ .with_back_on_first_page()
+ .with_confirm_btn(Some(button_text(TR::buttons__continue))),
+ ),
+ Screen::MenuIntro => framed(
+ Some(TR::tutorial__title_handy_menu),
+ text(&[TR::tutorial__menu, TR::tutorial__press_left])
+ .with_menu_nav(MenuNav::ChoiceMenu)
+ .with_back_on_first_page()
+ .with_confirm_btn(None),
+ ),
+ Screen::Menu => {
+ let labels = Vec::from_iter([
+ TR::tutorial__complete.into(),
+ TR::tutorial__restart_tutorial.into(),
+ ]);
+ let danger_items = Vec::from_iter([false, false]);
+ return Content::Menu(SimpleChoice::menu(labels, danger_items, 0));
+ }
+ Screen::Complete => framed(
+ Some(TR::tutorial__title_tutorial_complete),
+ text(&[TR::tutorial__ready_to_use])
+ .with_cancel_btn(Some(button_text(TR::buttons__again)))
+ .with_confirm_btn(Some(button_text(TR::buttons__continue))),
+ ),
+ Screen::MenuInfo => framed(
+ Some(TR::tutorial__title_handy_menu),
+ text(&[TR::tutorial__menu_later])
+ .with_menu_nav(MenuNav::Close)
+ .with_confirm_btn(None),
+ ),
+ };
+ Content::Page(page)
+ }
+}
+
+/// Paragraphs vertically centered on the screen.
+fn text(texts: &[TR]) -> ButtonPage<FormattedText> {
+ let mut ops = OpTextLayout::new(theme::TEXT_NORMAL);
+ for (i, &text) in texts.iter().enumerate() {
+ if i > 0 {
+ ops.add_newline();
+ }
+ ops.add_text_with_font(text, fonts::FONT_NORMAL);
+ }
+ ButtonPage::new(FormattedText::new(ops).vertically_centered(), theme::BG)
+}
+
+fn framed(title: Option<TR>, page: ButtonPage<FormattedText>) -> TutorialPage {
+ let frame = ScrollableFrame::new(page);
+ match title {
+ Some(title) => frame.with_title(title.into()),
+ None => frame,
+ }
+}
+
+fn button_text(text: TR) -> ButtonDetails {
+ ButtonDetails::text(TString::from(text))
+}
+
+impl Component for Tutorial {
+ type Msg = CancelConfirmMsg;
+
+ fn place(&mut self, bounds: Rect) -> Rect {
+ self.bounds = bounds;
+ self.pad.place(bounds);
+ match &mut self.content {
+ Content::Page(page) => page.place(bounds),
+ Content::Menu(menu) => menu.place(bounds),
+ };
+ bounds
+ }
+
+ fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
+ let hint = if matches!(self.screen, Screen::MiddleButton { .. }) {
+ self.single_press.event(event)
+ } else {
+ None
+ };
+
+ let msg = match &mut self.content {
+ Content::Page(page) => page.event(ctx, event).map(ContentMsg::Page),
+ Content::Menu(menu) => menu.event(ctx, event).map(ContentMsg::Menu),
+ };
+ let next = match msg {
+ Some(msg) => match self.next(msg) {
+ Ok(next) => next,
+ Err(result) => return Some(result),
+ },
+ None => hint.map(|hint| Screen::MiddleButton { hint: Some(hint) }),
+ };
+ if let Some(next) = next {
+ self.go_to(ctx, next);
+ }
+ None
+ }
+
+ fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
+ self.pad.render(target);
+ match &self.content {
+ Content::Page(page) => page.render(target),
+ Content::Menu(menu) => menu.render(target),
+ }
+ }
+}
+
+/// Detecting a button pressed and released without the other one, for the
+/// hint on `Screen::MiddleButton`.
+#[derive(Default)]
+struct SinglePress {
+ /// How many buttons are down
+ down: u8,
+ /// Whether both buttons were down since all of them were released
+ both: bool,
+}
+
+impl SinglePress {
+ /// The button released after it was pressed alone.
+ fn event(&mut self, event: Event) -> Option<ButtonPos> {
+ match event {
+ Event::Attach(_) => *self = Self::default(),
+ Event::Button(ButtonEvent::ButtonPressed(
+ PhysicalButton::Left | PhysicalButton::Right,
+ )) => {
+ self.down += 1;
+ self.both |= self.down > 1;
+ }
+ // A button pressed before the screen was shown is not counted
+ Event::Button(ButtonEvent::ButtonReleased(
+ button @ (PhysicalButton::Left | PhysicalButton::Right),
+ )) if self.down > 0 => {
+ self.down -= 1;
+ if self.down == 0 {
+ let alone = !self.both;
+ self.both = false;
+ if alone {
+ return Some(button.into());
+ }
+ }
+ }
+ _ => {}
+ }
+ None
+ }
+}
+
+// DEBUG-ONLY SECTION BELOW
+
+#[cfg(feature = "ui_debug")]
+impl crate::trace::Trace for Tutorial {
+ fn trace(&self, t: &mut dyn crate::trace::Tracer) {
+ // Traced as the current screen, like a standalone layout
+ match &self.content {
+ Content::Page(page) => page.trace(t),
+ Content::Menu(menu) => menu.trace(t),
+ }
+ }
+}
### core/embed/rust/src/ui/layout_caesar/component_msg_obj.rs
@@ -3,7 +3,7 @@ use core::convert::TryInto;
use super::component::{
AddressDetails, ButtonPage, CancelConfirmMsg, CoinJoinProgress, ConfirmHomescreen, Flow, Frame,
Homescreen, Lockscreen, NumberInput, NumberInputAction, Page, PassphraseEntry, PinEntry,
- Progress, ScrollableFrame, WordlistEntry,
+ Progress, ScrollableFrame, Tutorial, WordlistEntry,
};
use crate::micropython::{Error, Obj};
use crate::ui::component::base::Component;
@@ -66,6 +66,12 @@ where
}
}
+impl ComponentMsgObj for Tutorial {
+ fn msg_try_into_obj(&self, msg: Self::Msg) -> Result<Obj, Error> {
+ Ok(msg.into())
+ }
+}
+
impl ComponentMsgObj for PinEntry<'_> {
fn msg_try_into_obj(&self, msg: Self::Msg) -> Result<Obj, Error> {
match msg {
### core/embed/rust/src/ui/layout_caesar/ui_firmware.rs
@@ -6,9 +6,9 @@ use super::component::{
AddressDetails, ButtonActions, ButtonDetails, ButtonLayout, ButtonPage, ChoiceControls,
CoinJoinProgress, ConfirmHomescreen, Flow, FlowPages, Frame, Homescreen, Lockscreen, MenuNav,
NumberInput, Page, PassphraseEntry, PinEntry, Progress, ScrollableFrame, ShareWords,
- SimpleChoice, WordlistEntry, WordlistType, SIMPLE_CHOICE_MAX_LENGTH,
+ SimpleChoice, Tutorial, WordlistEntry, WordlistType, SIMPLE_CHOICE_MAX_LENGTH,
};
-use super::{constant, fonts, theme, UICaesar};
+use super::{fonts, theme, UICaesar};
use crate::io::BinaryData;
use crate::maybe_trace::MaybeTrace;
use crate::micropython::buffer::StrBuffer;
@@ -743,16 +743,8 @@ impl FirmwareUI for UICaesar {
.iter()
.map(|item| item.intent == MenuItemIntent::Danger)
.collect();
- // Returning the index of the selected menu item. The select text is not
- // used, the menu buttons show an arrow glyph instead.
- let layout = RootComponent::new(
- SimpleChoice::new(labels, ChoiceControls::Cancellable, TString::empty())
- .with_menu_buttons(danger_items)
- .with_initial_page_counter(current)
- .with_show_incomplete()
- .with_return_index()
- .with_ignore_cancelled(),
- );
+ // Returning the index of the selected menu item.
+ let layout = RootComponent::new(SimpleChoice::menu(labels, danger_items, current));
Ok(layout)
}
@@ -1221,76 +1213,7 @@ impl FirmwareUI for UICaesar {
}
fn tutorial() -> Result<impl LayoutMaybeTrace, Error> {
- const PAGE_COUNT: usize = 7;
-
- let get_page = move |page_index| {
- // Lazy-loaded list of screens to show, with custom content,
- // buttons and actions triggered by these buttons.
- // Cancelling the first screen will point to the last one,
- // which asks for confirmation whether user wants to
- // really cancel the tutorial.
- match page_index {
- // title, text, btn_layout, btn_actions
- 0 => tutorial_screen(
- TR::tutorial__title_hello.into(),
- TR::tutorial__welcome_press_right,
- ButtonLayout::cancel_none_arrow(),
- ButtonActions::last_none_next(),
- ),
- 1 => tutorial_screen(
- "".into(),
- TR::tutorial__use_trezor,
- ButtonLayout::arrow_none_arrow(),
- ButtonActions::prev_none_next(),
- ),
- 2 => tutorial_screen(
- TR::instructions__hold_to_confirm.into(),
- TR::tutorial__press_and_hold,
- ButtonLayout::arrow_none_htc(TR::buttons__hold_to_confirm.into()),
- ButtonActions::prev_none_next(),
- ),
- 3 => tutorial_screen(
- TR::tutorial__title_screen_scroll.into(),
- TR::tutorial__scroll_down,
- ButtonLayout::arrow_none_text(TR::buttons__continue.into()),
- ButtonActions::prev_none_next(),
- ),
- 4 => tutorial_screen(
- TR::buttons__confirm.into(),
- TR::tutorial__middle_click,
- ButtonLayout::none_armed_none(TR::buttons__confirm.into()),
- ButtonActions::none_next_none(),
- ),
- 5 => tutorial_screen(
- TR::tutorial__title_tutorial_complete.into(),
- TR::tutorial__ready_to_use,
- ButtonLayout::text_none_text(
- TR::buttons__again.into(),
- TR::buttons__continue.into(),
- ),
- ButtonActions::beginning_none_confirm(),
- ),
- 6 => tutorial_screen(
- TR::tutorial__title_skip.into(),
- TR::tutorial__sure_you_want_skip,
- ButtonLayout::arrow_none_text(TR::buttons__skip.into()),
- ButtonActions::beginning_none_cancel(),
- ),
- _ => unreachable!(),
- }
- };
-
- let pages = FlowPages::new(get_page, PAGE_COUNT);
-
- // Setting the ignore-second-button to mimic all the Choice pages, to teach user
- // that they should really press both buttons at the same time to achieve
- // middle-click.
- let layout = RootComponent::new(
- Flow::new(pages)
- .with_scrollbar(false)
- .with_ignore_second_button_ms(constant::IGNORE_OTHER_BTN_MS),
- );
- Ok(layout)
+ Ok(RootComponent::new(Tutorial::new()))
}
}
@@ -1349,20 +1272,6 @@ fn content_in_button_page<T: Component + Paginate + MaybeTrace + 'static>(
Ok(RootComponent::new(frame))
}
-/// General pattern of most tutorial screens.
-/// (title, text, btn_layout, btn_actions, text_y_offset)
-fn tutorial_screen(
- title: TString<'static>,
- text: TR,
- btn_layout: ButtonLayout,
- btn_actions: ButtonActions,
-) -> Page {
- let mut ops = OpTextLayout::new(theme::TEXT_NORMAL);
- ops.add_text_with_font(text, fonts::FONT_NORMAL);
- let formatted = FormattedText::new(ops).vertically_centered();
- Page::new(btn_layout, btn_actions, formatted).with_title(title)
-}
-
fn add_paragraphs<'a>(
paragraphs: &mut ParagraphVecLong<'a>,
key: Option<TString<'a>>,
### tests/click_tests/test_tutorial_caesar.py
@@ -50,12 +50,36 @@ def prepare_tutorial_and_cancel_after_it(
raise
-def go_through_tutorial_tr(debug: "DebugLink") -> None:
+def go_to_menu_intro(debug: "DebugLink") -> None:
+ """From the welcome screen to the screen introducing the menu."""
+ # Welcome
debug.press_right()
+ go_to_menu_intro_from_buttons(debug)
+
+
+def go_to_menu_intro_from_buttons(debug: "DebugLink") -> None:
+ """From the screen about the buttons to the screen introducing the menu."""
+ # Use Trezor by pressing left and right buttons
debug.press_right()
+ # Hold to confirm
debug.press_right(hold_ms=1000)
+ # Middle button
+ debug.press_middle()
+ # Try scrolling
debug.press_right()
+ # Need to go back? - Shift + right
+ assert debug.read_layout().title() == TR.tutorial__title_go_back
+ debug.press_right_with_shift()
+ # Remember
+ assert debug.read_layout().title() == TR.tutorial__title_remember
debug.press_right()
+ assert debug.read_layout().title() == TR.tutorial__title_handy_menu
+
+
+def go_through_tutorial_tr(debug: "DebugLink") -> None:
+ go_to_menu_intro(debug)
+ # Menu - "Complete tutorial"
+ debug.press_left()
debug.press_middle()
layout = debug.read_layout()
assert layout.title() == TR.tutorial__title_tutorial_complete
@@ -74,6 +98,18 @@ def test_tutorial_skip(device_handler: "BackgroundDeviceHandler"):
with prepare_tutorial_and_cancel_after_it(device_handler, cancelled=True) as debug:
# SKIP
debug.press_left()
+ assert debug.read_layout().title() == TR.tutorial__title_skip
+ debug.press_right()
+
+
+def test_tutorial_skip_declined(device_handler: "BackgroundDeviceHandler"):
+ with prepare_tutorial_and_cancel_after_it(device_handler) as debug:
+ # SKIP, then back to the welcome screen
+ debug.press_left()
+ debug.press_left()
+ assert debug.read_layout().title() == TR.tutorial__title_welcome
+
+ go_through_tutorial_tr(debug)
debug.press_right()
@@ -84,7 +120,102 @@ def test_tutorial_again_and_skip(device_handler: "BackgroundDeviceHandler"):
# AGAIN
debug.press_left()
+ assert debug.read_layout().title() == TR.tutorial__title_welcome
# SKIP
debug.press_left()
debug.press_right()
+
+
+def test_tutorial_menu_info(device_handler: "BackgroundDeviceHandler"):
+ with prepare_tutorial_and_cancel_after_it(device_handler) as debug:
+ debug.press_right()
+ # Use Trezor - the menu button shows information about the menu
+ debug.press_left()
+ layout = debug.read_layout()
+ assert layout.title() == TR.tutorial__title_handy_menu
+ assert TR.regexp("tutorial__menu_later").match(layout.text_content())
+ # closing it goes back
+ debug.press_left()
+ assert TR.regexp("tutorial__use_trezor").match(
+ debug.read_layout().text_content()
+ )
+
+ go_to_menu_intro_from_buttons(debug)
+ debug.press_left()
+ debug.press_middle()
+ debug.press_right()
+
+
+def test_tutorial_middle_button_hint(device_handler: "BackgroundDeviceHandler"):
+ with prepare_tutorial_and_cancel_after_it(device_handler) as debug:
+ debug.press_right()
+ debug.press_right()
+ debug.press_right(hold_ms=1000)
+ assert debug.read_layout().title() == TR.tutorial__title_middle_button
+
+ # one button alone shows the hint and stays on the screen
+ debug.press_left()
+ layout = debug.read_layout()
+ assert layout.title() == TR.tutorial__title_middle_button
+ assert TR.regexp("tutorial__press_both").match(layout.text_content())
+ debug.press_right()
+ assert debug.read_layout().title() == TR.tutorial__title_middle_button
+
+ debug.press_middle()
+ assert debug.read_layout().title() == TR.tutorial__title_screen_scroll
+
+ debug.press_right()
+ debug.press_right_with_shift()
+ debug.press_right()
+ debug.press_left()
+ debug.press_middle()
+ debug.press_right()
+
+
+def test_tutorial_go_back(device_handler: "BackgroundDeviceHandler"):
+ with prepare_tutorial_and_cancel_after_it(device_handler) as debug:
+ debug.press_right()
+ debug.press_right()
+ debug.press_right(hold_ms=1000)
+ debug.press_middle()
+ debug.press_right()
+
+ # the right button alone does nothing
+ debug.press_right()
+ assert debug.read_layout().title() == TR.tutorial__title_go_back
+
+ debug.press_right_with_shift()
+ assert debug.read_layout().title() == TR.tutorial__title_remember
+ # Shift + right goes back from the following screens
+ debug.press_right_with_shift()
+ assert debug.read_layout().title() == TR.tutorial__title_go_back
+ debug.press_right_with_shift()
+ debug.press_right()
+ assert debug.read_layout().title() == TR.tutorial__title_handy_menu
+ debug.press_right_with_shift()
+ assert debug.read_layout().title() == TR.tutorial__title_remember
+
+ debug.press_right()
+ debug.press_left()
+ debug.press_middle()
+ debug.press_right()
+
+
+def test_tutorial_menu(device_handler: "BackgroundDeviceHandler"):
+ with prepare_tutorial_and_cancel_after_it(device_handler) as debug:
+ go_to_menu_intro(debug)
+
+ # closing the menu goes back
+ debug.press_left()
+ debug.press_left()
+ assert debug.read_layout().title() == TR.tutorial__title_handy_menu
+
+ # "Restart tutorial"
+ debug.press_left()
+ debug.press_right()
+ debug.press_middle()
+ assert debug.read_layout().title() == TR.tutorial__title_welcome
+
+ go_through_tutorial_tr(debug)
+ debug.press_right()Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.