diff --git a/core/embed/rust/src/ui/model_mercury/component/footer.rs b/core/embed/rust/src/ui/model_mercury/component/footer.rs index e8055b3663..7ee6e2a08a 100644 --- a/core/embed/rust/src/ui/model_mercury/component/footer.rs +++ b/core/embed/rust/src/ui/model_mercury/component/footer.rs @@ -45,11 +45,14 @@ impl<'a> Footer<'a> { const STYLE_INSTRUCTION: &'static TextStyle = &theme::TEXT_SUB_GREY; const STYLE_DESCRIPTION: &'static TextStyle = &theme::TEXT_SUB_GREY_LIGHT; - pub fn new>>(instruction: T) -> Self { + pub fn new>>( + instruction: T, + description: Option>, + ) -> Self { Self { area: Rect::zero(), instruction: instruction.into(), - content: None, + content: description.map(FooterContent::Description), swipe_allow_down: false, swipe_allow_up: false, progress: 0, @@ -57,13 +60,6 @@ impl<'a> Footer<'a> { } } - pub fn with_description>>(self, description: T) -> Self { - Self { - content: Some(FooterContent::Description(description.into())), - ..self - } - } - pub fn with_page_counter(self, max_pages: u8) -> Self { Self { content: Some(FooterContent::PageCounter(PageCounter::new(max_pages))), @@ -110,16 +106,17 @@ impl<'a> Footer<'a> { } } - pub fn with_swipe_up(self) -> Self { - Self { - swipe_allow_up: true, - ..self - } - } - pub fn with_swipe_down(self) -> Self { - Self { - swipe_allow_down: true, - ..self + pub fn with_swipe(self, swipe_direction: SwipeDirection) -> Self { + match swipe_direction { + SwipeDirection::Up => Self { + swipe_allow_up: true, + ..self + }, + SwipeDirection::Down => Self { + swipe_allow_down: true, + ..self + }, + _ => self, } } } diff --git a/core/embed/rust/src/ui/model_mercury/component/frame.rs b/core/embed/rust/src/ui/model_mercury/component/frame.rs index 174d4f15fe..cc78b6de13 100644 --- a/core/embed/rust/src/ui/model_mercury/component/frame.rs +++ b/core/embed/rust/src/ui/model_mercury/component/frame.rs @@ -1,4 +1,4 @@ -use super::{theme, ButtonMsg, ButtonStyleSheet, CancelInfoConfirmMsg, Footer, Header}; +use super::{theme, ButtonStyleSheet, CancelInfoConfirmMsg, Footer, Header}; use crate::{ strutil::TString, ui::{ @@ -84,7 +84,6 @@ impl HorizontalSwipe { pub struct Frame { border: Insets, bounds: Rect, - button_msg: CancelInfoConfirmMsg, content: T, header: Header, footer: Option>, @@ -106,7 +105,6 @@ where Self { bounds: Rect::zero(), border: theme::borders(), - button_msg: CancelInfoConfirmMsg::Cancelled, content, header: Header::new(alignment, title), footer: None, @@ -145,8 +143,7 @@ where #[inline(never)] fn with_button(mut self, icon: Icon, msg: CancelInfoConfirmMsg, enabled: bool) -> Self { - self.header = self.header.with_button(icon, enabled); - self.button_msg = msg; + self.header = self.header.with_button(icon, enabled, msg); self } @@ -189,17 +186,13 @@ where instruction: TString<'static>, description: Option>, ) -> Self { - let mut footer = Footer::new(instruction); - if let Some(description_text) = description { - footer = footer.with_description(description_text); - } - self.footer = Some(footer); + self.footer = Some(Footer::new(instruction, description)); self } #[inline(never)] pub fn with_footer_counter(mut self, instruction: TString<'static>, max_value: u8) -> Self { - self.footer = Some(Footer::new(instruction).with_page_counter(max_value)); + self.footer = Some(Footer::new(instruction, None).with_page_counter(max_value)); self } @@ -213,8 +206,7 @@ where } pub fn update_title(&mut self, ctx: &mut EventCtx, new_title: TString<'static>) { - self.header.update_title(new_title); - ctx.request_paint(); + self.header.update_title(ctx, new_title); } pub fn update_subtitle( @@ -223,8 +215,7 @@ where new_subtitle: TString<'static>, new_style: Option, ) { - self.header.update_subtitle(new_subtitle, new_style); - ctx.request_paint(); + self.header.update_subtitle(ctx, new_subtitle, new_style); } pub fn update_content(&mut self, ctx: &mut EventCtx, update_fn: F) -> R @@ -244,11 +235,7 @@ where #[inline(never)] pub fn with_swipe(mut self, dir: SwipeDirection, settings: SwipeSettings) -> Self { - self.footer = self.footer.map(|f| match dir { - SwipeDirection::Up => f.with_swipe_up(), - SwipeDirection::Down => f.with_swipe_down(), - _ => f, - }); + self.footer = self.footer.map(|f| f.with_swipe(dir)); self.swipe = self.swipe.with_swipe(dir, settings); self } @@ -275,21 +262,7 @@ where fn place(&mut self, bounds: Rect) -> Rect { self.bounds = bounds; - - let (mut header_area, mut content_area) = bounds.split_top(TITLE_HEIGHT); - content_area = content_area.inset(Insets::top(theme::SPACING)); - header_area = header_area.inset(Insets::sides(theme::SPACING)); - - self.header.place(header_area); - - if let Some(footer) = &mut self.footer { - // FIXME: spacer at the bottom might be applied also for usage without footer - // but not for VerticalMenu - content_area = content_area.inset(Insets::bottom(theme::SPACING)); - let (remaining, footer_area) = content_area.split_bottom(footer.height()); - footer.place(footer_area); - content_area = remaining; - } + let content_area = frame_place(&mut self.header, &mut self.footer, bounds); self.content.place(content_area); @@ -297,9 +270,17 @@ where } fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option { - self.horizontal_swipe.event(event, self.swipe); + if let Some(value) = frame_event( + &mut self.horizontal_swipe, + self.swipe, + &mut self.header, + &mut self.footer, + ctx, + event, + ) { + return Some(FrameMsg::Button(value)); + } - self.footer.event(ctx, event); let msg = self.content.event(ctx, event).map(FrameMsg::Content); if let Some(count) = ctx.page_count() { self.internal_page_cnt = count; @@ -308,9 +289,7 @@ where if msg.is_some() { return msg; } - if let Some(ButtonMsg::Clicked) = self.header.event(ctx, event) { - return Some(FrameMsg::Button(self.button_msg)); - } + None } @@ -328,6 +307,37 @@ where .render_swipe_cover(target, self.bounds); } } +fn frame_event( + horizontal_swipe: &mut HorizontalSwipe, + swipe_config: SwipeConfig, + header: &mut Header, + footer: &mut Option