mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-03 16:56:07 +00:00
refactor(core): reduce ui::layout_delizia::component::header::Header
size
[no changelog]
This commit is contained in:
parent
830f038360
commit
96ac4e263c
@ -1,4 +1,4 @@
|
|||||||
use super::{theme, ButtonStyleSheet, Footer, Header};
|
use super::{header::HeaderMsg, theme, ButtonStyleSheet, Footer, Header};
|
||||||
use crate::{
|
use crate::{
|
||||||
strutil::TString,
|
strutil::TString,
|
||||||
ui::{
|
ui::{
|
||||||
@ -139,31 +139,31 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[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.header = self.header.with_button(icon, enabled, msg);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_cancel_button(self) -> 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 {
|
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 {
|
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())
|
.button_styled(theme::button_warning_high())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_warning_low_icon(self) -> Self {
|
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())
|
.button_styled(theme::button_warning_low())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_danger_icon(self) -> Self {
|
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())
|
.button_styled(theme::button_danger())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,22 @@ impl AttachAnimation {
|
|||||||
|
|
||||||
const BUTTON_EXPAND_BORDER: i16 = 32;
|
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 {
|
pub struct Header {
|
||||||
area: Rect,
|
area: Rect,
|
||||||
title: Label<'static>,
|
title: Label<'static>,
|
||||||
@ -70,7 +86,7 @@ pub struct Header {
|
|||||||
icon: Option<Icon>,
|
icon: Option<Icon>,
|
||||||
color: Option<Color>,
|
color: Option<Color>,
|
||||||
title_style: TextStyle,
|
title_style: TextStyle,
|
||||||
button_msg: FlowMsg,
|
button_msg: HeaderMsg,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Header {
|
impl Header {
|
||||||
@ -84,7 +100,7 @@ impl Header {
|
|||||||
icon: None,
|
icon: None,
|
||||||
color: None,
|
color: None,
|
||||||
title_style: theme::label_title_main(),
|
title_style: theme::label_title_main(),
|
||||||
button_msg: FlowMsg::Cancelled,
|
button_msg: HeaderMsg::Cancelled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
@ -133,7 +149,7 @@ impl Header {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[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);
|
let touch_area = Insets::uniform(BUTTON_EXPAND_BORDER);
|
||||||
self.button = Some(
|
self.button = Some(
|
||||||
Button::with_icon(icon)
|
Button::with_icon(icon)
|
||||||
@ -207,7 +223,7 @@ impl Component for Header {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ButtonMsg::Clicked) = self.button.event(ctx, event) {
|
if let Some(ButtonMsg::Clicked) = self.button.event(ctx, event) {
|
||||||
return Some(self.button_msg.clone());
|
return Some(self.button_msg.into());
|
||||||
};
|
};
|
||||||
|
|
||||||
None
|
None
|
||||||
|
Loading…
Reference in New Issue
Block a user