diff --git a/core/embed/rust/src/ui/component/text/paragraphs.rs b/core/embed/rust/src/ui/component/text/paragraphs.rs index bedbb8506d..aad2b5f7e0 100644 --- a/core/embed/rust/src/ui/component/text/paragraphs.rs +++ b/core/embed/rust/src/ui/component/text/paragraphs.rs @@ -86,8 +86,10 @@ where &self.source } - pub fn inner_mut(&mut self) -> &mut T { - &mut self.source + pub fn mutate(&mut self, func: impl Fn(&mut T) -> R) -> R { + let result = func(&mut self.source); + self.recalculate_pages(); + result } pub fn area(&self) -> Rect { @@ -186,6 +188,27 @@ where chr = 0; } } + + fn recalculate_pages(&mut self) { + if self.area.is_empty() { + return; + } + let total_pages = self.break_pages_from_start().count().max(1); + self.pager = Pager::new(total_pages as u16); + self.offset = PageOffset::default(); + self.change_offset(self.offset); + } +} + +impl<'a> Paragraphs> { + pub fn content(&self) -> &TString<'a> { + self.source.content() + } + + pub fn update>>(&mut self, content: T) { + self.source.update(content); + self.recalculate_pages(); + } } impl<'a, T> Component for Paragraphs @@ -198,11 +221,8 @@ where let recalc = self.area != bounds; self.area = bounds; if recalc { - self.offset = PageOffset::default(); - let total_pages = self.break_pages_from_start().count().max(1); - self.pager = Pager::new(total_pages as u16); + self.recalculate_pages(); } - self.change_offset(self.offset); self.area } diff --git a/core/embed/rust/src/ui/layout_bolt/component/address_details.rs b/core/embed/rust/src/ui/layout_bolt/component/address_details.rs index 4b28a2c215..38cff4ac9c 100644 --- a/core/embed/rust/src/ui/layout_bolt/component/address_details.rs +++ b/core/embed/rust/src/ui/layout_bolt/component/address_details.rs @@ -99,10 +99,9 @@ impl AddressDetails { let mut dummy_ctx = EventCtx::new(); self.xpub_view.update_title(&mut dummy_ctx, self.xpubs[i].0); self.xpub_view.update_content(&mut dummy_ctx, |p| { - p.inner_mut().update(self.xpubs[i].1); - let npages = p.page_count(); + p.update(self.xpubs[i].1); p.change_page(page); - npages + p.page_count() }) } diff --git a/core/embed/rust/src/ui/layout_bolt/component/dialog.rs b/core/embed/rust/src/ui/layout_bolt/component/dialog.rs index 9301db912a..9242de3817 100644 --- a/core/embed/rust/src/ui/layout_bolt/component/dialog.rs +++ b/core/embed/rust/src/ui/layout_bolt/component/dialog.rs @@ -116,7 +116,9 @@ where pub fn with_paragraph(mut self, para: Paragraph<'static>) -> Self { if !para.content().is_empty() { - self.paragraphs.inner_mut().add(para); + self.paragraphs.mutate(|p| { + p.add(para); + }); } self } diff --git a/core/embed/rust/src/ui/layout_bolt/component/number_input.rs b/core/embed/rust/src/ui/layout_bolt/component/number_input.rs index 0ffaabe61a..1d9158a570 100644 --- a/core/embed/rust/src/ui/layout_bolt/component/number_input.rs +++ b/core/embed/rust/src/ui/layout_bolt/component/number_input.rs @@ -56,10 +56,8 @@ where fn update_text(&mut self, ctx: &mut EventCtx, value: u32) { let text = (self.description_func)(value); - self.paragraphs.mutate(ctx, move |ctx, para| { - para.inner_mut().update(text); - // Recompute bounding box. - para.change_page(0); + self.paragraphs.mutate(ctx, |ctx, p| { + p.update(text); ctx.request_paint() }); self.paragraphs_pad.clear(); diff --git a/core/embed/rust/src/ui/layout_bolt/component/progress.rs b/core/embed/rust/src/ui/layout_bolt/component/progress.rs index 18177938eb..f998cb5217 100644 --- a/core/embed/rust/src/ui/layout_bolt/component/progress.rs +++ b/core/embed/rust/src/ui/layout_bolt/component/progress.rs @@ -81,9 +81,8 @@ impl Component for Progress { ctx.request_paint(); } self.description.mutate(ctx, |ctx, para| { - if para.inner_mut().content() != &new_description { - para.inner_mut().update(new_description); - para.change_page(0); // Recompute bounding box. + if para.content() != &new_description { + para.update(new_description); ctx.request_paint(); self.description_pad.clear(); } diff --git a/core/embed/rust/src/ui/layout_caesar/component/address_details.rs b/core/embed/rust/src/ui/layout_caesar/component/address_details.rs index 0322197273..6fca107c2f 100644 --- a/core/embed/rust/src/ui/layout_caesar/component/address_details.rs +++ b/core/embed/rust/src/ui/layout_caesar/component/address_details.rs @@ -158,7 +158,7 @@ impl AddressDetails { let i = self.current_page - 2; self.xpub_view.update_title(ctx, self.xpubs[i].0); self.xpub_view.update_content(ctx, |p| { - p.inner_mut().update(self.xpubs[i].1); + p.update(self.xpubs[i].1); p.change_page(0) }); } diff --git a/core/embed/rust/src/ui/layout_caesar/component/progress.rs b/core/embed/rust/src/ui/layout_caesar/component/progress.rs index 4d0f7743e2..f41eb9ccf9 100644 --- a/core/embed/rust/src/ui/layout_caesar/component/progress.rs +++ b/core/embed/rust/src/ui/layout_caesar/component/progress.rs @@ -4,7 +4,6 @@ use crate::{ strutil::TString, ui::{ component::{ - paginated::Paginate, text::paragraphs::{Paragraph, Paragraphs}, Child, Component, Event, EventCtx, Label, Never, Pad, }, @@ -119,9 +118,8 @@ impl Component for Progress { self.description.mutate(ctx, |ctx, para| { // NOTE: not doing any change for empty new descriptions // (currently, there is no use-case for deleting the description) - if !new_description.is_empty() && para.inner_mut().content() != &new_description { - para.inner_mut().update(new_description); - para.change_page(0); // Recompute bounding box. + if !new_description.is_empty() && para.content() != &new_description { + para.update(new_description); ctx.request_paint(); self.description_pad.clear(); } diff --git a/core/embed/rust/src/ui/layout_delizia/component/address_details.rs b/core/embed/rust/src/ui/layout_delizia/component/address_details.rs index 0e9b98745c..9e625428dd 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/address_details.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/address_details.rs @@ -92,10 +92,9 @@ impl AddressDetails { let mut dummy_ctx = EventCtx::new(); self.xpub_view.update_title(&mut dummy_ctx, self.xpubs[i].0); self.xpub_view.update_content(&mut dummy_ctx, |_ctx, p| { - p.inner_mut().update(self.xpubs[i].1); - let npages = p.pager().total() as usize; + p.update(self.xpubs[i].1); p.change_page(page); - npages + p.pager().total() as usize }) } diff --git a/core/embed/rust/src/ui/layout_delizia/component/fido.rs b/core/embed/rust/src/ui/layout_delizia/component/fido.rs index 3da375857d..8aa6e183c5 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/fido.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/fido.rs @@ -64,7 +64,7 @@ impl TString<'static>> Component for FidoCredential { fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option { if let Event::Attach(_) = event { - self.text.inner_mut()[1].update((self.get_account)()); + self.text.mutate(|p| p[1].update((self.get_account)())); ctx.request_paint(); } self.app_icon.event(ctx, event); diff --git a/core/embed/rust/src/ui/layout_delizia/component/progress.rs b/core/embed/rust/src/ui/layout_delizia/component/progress.rs index db00518270..887f3b7e65 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/progress.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/progress.rs @@ -4,7 +4,6 @@ use crate::{ strutil::TString, ui::{ component::{ - paginated::Paginate, text::paragraphs::{Paragraph, Paragraphs}, Component, Event, EventCtx, Label, Never, Pad, }, @@ -77,9 +76,8 @@ impl Component for Progress { if !animation_disabled() { ctx.request_paint(); } - if self.description.inner_mut().content() != &new_description { - self.description.inner_mut().update(new_description); - self.description.change_page(0); // Recompute bounding box. + if self.description.content() != &new_description { + self.description.update(new_description); ctx.request_paint(); self.description_pad.clear(); } diff --git a/core/embed/rust/src/ui/layout_delizia/component/updatable_more_info.rs b/core/embed/rust/src/ui/layout_delizia/component/updatable_more_info.rs index 74d567f10e..023a844b49 100644 --- a/core/embed/rust/src/ui/layout_delizia/component/updatable_more_info.rs +++ b/core/embed/rust/src/ui/layout_delizia/component/updatable_more_info.rs @@ -37,8 +37,7 @@ where fn update_text(&mut self, ctx: &mut EventCtx) { let text = (self.info_func)(); - self.paragraphs.inner_mut().update(text); - self.paragraphs.change_page(0); + self.paragraphs.update(text); ctx.request_paint(); } }