From 96ac4e263c4eb25067a2016d2a1441b2e4393cbe Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 23 Jan 2025 11:57:09 +0200 Subject: [PATCH] refactor(core): reduce `ui::layout_delizia::component::header::Header` size [no changelog] --- .../src/ui/layout_delizia/component/frame.rs | 14 +++++------ .../src/ui/layout_delizia/component/header.rs | 24 +++++++++++++++---- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/core/embed/rust/src/ui/layout_delizia/component/frame.rs b/core/embed/rust/src/ui/layout_delizia/component/frame.rs index c51cb3aaf07..33a8e1e383a 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/frame.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/frame.rs @@ -1,4 +1,4 @@ -use super::{theme, ButtonStyleSheet, Footer, Header}; +use super::{header::HeaderMsg, theme, ButtonStyleSheet, Footer, Header}; use crate::{ strutil::TString, ui::{ @@ -139,31 +139,31 @@ where } #[inline(never)] - fn with_button(mut self, icon: Icon, msg: FlowMsg, enabled: bool) -> Self { + fn with_button(mut self, icon: Icon, msg: HeaderMsg, enabled: bool) -> Self { self.header = self.header.with_button(icon, enabled, msg); self } pub fn with_cancel_button(self) -> Self { - self.with_button(theme::ICON_CLOSE, FlowMsg::Cancelled, true) + self.with_button(theme::ICON_CLOSE, HeaderMsg::Cancelled, true) } pub fn with_menu_button(self) -> Self { - self.with_button(theme::ICON_MENU, FlowMsg::Info, true) + self.with_button(theme::ICON_MENU, HeaderMsg::Info, true) } pub fn with_danger_menu_button(self) -> Self { - self.with_button(theme::ICON_MENU, FlowMsg::Info, true) + self.with_button(theme::ICON_MENU, HeaderMsg::Info, true) .button_styled(theme::button_warning_high()) } pub fn with_warning_low_icon(self) -> Self { - self.with_button(theme::ICON_WARNING, FlowMsg::Info, false) + self.with_button(theme::ICON_WARNING, HeaderMsg::Info, false) .button_styled(theme::button_warning_low()) } pub fn with_danger_icon(self) -> Self { - self.with_button(theme::ICON_WARNING, FlowMsg::Info, false) + self.with_button(theme::ICON_WARNING, HeaderMsg::Info, false) .button_styled(theme::button_danger()) } diff --git a/core/embed/rust/src/ui/layout_delizia/component/header.rs b/core/embed/rust/src/ui/layout_delizia/component/header.rs index 5d64c5ee5ed..83a4dcf929f 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/header.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/header.rs @@ -61,6 +61,22 @@ impl AttachAnimation { const BUTTON_EXPAND_BORDER: i16 = 32; +#[derive(Clone, Copy)] +pub enum HeaderMsg { + // Note: other FlowMsg variants are not used, so the total enum size can be reduced. + Cancelled, + Info, +} + +impl From for FlowMsg { + fn from(msg: HeaderMsg) -> Self { + match msg { + HeaderMsg::Cancelled => FlowMsg::Cancelled, + HeaderMsg::Info => FlowMsg::Info, + } + } +} + pub struct Header { area: Rect, title: Label<'static>, @@ -70,7 +86,7 @@ pub struct Header { icon: Option, color: Option, title_style: TextStyle, - button_msg: FlowMsg, + button_msg: HeaderMsg, } impl Header { @@ -84,7 +100,7 @@ impl Header { icon: None, color: None, title_style: theme::label_title_main(), - button_msg: FlowMsg::Cancelled, + button_msg: HeaderMsg::Cancelled, } } #[inline(never)] @@ -133,7 +149,7 @@ impl Header { } #[inline(never)] - pub fn with_button(mut self, icon: Icon, enabled: bool, msg: FlowMsg) -> Self { + pub fn with_button(mut self, icon: Icon, enabled: bool, msg: HeaderMsg) -> Self { let touch_area = Insets::uniform(BUTTON_EXPAND_BORDER); self.button = Some( Button::with_icon(icon) @@ -207,7 +223,7 @@ impl Component for Header { } if let Some(ButtonMsg::Clicked) = self.button.event(ctx, event) { - return Some(self.button_msg.clone()); + return Some(self.button_msg.into()); }; None