diff --git a/core/embed/rust/src/ui/component/text/paragraphs.rs b/core/embed/rust/src/ui/component/text/paragraphs.rs index 4c86c9fd96..ef8c35c08c 100644 --- a/core/embed/rust/src/ui/component/text/paragraphs.rs +++ b/core/embed/rust/src/ui/component/text/paragraphs.rs @@ -71,6 +71,13 @@ where self } + pub fn add_break(mut self) -> Self { + if let Some(ref mut para) = self.list.last_mut() { + para.break_after = true; + }; + self + } + /// Update bounding boxes of paragraphs on the current page. First determine /// the number of visible paragraphs and their sizes. These are then /// arranged according to the layout. @@ -94,6 +101,10 @@ where remaining_area = free; self.visible += 1; char_offset = 0; + + if paragraph.break_after { + break; + } } self.placement.arrange( @@ -195,6 +206,7 @@ pub mod trace { pub struct Paragraph { content: T, layout: TextLayout, + break_after: bool, } impl Paragraph @@ -202,7 +214,11 @@ where T: AsRef, { pub fn new(content: T, layout: TextLayout) -> Self { - Self { content, layout } + Self { + content, + layout, + break_after: false, + } } pub fn content(&self, char_offset: usize) -> &str { @@ -274,6 +290,11 @@ where current.par += 1; current.chr = 0; progress = true; + + // Handle hard break if requested for this paragraph. + if paragraph.break_after && current.par < self.paragraphs.list.len() { + return self.current; + } } LayoutFit::OutOfBounds { processed_chars, .. diff --git a/core/embed/rust/src/ui/model_tt/component/page.rs b/core/embed/rust/src/ui/model_tt/component/page.rs index a6e5ab4914..f33051c30e 100644 --- a/core/embed/rust/src/ui/model_tt/component/page.rs +++ b/core/embed/rust/src/ui/model_tt/component/page.rs @@ -470,4 +470,32 @@ mod tests { swipe_down(&mut page); assert_eq!(trace(&page), expected1); } + + #[test] + fn paragraphs_hard_break() { + let mut page = SwipePage::new( + Paragraphs::new() + .add(theme::TEXT_NORMAL, "Short one.") + .add_break() + .add(theme::TEXT_NORMAL, "Short two.") + .add_break() + .add(theme::TEXT_NORMAL, "Short three.") + .add_break(), + Empty, + theme::BG, + ); + page.place(SCREEN); + + let expected1 = " buttons: >"; + let expected2 = " buttons: >"; + let expected3 = " buttons: >"; + + assert_eq!(trace(&page), expected1); + swipe_up(&mut page); + assert_eq!(trace(&page), expected2); + swipe_up(&mut page); + assert_eq!(trace(&page), expected3); + swipe_up(&mut page); + assert_eq!(trace(&page), expected3); + } } diff --git a/core/embed/rust/src/ui/model_tt/layout.rs b/core/embed/rust/src/ui/model_tt/layout.rs index 61ee112862..a95d6b399e 100644 --- a/core/embed/rust/src/ui/model_tt/layout.rs +++ b/core/embed/rust/src/ui/model_tt/layout.rs @@ -376,7 +376,7 @@ extern "C" fn new_confirm_modify_output(n_args: usize, args: *const Obj, kwargs: let paragraphs = Paragraphs::new() .add(theme::TEXT_NORMAL, "Address:".into()) .add(theme::TEXT_MONO, address) - // FIXME pagebreak + .add_break() .add(theme::TEXT_NORMAL, description.into()) .add(theme::TEXT_MONO, amount_change) .add(theme::TEXT_NORMAL, "New amount:".into())