Skip to content

Commit

Permalink
refactor(core): reduce `ui::layout_delizia::component::header::Header…
Browse files Browse the repository at this point in the history
…` size

[no changelog]
  • Loading branch information
romanz committed Jan 28, 2025
1 parent 830f038 commit 96ac4e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
14 changes: 7 additions & 7 deletions core/embed/rust/src/ui/layout_delizia/component/frame.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{theme, ButtonStyleSheet, Footer, Header};
use super::{header::HeaderMsg, theme, ButtonStyleSheet, Footer, Header};
use crate::{
strutil::TString,
ui::{
Expand Down Expand Up @@ -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())
}

Expand Down
24 changes: 20 additions & 4 deletions core/embed/rust/src/ui/layout_delizia/component/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HeaderMsg> 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>,
Expand All @@ -70,7 +86,7 @@ pub struct Header {
icon: Option<Icon>,
color: Option<Color>,
title_style: TextStyle,
button_msg: FlowMsg,
button_msg: HeaderMsg,
}

impl Header {
Expand All @@ -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)]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 96ac4e2

Please sign in to comment.