From c168c7d7205b79a8c7a5da333d370a41fb4f14f5 Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 12 Nov 2025 15:26:17 +0800 Subject: [PATCH] update ui to use builder pattern --- libs/ux-api/src/widgets/bip39entry.rs | 13 ++++++++----- libs/ux-api/src/widgets/checkboxes.rs | 5 +++-- libs/ux-api/src/widgets/radiobuttons.rs | 5 +++-- libs/ux-api/src/widgets/scroll.rs | 16 ++++++++-------- libs/ux-api/src/widgets/textentry.rs | 8 +++++--- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/libs/ux-api/src/widgets/bip39entry.rs b/libs/ux-api/src/widgets/bip39entry.rs index 5590222ae..0bcab8430 100644 --- a/libs/ux-api/src/widgets/bip39entry.rs +++ b/libs/ux-api/src/widgets/bip39entry.rs @@ -69,22 +69,25 @@ pub struct Bip39Entry { impl Default for Bip39Entry { fn default() -> Self { - let mut items = ScrollableList::default().set_margin(Point::new(4, 0)); + let mut items = ScrollableList::default(); + items.set_margin(Point::new(4, 0)); let br = items.pane().br(); let row_height = items.row_height(); - items = items.pane_size(Rectangle::new(Point::new(0, row_height as isize + 2), br)); + items.pane_size(Rectangle::new(Point::new(0, row_height as isize + 2), br)); items.add_item(0, t!("bip39.pick_word", locales::LANG)); items.add_item(0, t!("bip39.scan_qr_code", locales::LANG)); items.add_item(0, t!("bip39.cancel", locales::LANG)); let extra_items = items.col_length(0).unwrap_or(0); - let mut sl = ScrollableList::default().set_margin(Point::new(10, 0)); + let mut sl = ScrollableList::default(); + sl.set_margin(Point::new(10, 0)); let br = sl.pane().br(); let row_height = sl.row_height(); - sl = sl.pane_size(Rectangle::new(Point::new(0, row_height as isize + 2), br)); + sl.pane_size(Rectangle::new(Point::new(0, row_height as isize + 2), br)); - let mut osk = ScrollableList::default().set_alignment(TextAlignment::Center); + let mut osk = ScrollableList::default(); + osk.set_alignment(TextAlignment::Center); match locales::LANG { "en" => { /* diff --git a/libs/ux-api/src/widgets/checkboxes.rs b/libs/ux-api/src/widgets/checkboxes.rs index 2243b9d33..d1013b81c 100644 --- a/libs/ux-api/src/widgets/checkboxes.rs +++ b/libs/ux-api/src/widgets/checkboxes.rs @@ -15,10 +15,11 @@ pub struct CheckBoxes { } impl CheckBoxes { pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self { - let mut sl = ScrollableList::default().set_margin(Point::new(2, 0)); + let mut sl = ScrollableList::default(); + sl.set_margin(Point::new(2, 0)); let br = sl.pane().br(); let row_height = sl.row_height(); - sl = sl.pane_size(Rectangle::new(Point::new(0, row_height as isize + 2), br)); + sl.pane_size(Rectangle::new(Point::new(0, row_height as isize + 2), br)); sl.add_item(0, t!("radio.select_and_close", locales::LANG)); CheckBoxes { items: sl, action_conn, action_opcode, action_payload: CheckBoxPayload::new() } } diff --git a/libs/ux-api/src/widgets/radiobuttons.rs b/libs/ux-api/src/widgets/radiobuttons.rs index 43e19029e..e4a29f607 100644 --- a/libs/ux-api/src/widgets/radiobuttons.rs +++ b/libs/ux-api/src/widgets/radiobuttons.rs @@ -10,10 +10,11 @@ pub struct RadioButtons { } impl RadioButtons { pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self { - let mut sl = ScrollableList::default().set_margin(Point::new(12, 0)); + let mut sl = ScrollableList::default(); + sl.set_margin(Point::new(12, 0)); let br = sl.pane().br(); let row_height = sl.row_height(); - sl = sl.pane_size(Rectangle::new(Point::new(0, row_height as isize + 2), br)); + sl.pane_size(Rectangle::new(Point::new(0, row_height as isize + 2), br)); RadioButtons { items: sl, action_conn, action_opcode, action_payload: RadioButtonPayload::new("") } } diff --git a/libs/ux-api/src/widgets/scroll.rs b/libs/ux-api/src/widgets/scroll.rs index 9a87b1644..12bb21298 100644 --- a/libs/ux-api/src/widgets/scroll.rs +++ b/libs/ux-api/src/widgets/scroll.rs @@ -63,8 +63,8 @@ pub struct ScrollableList { impl Clone for ScrollableList { fn clone(&self) -> Self { - let mut sl = ScrollableList::default() - .pane_size(self.pane()) + let mut sl = ScrollableList::default(); + sl.pane_size(self.pane()) .set_min_col_width(self.min_col_width) .style(self.style) .set_with_scrollbars(self.with_scrollbars) @@ -108,19 +108,19 @@ impl ScrollableList { pub fn get_alignment(&self) -> TextAlignment { self.text_alignment } - pub fn set_alignment(mut self, alignment: TextAlignment) -> Self { + pub fn set_alignment<'a>(&'a mut self, alignment: TextAlignment) -> &'a mut Self { self.text_alignment = alignment; self } - pub fn pane_size(mut self, pane: Rectangle) -> Self { + pub fn pane_size<'a>(&'a mut self, pane: Rectangle) -> &'a mut Self { self.pane = RefCell::new(pane); self } pub fn pane(&self) -> Rectangle { self.pane.borrow().clone() } - pub fn style(mut self, style: GlyphStyle) -> Self { + pub fn style<'a>(&'a mut self, style: GlyphStyle) -> &'a mut Self { self.style = style; self.height_hint = self.gfx.glyph_height_hint(style).unwrap(); self @@ -180,20 +180,20 @@ impl ScrollableList { pub fn row_height(&self) -> usize { self.height_hint } /// Use this to add space around list items for aesthetic tuning. - pub fn set_margin(mut self, margin: Point) -> Self { + pub fn set_margin<'a>(&'a mut self, margin: Point) -> &'a mut Self { self.margin = margin; self } /// Tunes the desired minimum width of a column. - pub fn set_min_col_width(mut self, width: usize) -> Self { + pub fn set_min_col_width<'a>(&'a mut self, width: usize) -> &'a mut Self { self.min_col_width = width; self } /// When `with_bars` is `true`, scroll bars are rendered when only part /// of the list is visible on the screen. - pub fn set_with_scrollbars(mut self, with_bars: bool) -> Self { + pub fn set_with_scrollbars<'a>(&'a mut self, with_bars: bool) -> &'a mut Self { self.with_scrollbars = with_bars; self } diff --git a/libs/ux-api/src/widgets/textentry.rs b/libs/ux-api/src/widgets/textentry.rs index d8230fa08..29fba2ddc 100644 --- a/libs/ux-api/src/widgets/textentry.rs +++ b/libs/ux-api/src/widgets/textentry.rs @@ -53,12 +53,14 @@ pub struct TextEntry { impl Default for TextEntry { fn default() -> Self { - let mut sl = ScrollableList::default().set_margin(Point::new(4, 0)); + let mut sl = ScrollableList::default(); + sl.set_margin(Point::new(4, 0)); let br = sl.pane().br(); let row_height = sl.row_height(); - sl = sl.pane_size(Rectangle::new(Point::new(0, row_height as isize + 2), br)); + sl.pane_size(Rectangle::new(Point::new(0, row_height as isize + 2), br)); - let mut osk = ScrollableList::default().set_alignment(TextAlignment::Center); + let mut osk = ScrollableList::default(); + osk.set_alignment(TextAlignment::Center); match locales::LANG { "en" => { let osk_matrix = en::OSK_MATRIX;