diff --git a/libs/ux-api/src/widgets/checkboxes.rs b/libs/ux-api/src/widgets/checkboxes.rs index 92aeccd0b..2243b9d33 100644 --- a/libs/ux-api/src/widgets/checkboxes.rs +++ b/libs/ux-api/src/widgets/checkboxes.rs @@ -43,7 +43,7 @@ fn replace_first_char(s: &str, replacement: char) -> String { use crate::widgets::ActionApi; impl ActionApi for CheckBoxes { fn height(&self, _glyph_height: isize, _margin: isize, _modal: &Modal) -> isize { - (self.items.len() * self.items.row_height()) as isize + ((self.items.len() + 1) * self.items.row_height()) as isize } fn redraw(&self, at_height: isize, _modal: &Modal) { self.items.draw(at_height); } diff --git a/libs/ux-api/src/widgets/payload.rs b/libs/ux-api/src/widgets/payload.rs index 52fc54a5c..63afa1bd1 100644 --- a/libs/ux-api/src/widgets/payload.rs +++ b/libs/ux-api/src/widgets/payload.rs @@ -21,7 +21,7 @@ pub struct Bip39EntryPayload { #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone, Eq, PartialEq, Default)] pub struct TextEntryPayload { - dirty: bool, + pub dirty: bool, pub content: String, pub placeholder: Option, pub placeholder_persist: bool, diff --git a/libs/ux-api/src/widgets/radiobuttons.rs b/libs/ux-api/src/widgets/radiobuttons.rs index 31ff59e64..43e19029e 100644 --- a/libs/ux-api/src/widgets/radiobuttons.rs +++ b/libs/ux-api/src/widgets/radiobuttons.rs @@ -52,13 +52,15 @@ impl ActionApi for RadioButtons { } '∴' | '\u{d}' => { self.action_payload = RadioButtonPayload::new(self.items.get_selected()); + + self.items.gfx.release_modal().unwrap(); xous::yield_slice(); + let buf = xous_ipc::Buffer::into_buf(self.action_payload.clone()) .expect("couldn't convert message to payload"); buf.send(self.action_conn, self.action_opcode) .map(|_| ()) .expect("couldn't send action message"); - self.items.gfx.release_modal().unwrap(); return None; } '\u{0}' => { diff --git a/libs/ux-api/src/widgets/scroll.rs b/libs/ux-api/src/widgets/scroll.rs index 2c89fda35..ffc230ac5 100644 --- a/libs/ux-api/src/widgets/scroll.rs +++ b/libs/ux-api/src/widgets/scroll.rs @@ -54,6 +54,26 @@ pub struct ScrollableList { pub gfx: Gfx, } +impl Clone for ScrollableList { + fn clone(&self) -> Self { + let mut sl = ScrollableList::default() + .pane_size(self.pane()) + .set_min_col_width(self.min_col_width) + .style(self.style) + .set_with_scrollbars(self.with_scrollbars) + .set_margin(self.margin); + let items = self.get_all(); + for (c, cols) in items.enumerate() { + for row in cols { + sl.add_item(c, row); + } + } + sl.set_scroll_offset(self.scroll_offset.0, self.scroll_offset.1).ok(); + sl.set_selected(self.select_index.0, self.select_index.1).ok(); + sl + } +} + impl ScrollableList { pub fn default() -> Self { let xns = xous_names::XousNames::new().unwrap(); @@ -90,6 +110,8 @@ impl ScrollableList { self } + pub fn get_style(&self) -> GlyphStyle { self.style } + pub fn add_item(&mut self, column: usize, item: &str) { // create columns, if they don't already exist if (column + 1) > self.items.len() { @@ -163,7 +185,7 @@ impl ScrollableList { /// Set the selected element in the scrollable array /// /// Returns `Err(())` if the indices are out of range, without updating anything. - pub fn set_selected(&mut self, row: usize, col: usize) -> Result<(), ()> { + pub fn set_selected(&mut self, col: usize, row: usize) -> Result<(), ()> { if col < self.items.len() { if row < self.items[col].len() { self.select_index = (row, col); @@ -180,7 +202,7 @@ impl ScrollableList { /// it designates the top left element on the screen. /// /// Returns `Err(())` if the indices are out of range, without updating anything. - pub fn set_scroll_offset(&mut self, row: usize, col: usize) -> Result<(), ()> { + pub fn set_scroll_offset(&mut self, col: usize, row: usize) -> Result<(), ()> { if col < self.items.len() { if row < self.items[col].len() { self.scroll_offset = (row, col); @@ -265,6 +287,12 @@ impl ScrollableList { self.items.iter().map(|inner_vec| inner_vec.iter().map(|s| s.as_str())) } + /// Returns a reference to the requested column; None if the column is out of range + pub fn get_column(&self, column: usize) -> Option<&Vec> { + // create columns, if they don't already exist + if column < self.items.len() { Some(&self.items[column]) } else { None } + } + /// Returns only the index into the list of items that is selected pub fn get_selected_index(&self) -> (usize, usize) { self.select_index }