refactor(core/caesar): split bootloader UI
What changed, and why it matters
This commit reorganizes the on-screen button and menu code used by the Trezor bootloader on small-screen devices (T2B1/T3B1). It creates bootloader-specific copies of user-interface components instead of sharing them with the main firmware, and removes unused button layout helpers. The stated goal is to reduce flash memory use and make the bootloader UI independent from firmware UI changes. There is no indication in the commit that this fixes a security bug or changes security-critical behavior.
No security action required. Treat as a normal code-quality/flash-optimization refactor. If auditing, verify that the new bootloader `Buttons` state machine correctly handles left/right/both-button sequences and that the `#[cfg(not(feature = "bootloader"))]` gating does not accidentally exclude required components from bootloader builds.
Security signals we found
No security-relevant signals present in the diff or commit metadata.
Refactor is described by the vendor as flash-space optimization and UI isolation, not a security fix.
Behavioral logic in bootloader screens (confirm, connect, intro, menu) is preserved with equivalent button mappings.
Evidence from the diff
The change refactors core/embed/rust/src/ui/layout_caesar/bootloader/ by introducing a local Buttons component (buttons.rs), local Menu, Confirm, Connect, Intro, and ResultScreen implementations, and a standalone theme/bootloader.rs. It gates most firmware UI components with #[cfg(not(feature = "bootloader"))] in component/mod.rs, so the bootloader build no longer links the firmware’s ButtonController, ChoicePage, HoldToConfirm, etc. The new Buttons component is a simplified state machine for left/right/both-button presses and replaces the firmware ButtonController in bootloader screens. Button text types are narrowed from TString<'static> to &'static str. Unused ButtonLayout constructors cancel_none_none and menu_none_text are removed from the firmware component. The commit message explicitly calls this a refactor to save flash space.
Changed components
Trezor firmware core Rust UI layer for Caesar layoutBootloader UI on T2B1/T3B1 devicescore/embed/rust/src/ui/layout_caesar/bootloader/*core/embed/rust/src/ui/layout_caesar/component/mod.rscore/embed/rust/src/ui/layout_caesar/component/button.rscore/embed/rust/src/ui/layout_caesar/theme/bootloader.rsInspect captured patch +492 / −135
### core/embed/rust/src/ui/layout_caesar/bootloader/buttons.rs
@@ -0,0 +1,276 @@
+use super::super::theme::bootloader::{
+ ARMED_ICON_WIDTH, ARMS_MARGIN, BLD_BG, BLD_FG, BUTTON_HEIGHT, BUTTON_ICON_WIDTH,
+ BUTTON_OUTLINE, FONT_BUTTON, ICON_ARM_LEFT, ICON_ARM_RIGHT, ICON_ARROW_LEFT, ICON_ARROW_RIGHT,
+ ICON_CLOSE, ICON_MENU, ICON_SELECT,
+};
+use crate::ui::component::{Component, Event, EventCtx, Pad};
+use crate::ui::display::Icon;
+use crate::ui::event::{ButtonEvent, PhysicalButton};
+use crate::ui::geometry::{Alignment2D, Offset, Rect};
+use crate::ui::shape::{self, Renderer};
+
+#[derive(Copy, Clone, PartialEq, Eq)]
+pub enum ButtonPos {
+ Left,
+ /// Triggered by pressing both buttons
+ Middle,
+ Right,
+}
+
+impl ButtonPos {
+ fn from_physical(button: PhysicalButton) -> Self {
+ if button == PhysicalButton::Left {
+ Self::Left
+ } else {
+ Self::Right
+ }
+ }
+}
+
+/// Content and decoration of a button, looking the same as the firmware
+/// buttons.
+#[derive(Copy, Clone)]
+pub enum Button {
+ /// Icon in the corner, moved by the offset
+ Icon(Icon, Offset),
+ /// Outlined text
+ Text(&'static str),
+ /// Text between arms
+ ArmedText(&'static str),
+ /// Icon between arms
+ ArmedIcon(Icon),
+}
+
+impl Button {
+ pub const fn cancel() -> Self {
+ Self::Icon(ICON_CLOSE, Offset::new(3, -3))
+ }
+
+ /// Opening the context menu
+ pub const fn menu() -> Self {
+ Self::Icon(ICON_MENU, Offset::new(3, -3))
+ }
+
+ pub const fn left_arrow() -> Self {
+ Self::Icon(ICON_ARROW_LEFT, Offset::new(4, -3))
+ }
+
+ pub const fn right_arrow() -> Self {
+ Self::Icon(ICON_ARROW_RIGHT, Offset::new(-4, -3))
+ }
+
+ /// Entering the selected menu item
+ pub const fn select() -> Self {
+ Self::ArmedIcon(ICON_SELECT)
+ }
+
+ fn area(&self, pos: ButtonPos, bounds: Rect) -> Rect {
+ // Arms connect to the center, therefore the height is smaller
+ let (width, height) = match self {
+ Self::Icon(..) => (BUTTON_ICON_WIDTH, BUTTON_HEIGHT),
+ Self::Text(text) => (
+ FONT_BUTTON.visible_text_width(text) + 2 * BUTTON_OUTLINE,
+ BUTTON_HEIGHT,
+ ),
+ Self::ArmedText(text) => (
+ FONT_BUTTON.visible_text_width(text) + 2 * ARMS_MARGIN,
+ BUTTON_HEIGHT - 2,
+ ),
+ Self::ArmedIcon(_) => (ARMED_ICON_WIDTH, BUTTON_HEIGHT - 2),
+ };
+ let area = bounds.split_bottom(height).1;
+ match pos {
+ ButtonPos::Left => area.split_left(width).0,
+ ButtonPos::Middle => area.split_center(width).1,
+ ButtonPos::Right => area.split_right(width).1,
+ }
+ }
+
+ fn render<'s>(
+ &self,
+ target: &mut impl Renderer<'s>,
+ pos: ButtonPos,
+ bounds: Rect,
+ pressed: bool,
+ ) {
+ let area = self.area(pos, bounds);
+ let (fg, bg) = if pressed {
+ (BLD_BG, BLD_FG)
+ } else {
+ (BLD_FG, BLD_BG)
+ };
+
+ // Background: filled when pressed, outlined for text
+ if pressed {
+ shape::Bar::new(area)
+ .with_radius(3)
+ .with_bg(bg)
+ .render(target);
+ } else if let Self::Text(_) = self {
+ shape::Bar::new(area)
+ .with_radius(3)
+ .with_fg(fg)
+ .render(target);
+ } else {
+ shape::Bar::new(area).with_bg(bg).render(target);
+ }
+
+ // Arms are never inverted
+ if let Self::ArmedText(_) | Self::ArmedIcon(_) = self {
+ shape::ToifImage::new(area.left_center(), ICON_ARM_LEFT.toif)
+ .with_align(Alignment2D::TOP_RIGHT)
+ .with_fg(BLD_FG)
+ .render(target);
+ shape::ToifImage::new(area.right_center(), ICON_ARM_RIGHT.toif)
+ .with_align(Alignment2D::TOP_LEFT)
+ .with_fg(BLD_FG)
+ .render(target);
+ }
+
+ match *self {
+ Self::Icon(icon, offset) => {
+ let icon_area = area.translate(offset);
+ let (point, align) = match pos {
+ ButtonPos::Left => (icon_area.bottom_left(), Alignment2D::BOTTOM_LEFT),
+ ButtonPos::Middle => (icon_area.center(), Alignment2D::CENTER),
+ ButtonPos::Right => (icon_area.bottom_right(), Alignment2D::BOTTOM_RIGHT),
+ };
+ shape::ToifImage::new(point, icon.toif)
+ .with_align(align)
+ .with_fg(fg)
+ .render(target);
+ }
+ Self::ArmedIcon(icon) => {
+ shape::ToifImage::new(area.center(), icon.toif)
+ .with_align(Alignment2D::CENTER)
+ .with_fg(fg)
+ .render(target);
+ }
+ Self::Text(text) | Self::ArmedText(text) => {
+ let margin = if let Self::Text(_) = self {
+ BUTTON_OUTLINE
+ } else {
+ ARMS_MARGIN
+ };
+ let baseline = area.bottom_left()
+ + Offset::new(margin - FONT_BUTTON.start_x_bearing(text), -margin);
+ shape::Text::new(baseline, text, FONT_BUTTON)
+ .with_fg(fg)
+ .render(target);
+ }
+ }
+ }
+}
+
+#[derive(Copy, Clone, PartialEq, Eq)]
+enum State {
+ Nothing,
+ OneDown(PhysicalButton),
+ /// Both buttons are down - the middle button
+ BothDown,
+ /// One button was released after both were down
+ OneReleased(PhysicalButton),
+}
+
+/// Bottom bar with up to three buttons. A simplified copy of the firmware
+/// `ButtonController` without hold-to-confirm, long press and "Shift", which
+/// need timers.
+pub struct Buttons {
+ pad: Pad,
+ left: Option<Button>,
+ middle: Option<Button>,
+ right: Option<Button>,
+ state: State,
+}
+
+impl Buttons {
+ pub fn new(left: Option<Button>, middle: Option<Button>, right: Option<Button>) -> Self {
+ Self {
+ pad: Pad::with_background(BLD_BG).with_clear(),
+ left,
+ middle,
+ right,
+ state: State::Nothing,
+ }
+ }
+
+ pub fn set(&mut self, left: Option<Button>, middle: Option<Button>, right: Option<Button>) {
+ self.left = left;
+ self.middle = middle;
+ self.right = right;
+ self.pad.clear();
+ }
+
+ fn get(&self, pos: ButtonPos) -> Option<Button> {
+ match pos {
+ ButtonPos::Left => self.left,
+ ButtonPos::Middle => self.middle,
+ ButtonPos::Right => self.right,
+ }
+ }
+
+ /// The button currently held down.
+ pub fn pressed(&self) -> Option<ButtonPos> {
+ match self.state {
+ State::Nothing => None,
+ State::OneDown(button) => Some(ButtonPos::from_physical(button)),
+ State::BothDown | State::OneReleased(_) => Some(ButtonPos::Middle),
+ }
+ }
+}
+
+impl Component for Buttons {
+ /// Triggered button, sent on release
+ type Msg = ButtonPos;
+
+ fn place(&mut self, bounds: Rect) -> Rect {
+ self.pad.place(bounds);
+ bounds
+ }
+
+ fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
+ let (state, msg) = match (self.state, event) {
+ // Presses that happened before the screen was shown are forgotten
+ (_, Event::Attach(_)) => (State::Nothing, None),
+ (State::Nothing, Event::Button(ButtonEvent::ButtonPressed(b)))
+ if matches!(b, PhysicalButton::Left | PhysicalButton::Right) =>
+ {
+ (State::OneDown(b), None)
+ }
+ (State::OneDown(down), Event::Button(ButtonEvent::ButtonReleased(b))) if b == down => {
+ let pos = ButtonPos::from_physical(b);
+ (State::Nothing, self.get(pos).map(|_| pos))
+ }
+ (State::OneDown(down), Event::Button(ButtonEvent::ButtonPressed(b)))
+ if b != down && self.middle.is_some() =>
+ {
+ (State::BothDown, None)
+ }
+ (State::BothDown, Event::Button(ButtonEvent::ButtonReleased(b))) => {
+ (State::OneReleased(b), None)
+ }
+ (State::OneReleased(up), Event::Button(ButtonEvent::ButtonPressed(b))) if b == up => {
+ (State::BothDown, None)
+ }
+ (State::OneReleased(up), Event::Button(ButtonEvent::ButtonReleased(b))) if b != up => {
+ (State::Nothing, self.middle.map(|_| ButtonPos::Middle))
+ }
+ (state, _) => (state, None),
+ };
+ if state != self.state {
+ self.state = state;
+ ctx.request_paint();
+ }
+ msg
+ }
+
+ fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
+ self.pad.render(target);
+ let pressed = self.pressed();
+ for pos in [ButtonPos::Left, ButtonPos::Middle, ButtonPos::Right] {
+ if let Some(button) = self.get(pos) {
+ button.render(target, pos, self.pad.area, pressed == Some(pos));
+ }
+ }
+ }
+}
### core/embed/rust/src/ui/layout_caesar/bootloader/confirm.rs
@@ -1,5 +1,5 @@
-use super::super::component::{ButtonController, ButtonControllerMsg, ButtonLayout, ButtonPos};
-use super::super::theme::{BUTTON_HEIGHT, TEXT_BOLD, TITLE_AREA_HEIGHT};
+use super::super::theme::bootloader::{BUTTON_HEIGHT, TEXT_BOLD, TITLE_AREA_HEIGHT};
+use super::buttons::{Button, ButtonPos, Buttons};
use super::menu::{Menu, MenuSelection};
use crate::strutil::TString;
use crate::ui::component::{Component, ComponentExt, Event, EventCtx, Label, Pad};
@@ -38,8 +38,8 @@ pub struct Confirm<'a> {
info_title: Option<Label<'a>>,
info_text: Option<Label<'a>>,
menu: Option<ConfirmMenu>,
- button_text: TString<'static>,
- buttons: ButtonController,
+ button_text: &'static str,
+ buttons: Buttons,
state: ConfirmState,
}
@@ -51,9 +51,9 @@ impl<'a> Confirm<'a> {
title: TString<'a>,
message: Label<'a>,
alert: Option<Label<'a>>,
- button_text: TString<'static>,
+ button_text: &'static str,
) -> Self {
- Self {
+ let mut confirm = Self {
bg: Pad::with_background(bg_color).with_clear(),
title: Label::left_aligned(title, TEXT_BOLD),
message,
@@ -63,13 +63,15 @@ impl<'a> Confirm<'a> {
info_text: None,
menu: None,
button_text,
- buttons: ButtonController::new(ButtonLayout::cancel_armed_none(button_text)),
+ buttons: Buttons::new(None, None, None),
state: ConfirmState::Main,
- }
+ };
+ confirm.set_buttons();
+ confirm
}
- /// Adding a context menu on the left with an info screen and cancel. The
- /// right button confirms.
+ /// Adding a context menu on the left with an info screen and cancel. Both
+ /// buttons still confirm.
pub fn with_menu(
mut self,
info_name: &'static str,
@@ -79,35 +81,36 @@ impl<'a> Confirm<'a> {
self.info_name = Some(info_name);
self.info_title = Some(Label::left_aligned(info_title, TEXT_BOLD));
self.info_text = Some(info_text);
- self.buttons = ButtonController::new(self.get_button_layout());
+ self.set_buttons();
self
}
fn new_menu(info_name: &'static str) -> ConfirmMenu {
Menu::new([info_name, "Cancel"])
}
- fn get_button_layout(&self) -> ButtonLayout {
- match self.state {
+ fn set_buttons(&mut self) {
+ let (left, middle) = match self.state {
ConfirmState::Main if self.info_name.is_some() => {
- ButtonLayout::menu_none_text(self.button_text)
+ (Button::menu(), Some(Button::ArmedText(self.button_text)))
}
- ConfirmState::Main => ButtonLayout::cancel_armed_none(self.button_text),
+ ConfirmState::Main => (Button::cancel(), Some(Button::ArmedText(self.button_text))),
// The menu has its own buttons
- ConfirmState::Menu | ConfirmState::Info => ButtonLayout::cancel_none_none(),
- }
+ ConfirmState::Menu | ConfirmState::Info => (Button::cancel(), None),
+ };
+ self.buttons.set(Some(left), middle, None);
}
fn set_state(&mut self, ctx: &mut EventCtx, state: ConfirmState) {
self.state = state;
self.bg.clear();
- self.buttons.set(self.get_button_layout());
+ self.set_buttons();
self.request_complete_repaint(ctx);
}
fn event_main(&mut self, ctx: &mut EventCtx, event: Event) -> Option<ConfirmMsg> {
match self.buttons.event(ctx, event) {
- Some(ButtonControllerMsg::Triggered(ButtonPos::Left, _)) => {
+ Some(ButtonPos::Left) => {
let Some(info_name) = self.info_name else {
return Some(ConfirmMsg::Cancel);
};
@@ -118,10 +121,8 @@ impl<'a> Confirm<'a> {
self.set_state(ctx, ConfirmState::Menu);
None
}
- Some(ButtonControllerMsg::Triggered(ButtonPos::Middle | ButtonPos::Right, _)) => {
- Some(ConfirmMsg::Confirm)
- }
- _ => None,
+ Some(ButtonPos::Middle) => Some(ConfirmMsg::Confirm),
+ Some(ButtonPos::Right) | None => None,
}
}
}
@@ -170,9 +171,7 @@ impl Component for Confirm<'_> {
}
ConfirmState::Info => {
// Going back to the menu with the cross
- if let Some(ButtonControllerMsg::Triggered(ButtonPos::Left, _)) =
- self.buttons.event(ctx, event)
- {
+ if let Some(ButtonPos::Left) = self.buttons.event(ctx, event) {
self.set_state(ctx, ConfirmState::Menu);
}
None
### core/embed/rust/src/ui/layout_caesar/bootloader/connect.rs
@@ -1,5 +1,5 @@
-use super::super::component::{ButtonController, ButtonControllerMsg, ButtonLayout, ButtonPos};
-use super::super::theme::{BUTTON_HEIGHT, TITLE_AREA_HEIGHT};
+use super::super::theme::bootloader::{BUTTON_HEIGHT, TITLE_AREA_HEIGHT};
+use super::buttons::{Button, ButtonPos, Buttons};
use crate::strutil::TString;
use crate::ui::component::{Component, Event, EventCtx, Pad};
use crate::ui::display::{Color, Font};
@@ -18,7 +18,7 @@ pub struct Connect {
bg: Pad,
message: TString<'static>,
font: Font,
- buttons: ButtonController,
+ buttons: Buttons,
}
impl Connect {
@@ -31,7 +31,7 @@ impl Connect {
bg: Pad::with_background(bg),
message: message.into(),
font,
- buttons: ButtonController::new(ButtonLayout::cancel_none_none()),
+ buttons: Buttons::new(Some(Button::cancel()), None, None),
};
instance.bg.clear();
@@ -55,9 +55,7 @@ impl Component for Connect {
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
- if let Some(ButtonControllerMsg::Triggered(ButtonPos::Left, _)) =
- self.buttons.event(ctx, event)
- {
+ if let Some(ButtonPos::Left) = self.buttons.event(ctx, event) {
return Some(ConnectMsg::Cancel);
}
### core/embed/rust/src/ui/layout_caesar/bootloader/intro.rs
@@ -1,7 +1,7 @@
-use super::super::component::ButtonControllerMsg::Triggered;
-use super::super::component::{ButtonController, ButtonLayout, ButtonPos};
-use super::super::theme::bootloader::{BLD_BG, BLD_FG, TEXT_NORMAL};
-use super::super::theme::{BUTTON_HEIGHT, ICON_WARN_TITLE, TITLE_AREA_HEIGHT};
+use super::super::theme::bootloader::{
+ BLD_BG, BLD_FG, BUTTON_HEIGHT, ICON_WARN_TITLE, TEXT_NORMAL, TITLE_AREA_HEIGHT,
+};
+use super::buttons::{Button, ButtonPos, Buttons};
use crate::strutil::TString;
use crate::ui::component::{Child, Component, Event, EventCtx, Label, Pad};
use crate::ui::geometry::{Alignment, Alignment2D, Rect};
@@ -26,7 +26,7 @@ impl ReturnToC for IntroMsg {
pub struct Intro<'a> {
bg: Pad,
title: Child<Label<'a>>,
- buttons: Child<ButtonController>,
+ buttons: Buttons,
text: Child<Label<'a>>,
warn: Option<Child<Label<'a>>>,
}
@@ -36,9 +36,11 @@ impl<'a> Intro<'a> {
Self {
bg: Pad::with_background(BLD_BG).with_clear(),
title: Child::new(Label::centered(title, TEXT_NORMAL).vertically_centered()),
- buttons: Child::new(ButtonController::new(ButtonLayout::menu_none_text(
- RIGHT_BUTTON_TEXT.into(),
- ))),
+ buttons: Buttons::new(
+ Some(Button::menu()),
+ None,
+ Some(Button::Text(RIGHT_BUTTON_TEXT)),
+ ),
text: Child::new(Label::left_aligned(content, TEXT_NORMAL).vertically_centered()),
warn: (!fw_ok).then_some(Child::new(
Label::new("FIRMWARE CORRUPTED".into(), Alignment::Start, TEXT_NORMAL)
@@ -74,15 +76,11 @@ impl<'a> Component for Intro<'a> {
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
- let msg = self.buttons.event(ctx, event);
-
- if let Some(Triggered(ButtonPos::Left, _)) = msg {
- return Some(Self::Msg::GoToMenu);
- };
- if let Some(Triggered(ButtonPos::Right, _)) = msg {
- return Some(Self::Msg::InstallFirmware);
- };
- None
+ match self.buttons.event(ctx, event)? {
+ ButtonPos::Left => Some(Self::Msg::GoToMenu),
+ ButtonPos::Right => Some(Self::Msg::InstallFirmware),
+ ButtonPos::Middle => None,
+ }
}
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
### core/embed/rust/src/ui/layout_caesar/bootloader/menu.rs
@@ -1,9 +1,11 @@
-use super::super::component::{ButtonLayout, ChoiceFactory, ChoiceItem, ChoiceMsg, ChoicePage};
-use super::super::theme::bootloader::BLD_BG;
+use super::super::theme::bootloader::{
+ BLD_BG, BLD_FG, BUTTON_HEIGHT, BUTTON_OUTLINE, FONT_MENU_ITEM,
+};
+use super::buttons::{Button, ButtonPos, Buttons};
use crate::ui::component::{Component, Event, EventCtx, Pad};
-use crate::ui::geometry::Rect;
+use crate::ui::geometry::{Offset, Rect};
use crate::ui::layout::simplified::ReturnToC;
-use crate::ui::shape::Renderer;
+use crate::ui::shape::{self, Renderer};
#[repr(u32)]
#[derive(Copy, Clone)]
@@ -41,63 +43,102 @@ pub enum MenuSelection {
Item(usize),
}
-pub struct MenuChoiceFactory<const N: usize> {
- items: [&'static str; N],
-}
-
-impl<const N: usize> ChoiceFactory for MenuChoiceFactory<N> {
- type Action = usize;
- type Item = ChoiceItem;
-
- fn count(&self) -> usize {
- N
- }
-
- fn get(&self, choice_index: usize) -> (Self::Item, Self::Action) {
- let btn_layout = ButtonLayout::menu_item(choice_index == 0, choice_index == N - 1);
- (
- ChoiceItem::new(self.items[choice_index], btn_layout),
- choice_index,
- )
- }
-}
-
-/// Context menu carousel, the same as the firmware `select_menu`. The cross on
-/// the first item closes the menu.
+/// Context menu carousel showing one item at a time, with the same buttons as
+/// the firmware `select_menu`. The cross on the first item closes the menu.
+/// Items must fit on one line.
pub struct Menu<const N: usize> {
pad: Pad,
- choice_page: ChoicePage<MenuChoiceFactory<N>, usize>,
+ items: [&'static str; N],
+ index: usize,
+ item_area: Rect,
+ buttons: Buttons,
}
impl<const N: usize> Menu<N> {
pub fn new(items: [&'static str; N]) -> Self {
- let choices = MenuChoiceFactory { items };
- Self {
+ let mut menu = Self {
pad: Pad::with_background(BLD_BG).with_clear(),
- choice_page: ChoicePage::new(choices).with_incomplete(true),
- }
+ items,
+ index: 0,
+ item_area: Rect::zero(),
+ buttons: Buttons::new(None, None, None),
+ };
+ menu.set_buttons();
+ menu
+ }
+
+ fn set_buttons(&mut self) {
+ let left = if self.index == 0 {
+ Button::cancel()
+ } else {
+ Button::left_arrow()
+ };
+ let right = (self.index < N - 1).then_some(Button::right_arrow());
+ self.buttons.set(Some(left), Some(Button::select()), right);
+ }
+
+ fn go_to(&mut self, ctx: &mut EventCtx, index: usize) {
+ self.index = index;
+ self.set_buttons();
+ self.pad.clear();
+ ctx.request_paint();
}
}
impl<const N: usize> Component for Menu<N> {
type Msg = MenuSelection;
fn place(&mut self, bounds: Rect) -> Rect {
+ let (item_area, button_area) = bounds.split_bottom(BUTTON_HEIGHT);
self.pad.place(bounds);
- self.choice_page.place(bounds);
+ self.item_area = item_area;
+ self.buttons.place(button_area);
bounds
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
- match self.choice_page.event(ctx, event) {
- Some(ChoiceMsg::Choice { item, .. }) => Some(MenuSelection::Item(item)),
- Some(ChoiceMsg::Cancel) => Some(MenuSelection::Close),
- None => None,
+ match self.buttons.event(ctx, event)? {
+ ButtonPos::Left if self.index == 0 => return Some(MenuSelection::Close),
+ ButtonPos::Left => self.go_to(ctx, self.index - 1),
+ ButtonPos::Right => self.go_to(ctx, self.index + 1),
+ ButtonPos::Middle => return Some(MenuSelection::Item(self.index)),
}
+ None
}
fn render<'s>(&'s self, target: &mut impl Renderer<'s>) {
self.pad.render(target);
- self.choice_page.render(target);
+ self.buttons.render(target);
+
+ // The item is outlined, and inverted while the middle button is down
+ let text = self.items[self.index];
+ let font = FONT_MENU_ITEM;
+ let text_size = Offset::new(font.visible_text_width(text), font.allcase_text_height());
+ let text_area = Rect::from_center_and_size(self.item_area.center(), text_size);
+ let outline = Rect::from_center_and_size(
+ text_area.center() + Offset::y(1),
+ text_size + Offset::uniform(2 * BUTTON_OUTLINE),
+ );
+ let inverse = self.buttons.pressed() == Some(ButtonPos::Middle);
+
+ shape::Bar::new(outline)
+ .with_radius(1)
+ .with_bg(BLD_FG)
+ .render(target);
+ if !inverse {
+ shape::Bar::new(outline.shrink(1))
+ .with_radius(1)
+ .with_bg(BLD_BG)
+ .render(target);
+ }
+
+ let fg = if inverse { BLD_BG } else { BLD_FG };
+ shape::Text::new(
+ text_area.bottom_left() - Offset::x(font.start_x_bearing(text)),
+ text,
+ font,
+ )
+ .with_fg(fg)
+ .render(target);
}
}
### core/embed/rust/src/ui/layout_caesar/bootloader/mod.rs
@@ -1,23 +1,27 @@
use heapless::String;
use ufmt::uwrite;
+mod buttons;
mod confirm;
+mod connect;
mod intro;
mod menu;
+mod result;
mod welcome;
-mod connect;
-
use sys::time;
use self::confirm::{Confirm, ConfirmMsg};
use self::connect::Connect;
use self::intro::Intro;
use self::menu::{Menu, MenuMsg, MENU_ITEMS};
+use self::result::ResultScreen;
use self::welcome::Welcome;
-use super::component::{ResultScreen, WelcomeScreen};
-use super::theme::bootloader::{BLD_BG, BLD_FG, ICON_ALERT, ICON_SPINNER, ICON_SUCCESS};
-use super::theme::{ICON_ARM_LEFT, ICON_ARM_RIGHT, TEXT_BOLD, TEXT_NORMAL};
+use super::component::WelcomeScreen;
+use super::theme::bootloader::{
+ BLD_BG, BLD_FG, ICON_ALERT, ICON_ARM_LEFT, ICON_ARM_RIGHT, ICON_SPINNER, ICON_SUCCESS,
+ TEXT_BOLD, TEXT_NORMAL,
+};
use super::{cshape, fonts, UICaesar};
use crate::bootloader::run;
use crate::ui::component::LineBreaking::BreakWordsNoHyphen;
@@ -175,7 +179,7 @@ impl BootloaderUI for UICaesar {
TEXT_NORMAL,
));
- let mut frame = Confirm::new(BLD_BG, title_str.into(), message, alert, "INSTALL".into())
+ let mut frame = Confirm::new(BLD_BG, title_str.into(), message, alert, "INSTALL")
.with_menu("Fingerprint", "FW FINGERPRINT".into(), fingerprint);
let (_, res) = run(&mut frame, true, false);
@@ -186,13 +190,7 @@ impl BootloaderUI for UICaesar {
let message = Label::left_aligned("Seed and firmware will be erased!".into(), TEXT_NORMAL)
.vertically_centered();
- let mut frame = Confirm::new(
- BLD_BG,
- "FACTORY RESET".into(),
- message,
- None,
- "RESET".into(),
- );
+ let mut frame = Confirm::new(BLD_BG, "FACTORY RESET".into(), message, None, "RESET");
let (_, res) = run(&mut frame, true, false);
res
@@ -205,13 +203,7 @@ impl BootloaderUI for UICaesar {
)
.vertically_centered();
- let mut frame = Confirm::new(
- BLD_BG,
- "UNLOCK BOOTLOADER?".into(),
- message,
- None,
- "UNLOCK".into(),
- );
+ let mut frame = Confirm::new(BLD_BG, "UNLOCK BOOTLOADER?".into(), message, None, "UNLOCK");
let (_, res) = run(&mut frame, true, false);
res
### core/embed/rust/src/ui/layout_caesar/bootloader/result.rs
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/component/button.rs
@@ -631,20 +631,6 @@ impl ButtonLayout {
Self::new(None, Some(ButtonDetails::armed_text(text)), None)
}
- /// Only cancel cross on the left.
- pub fn cancel_none_none() -> Self {
- Self::new(Some(ButtonDetails::cancel_icon()), None, None)
- }
-
- /// Context menu on the left and text on the right.
- pub fn menu_none_text(text: TString<'static>) -> Self {
- Self::new(
- Some(ButtonDetails::menu_icon()),
- None,
- Some(ButtonDetails::text(text)),
- )
- }
-
/// Item of a context menu carousel: arrows to move and an arrow glyph to
/// enter the item. The first item has a cross closing the menu instead of
/// the left arrow, the last one has no right arrow.
### core/embed/rust/src/ui/layout_caesar/component/mod.rs
@@ -1,52 +1,81 @@
+// The bootloader has its own copies of the interactive components (see
+// `layout_caesar::bootloader`), so that firmware UI changes cannot reach it
+// unnoticed. Everything except the boot and fatal error screens is therefore
+// left out of the bootloader build.
+
+mod error;
+mod welcome_screen;
+
+pub use error::ErrorScreen;
+pub use welcome_screen::WelcomeScreen;
+
+#[cfg(not(feature = "bootloader"))]
mod button;
+#[cfg(not(feature = "bootloader"))]
mod button_controller;
-mod error;
+#[cfg(not(feature = "bootloader"))]
mod hold_to_confirm;
+#[cfg(not(feature = "bootloader"))]
mod input_methods;
+#[cfg(not(feature = "bootloader"))]
mod loader;
-mod result;
-mod welcome_screen;
+#[cfg(not(feature = "bootloader"))]
pub use button::{
Button, ButtonAction, ButtonActions, ButtonContent, ButtonDetails, ButtonLayout, ButtonPos,
};
+#[cfg(not(feature = "bootloader"))]
pub use button_controller::{AutomaticMover, ButtonController, ButtonControllerMsg};
+#[cfg(not(feature = "bootloader"))]
pub use common_messages::CancelConfirmMsg;
-pub use error::ErrorScreen;
+#[cfg(not(feature = "bootloader"))]
pub use hold_to_confirm::{HoldToConfirm, HoldToConfirmMsg};
+#[cfg(not(feature = "bootloader"))]
pub use input_methods::choice::{Choice, ChoiceControls, ChoiceFactory, ChoiceMsg, ChoicePage};
+#[cfg(not(feature = "bootloader"))]
pub use input_methods::choice_item::ChoiceItem;
+#[cfg(not(feature = "bootloader"))]
pub use loader::{Loader, LoaderMsg, LoaderStyle, LoaderStyleSheet, ProgressLoader};
-pub use result::ResultScreen;
-pub use welcome_screen::WelcomeScreen;
+#[cfg(not(feature = "bootloader"))]
use super::{common_messages, constant, theme};
#[cfg(all(feature = "micropython", feature = "translations"))]
mod address_details;
+#[cfg(not(feature = "bootloader"))]
mod changing_text;
#[cfg(feature = "translations")]
mod coinjoin_progress;
+#[cfg(not(feature = "bootloader"))]
mod flow;
+#[cfg(not(feature = "bootloader"))]
mod flow_pages;
+#[cfg(not(feature = "bootloader"))]
mod frame;
#[cfg(feature = "micropython")]
mod homescreen;
#[cfg(feature = "translations")]
mod page;
+#[cfg(not(feature = "bootloader"))]
mod progress;
+#[cfg(not(feature = "bootloader"))]
mod scrollbar;
#[cfg(feature = "translations")]
mod share_words;
+#[cfg(not(feature = "bootloader"))]
mod title;
#[cfg(all(feature = "micropython", feature = "translations"))]
pub use address_details::AddressDetails;
+#[cfg(not(feature = "bootloader"))]
pub use changing_text::ChangingTextLine;
#[cfg(feature = "translations")]
pub use coinjoin_progress::CoinJoinProgress;
+#[cfg(not(feature = "bootloader"))]
pub use flow::Flow;
+#[cfg(not(feature = "bootloader"))]
pub use flow_pages::{FlowPages, Page};
+#[cfg(not(feature = "bootloader"))]
pub use frame::{Frame, ScrollableFrame};
#[cfg(feature = "micropython")]
pub use homescreen::{check_homescreen_format, ConfirmHomescreen, Homescreen, Lockscreen};
@@ -60,7 +89,9 @@ pub use input_methods::{
};
#[cfg(feature = "translations")]
pub use page::{ButtonPage, MenuNav};
+#[cfg(not(feature = "bootloader"))]
pub use progress::Progress;
+#[cfg(not(feature = "bootloader"))]
pub use scrollbar::ScrollBar;
#[cfg(feature = "translations")]
pub use share_words::ShareWords;
### core/embed/rust/src/ui/layout_caesar/res/bootloader/arm_left.png
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/arm_left.toif
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/arm_right.png
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/arm_right.toif
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/arrow_left.png
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/arrow_left.toif
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/arrow_right.png
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/arrow_right.toif
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/close.png
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/close.toif
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/menu.png
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/menu.toif
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/mid_button_arrow_down.png
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/res/bootloader/mid_button_arrow_down.toif
[binary or diff unavailable]
### core/embed/rust/src/ui/layout_caesar/theme/bootloader.rs
@@ -1,16 +1,52 @@
+//! Bootloader theme. It does not use the firmware theme, so that firmware UI
+//! changes do not reach the bootloader unnoticed.
+
use super::super::fonts;
-pub use super::super::theme::{BLACK, WHITE};
use crate::ui::component::text::TextStyle;
-use crate::ui::display::Color;
+use crate::ui::display::{Color, Font};
use crate::ui::util::include_icon;
-pub const BLD_BG: Color = BLACK;
-pub const BLD_FG: Color = WHITE;
+pub const BLD_BG: Color = Color::black();
+pub const BLD_FG: Color = Color::white();
+
+pub const TEXT_NORMAL: TextStyle =
+ TextStyle::new(fonts::FONT_NORMAL, BLD_FG, BLD_BG, BLD_FG, BLD_FG);
+pub const TEXT_BOLD: TextStyle = TextStyle::new(fonts::FONT_BOLD, BLD_FG, BLD_BG, BLD_FG, BLD_FG);
+
+pub const FONT_BUTTON: Font = fonts::FONT_NORMAL_UPPER;
+pub const FONT_MENU_ITEM: Font = fonts::FONT_NORMAL;
+
+pub const TITLE_AREA_HEIGHT: i16 = 12;
+
+// Button content is 7 pixels high, plus the outline on both sides.
+pub const BUTTON_OUTLINE: i16 = 3;
+pub const BUTTON_HEIGHT: i16 = 7 + 2 * BUTTON_OUTLINE;
+pub const BUTTON_ICON_WIDTH: i16 = BUTTON_HEIGHT;
+pub const ARMS_MARGIN: i16 = 2;
+/// Width of an icon between the arms of a middle button.
+pub const ARMED_ICON_WIDTH: i16 = 24;
include_icon!(ICON_ALERT, "layout_caesar/res/alert.toif");
include_icon!(ICON_SPINNER, "layout_caesar/res/spinner.toif");
include_icon!(ICON_SUCCESS, "layout_caesar/res/success.toif");
+include_icon!(ICON_WARN_TITLE, "layout_caesar/res/bld_header_warn.toif");
-pub const TEXT_NORMAL: TextStyle =
- TextStyle::new(fonts::FONT_NORMAL, BLD_FG, BLD_BG, BLD_FG, BLD_FG);
-pub const TEXT_BOLD: TextStyle = TextStyle::new(fonts::FONT_BOLD, BLD_FG, BLD_BG, BLD_FG, BLD_FG);
+include_icon!(ICON_ARM_LEFT, "layout_caesar/res/bootloader/arm_left.toif"); // 10*6
+include_icon!(
+ ICON_ARM_RIGHT,
+ "layout_caesar/res/bootloader/arm_right.toif"
+); // 10*6
+include_icon!(
+ ICON_ARROW_LEFT,
+ "layout_caesar/res/bootloader/arrow_left.toif"
+); // 4*7
+include_icon!(
+ ICON_ARROW_RIGHT,
+ "layout_caesar/res/bootloader/arrow_right.toif"
+); // 4*7
+include_icon!(ICON_CLOSE, "layout_caesar/res/bootloader/close.toif"); // 8*7
+include_icon!(ICON_MENU, "layout_caesar/res/bootloader/menu.toif"); // 6*7
+include_icon!(
+ ICON_SELECT,
+ "layout_caesar/res/bootloader/mid_button_arrow_down.toif"
+); // 8*4Why this scored 12/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.