From 78656bdfff8564808919a3dcf3f387ff55f19164 Mon Sep 17 00:00:00 2001 From: Lukas Bielesch Date: Mon, 17 Feb 2025 23:02:29 +0100 Subject: [PATCH] feat(eckhart): Add parametrized content offset to Button --- .../src/ui/layout_eckhart/component/button.rs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) 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 ae5a1145dd..4fd60e5f09 100644 --- a/core/embed/rust/src/ui/layout_eckhart/component/button.rs +++ b/core/embed/rust/src/ui/layout_eckhart/component/button.rs @@ -26,6 +26,7 @@ pub struct Button { area: Rect, touch_expand: Option, content: ButtonContent, + content_offset: Offset, styles: ButtonStyleSheet, text_align: Alignment, radius: Option, @@ -36,13 +37,13 @@ pub struct Button { } impl Button { - pub const BASELINE_OFFSET: Offset = Offset::new(12, 6); const LINE_SPACING: i16 = 7; const SUBTEXT_STYLE: TextStyle = theme::label_menu_item_subtitle(); pub const fn new(content: ButtonContent) -> Self { Self { content, + content_offset: Offset::zero(), area: Rect::zero(), touch_expand: None, styles: theme::button_default(), @@ -85,6 +86,11 @@ impl Button { self } + pub const fn with_content_offset(mut self, offset: Offset) -> Self { + self.content_offset = offset; + self + } + pub const fn with_expanded_touch_area(mut self, expand: Insets) -> Self { self.touch_expand = Some(expand); self @@ -157,6 +163,10 @@ impl Button { &self.content } + pub fn content_offset(&self) -> Offset { + self.content_offset + } + pub fn content_height(&self) -> i16 { match &self.content { ButtonContent::Empty => 0, @@ -238,11 +248,9 @@ impl Button { ButtonContent::Text(text) => { let y_offset = Offset::y(self.content_height() / 2); let start_of_baseline = match self.text_align { - Alignment::Start => { - self.area.left_center() + Offset::x(Self::BASELINE_OFFSET.x) - } + Alignment::Start => self.area.left_center() + self.content_offset, Alignment::Center => self.area.center(), - Alignment::End => self.area.right_center() - Offset::x(Self::BASELINE_OFFSET.x), + Alignment::End => self.area.right_center() - self.content_offset, } + y_offset; text.map(|text| { shape::Text::new(start_of_baseline, text, style.font) @@ -257,11 +265,9 @@ impl Button { Offset::y(self.content_height() / 2 - self.style().font.allcase_text_height()); let subtext_y_offset = Offset::y(self.content_height() / 2); let start_of_baseline = match self.text_align { - Alignment::Start => { - self.area.left_center() + Offset::x(Self::BASELINE_OFFSET.x) - } + Alignment::Start => self.area.left_center() + self.content_offset, Alignment::Center => self.area.center(), - Alignment::End => self.area.right_center() - Offset::x(Self::BASELINE_OFFSET.x), + Alignment::End => self.area.right_center() - self.content_offset, }; let text_baseline = start_of_baseline - text_y_offset; let subtext_baseline = start_of_baseline + subtext_y_offset; @@ -290,13 +296,7 @@ impl Button { .render(target); } ButtonContent::IconAndText(child) => { - child.render( - target, - self.area, - self.style(), - Self::BASELINE_OFFSET, - alpha, - ); + child.render(target, self.area, self.style(), self.content_offset, alpha); } } }