diff --git a/libs/ux-api/src/menu.rs b/libs/ux-api/src/menu.rs index 96faa8c61..bb95b0529 100644 --- a/libs/ux-api/src/menu.rs +++ b/libs/ux-api/src/menu.rs @@ -67,7 +67,6 @@ pub struct Menu<'a> { pub gfx: Gfx, pub sid: xous::SID, pub items: Vec, - pub index: usize, // currently selected item pub helper_data: Option>, pub name: String, pub list: ScrollableList, // UI rendering element @@ -106,7 +105,6 @@ impl<'a> Menu<'a> { gfx: Gfx::new(&xns).unwrap(), sid, items: Vec::new(), - index: 0, helper_data: None, name: String::from(name), list, @@ -116,7 +114,7 @@ impl<'a> Menu<'a> { } } - pub fn set_index(&mut self, index: usize) { self.index = index; } + pub fn set_index(&mut self, index: usize) { self.list.set_selected(0, index).unwrap() } /// this function spawns a client-side thread to forward redraw and key event /// messages on to a local server. The goal is to keep the local server's SID @@ -219,7 +217,9 @@ impl<'a> Menu<'a> { log::debug!("got key '{}'", k); match k { '∴' => { - let mi = &self.items[self.index]; + let (_, selected) = self.list.get_selected_index(); + log::info!("selected index {}", selected); + let mi = &self.items[selected]; if let Some(action) = mi.action_conn { log::debug!("doing menu action for {}", mi.name); match mi.action_payload { @@ -241,7 +241,7 @@ impl<'a> Menu<'a> { } } } - self.index = 0; // reset the index to 0 + self.list.set_selected(0, 0).ok(); // reset selection if !mi.close_on_select { self.redraw(); } else { diff --git a/libs/ux-api/src/widgets/scroll.rs b/libs/ux-api/src/widgets/scroll.rs index 12bb21298..da55c4546 100644 --- a/libs/ux-api/src/widgets/scroll.rs +++ b/libs/ux-api/src/widgets/scroll.rs @@ -36,6 +36,7 @@ pub enum TextAlignment { pub struct ScrollableList { items: Vec>, /// corresponds to the index into `items` that should be rendered as selected + /// format is (col, row) select_index: (usize, usize), /// offset in the list that represents the top left drawable item scroll_offset: (usize, usize),