diff --git a/core/embed/rust/src/ui/geometry.rs b/core/embed/rust/src/ui/geometry.rs index 10f2f64a80..a777914b5d 100644 --- a/core/embed/rust/src/ui/geometry.rs +++ b/core/embed/rust/src/ui/geometry.rs @@ -539,6 +539,10 @@ impl Insets { } } + pub const fn zero() -> Self { + Self::new(0, 0, 0, 0) + } + pub const fn uniform(d: i16) -> Self { Self::new(d, d, d, d) } diff --git a/core/embed/rust/src/ui/layout_bolt/component/button.rs b/core/embed/rust/src/ui/layout_bolt/component/button.rs index 60c9bb3505..81a65e01d7 100644 --- a/core/embed/rust/src/ui/layout_bolt/component/button.rs +++ b/core/embed/rust/src/ui/layout_bolt/component/button.rs @@ -37,7 +37,7 @@ pub trait SelectHandler = Fn(ButtonMsg) -> Option; pub struct Button { area: Rect, - touch_expand: Option, + touch_expand: Insets, content: ButtonContent, styles: ButtonStyleSheet, state: State, @@ -55,7 +55,7 @@ impl Button { Self { content, area: Rect::zero(), - touch_expand: None, + touch_expand: Insets::zero(), styles: theme::button_default(), state: State::Initial, long_press: Duration::ZERO, @@ -90,7 +90,7 @@ impl Button { } pub const fn with_expanded_touch_area(mut self, expand: Insets) -> Self { - self.touch_expand = Some(expand); + self.touch_expand = expand; self } @@ -235,11 +235,7 @@ impl Component for Button { } fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option { - let touch_area = if let Some(expand) = self.touch_expand { - self.area.outset(expand) - } else { - self.area - }; + let touch_area = self.area.outset(self.touch_expand); match event { Event::Touch(TouchEvent::TouchStart(pos)) => { diff --git a/core/embed/rust/src/ui/layout_delizia/component/button.rs b/core/embed/rust/src/ui/layout_delizia/component/button.rs index fa9f5f1f54..b6225903e6 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/button.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/button.rs @@ -24,7 +24,7 @@ pub enum ButtonMsg { pub struct Button { area: Rect, - touch_expand: Option, + touch_expand: Insets, content: ButtonContent, styles: ButtonStyleSheet, text_align: Alignment, @@ -45,7 +45,7 @@ impl Button { Self { content, area: Rect::zero(), - touch_expand: None, + touch_expand: Insets::zero(), styles: theme::button_default(), text_align: Alignment::Start, radius: None, @@ -83,7 +83,7 @@ impl Button { } pub const fn with_expanded_touch_area(mut self, expand: Insets) -> Self { - self.touch_expand = Some(expand); + self.touch_expand = expand; self } @@ -255,11 +255,7 @@ impl Component for Button { } fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option { - let touch_area = if let Some(expand) = self.touch_expand { - self.area.outset(expand) - } else { - self.area - }; + let touch_area = self.area.outset(self.touch_expand); match event { Event::Touch(TouchEvent::TouchStart(pos)) => { diff --git a/core/embed/rust/src/ui/layout_eckhart/component/button.rs b/core/embed/rust/src/ui/layout_eckhart/component/button.rs index 5bdaad96cb..77618722f9 100644 --- a/core/embed/rust/src/ui/layout_eckhart/component/button.rs +++ b/core/embed/rust/src/ui/layout_eckhart/component/button.rs @@ -29,7 +29,7 @@ pub enum ButtonMsg { pub struct Button { area: Rect, - touch_expand: Option, + touch_expand: Insets, content: ButtonContent, content_offset: Offset, stylesheet: ButtonStyleSheet, @@ -66,7 +66,7 @@ impl Button { content, content_offset: Offset::zero(), area: Rect::zero(), - touch_expand: None, + touch_expand: Insets::zero(), stylesheet: theme::button_default(), text_align: Alignment::Center, radius: None, @@ -160,7 +160,7 @@ impl Button { } pub const fn with_expanded_touch_area(mut self, expand: Insets) -> Self { - self.touch_expand = Some(expand); + self.touch_expand = expand; self } @@ -237,7 +237,7 @@ impl Button { } pub fn set_expanded_touch_area(&mut self, expand: Insets) { - self.touch_expand = Some(expand); + self.touch_expand = expand; } pub fn set_content_offset(&mut self, offset: Offset) { @@ -323,8 +323,7 @@ impl Button { } pub fn touch_area(&self) -> Rect { - self.touch_expand - .map_or(self.area, |expand| self.area.outset(expand)) + self.area.outset(self.touch_expand) } fn set(&mut self, ctx: &mut EventCtx, state: State) {