diff --git a/services/gam/src/api.rs b/services/gam/src/api.rs index 4040fa442..608bf200f 100644 --- a/services/gam/src/api.rs +++ b/services/gam/src/api.rs @@ -244,7 +244,7 @@ pub(crate) struct GamActivation { pub(crate) result: Option, } -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)] pub(crate) struct MenuManagement { pub(crate) item: MenuItem, pub(crate) op: MenuMgrOp, diff --git a/services/gam/src/api/rkyv_enum.rs b/services/gam/src/api/rkyv_enum.rs index 042245f85..84782497c 100644 --- a/services/gam/src/api/rkyv_enum.rs +++ b/services/gam/src/api/rkyv_enum.rs @@ -34,7 +34,7 @@ pub(crate) enum Return { NotCurrentlyDrawable, } -#[derive(Debug, Eq, PartialEq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] +#[derive(Debug, Eq, PartialEq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)] pub(crate) enum MenuMgrOp { // incoming is one of these ops AddItem, diff --git a/services/gam/src/menu.rs b/services/gam/src/menu.rs index da436a56f..fe2d14307 100644 --- a/services/gam/src/menu.rs +++ b/services/gam/src/menu.rs @@ -184,7 +184,7 @@ impl<'a> Menu<'a> { // something) pub fn delete_item(&mut self, item: &str) -> bool { let len_before = self.items.len(); - self.items.retain(|&candidate| candidate.name.as_str() != item); + self.items.retain(|candidate| candidate.name.as_str() != item); // now, recompute the height let mut total_items = self.num_items(); @@ -208,7 +208,7 @@ impl<'a> Menu<'a> { use core::fmt::Write; let canvas_size = self.gam.get_canvas_bounds(self.canvas).unwrap(); - let item = self.items[index as usize]; + let item = &self.items[index as usize]; let mut item_tv = TextView::new( self.canvas, TextBounds::BoundingBox(Rectangle::new( @@ -357,7 +357,7 @@ impl<'a> Menu<'a> { log::debug!("got key '{}'", k); match k { '∴' => { - let mi = self.items[self.index]; + let mi = &self.items[self.index]; // give up focus before issuing the command, as some commands conflict with loss of // focus... if mi.close_on_select { @@ -562,12 +562,12 @@ pub fn menu_matic( .expect("menu manager received unexpected message type"); match mgmt.op { MenuMgrOp::AddItem => { - menu.lock().unwrap().add_item(mgmt.item); + menu.lock().unwrap().add_item(mgmt.item.clone()); mgmt.op = MenuMgrOp::Ok; buffer.replace(mgmt).unwrap(); } MenuMgrOp::InsertItem(at) => { - if menu.lock().unwrap().insert_item(mgmt.item, at) { + if menu.lock().unwrap().insert_item(mgmt.item.clone(), at) { mgmt.op = MenuMgrOp::Ok; buffer.replace(mgmt).unwrap(); } else { diff --git a/services/gam/src/modal/checkboxes.rs b/services/gam/src/modal/checkboxes.rs index 89fda5bb6..eea6543b8 100644 --- a/services/gam/src/modal/checkboxes.rs +++ b/services/gam/src/modal/checkboxes.rs @@ -209,8 +209,8 @@ impl ActionApi for CheckBoxes { self.gam.relinquish_focus().unwrap(); xous::yield_slice(); - let buf = - Buffer::into_buf(self.action_payload).expect("couldn't convert message to payload"); + let buf = 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"); diff --git a/services/gam/src/modal/consoleinput.rs b/services/gam/src/modal/consoleinput.rs index 874f6b3b1..dc0cc8722 100644 --- a/services/gam/src/modal/consoleinput.rs +++ b/services/gam/src/modal/consoleinput.rs @@ -13,7 +13,7 @@ impl Clone for ConsoleInput { ConsoleInput { action_conn: self.action_conn, action_opcode: self.action_opcode, - action_payload: self.action_payload, + action_payload: self.action_payload.clone(), gam: crate::Gam::new(&xous_names::XousNames::new().unwrap()).unwrap(), } } @@ -48,7 +48,8 @@ impl ActionApi for ConsoleInput { self.gam.relinquish_focus().unwrap(); xous::yield_slice(); - let buf = Buffer::into_buf(self.action_payload).expect("couldn't convert message to payload"); + let buf = 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"); @@ -56,7 +57,7 @@ impl ActionApi for ConsoleInput { } _ => { // text entry - self.action_payload.content.push(k).expect("ran out of space storing password"); + self.action_payload.content.push(k); log::trace!("****update payload: {}", self.action_payload.content); } } diff --git a/services/gam/src/modal/progressbar.rs b/services/gam/src/modal/progressbar.rs index f2bdbbcfa..8250f90e1 100644 --- a/services/gam/src/modal/progressbar.rs +++ b/services/gam/src/modal/progressbar.rs @@ -69,7 +69,14 @@ impl<'a, 'b> ProgressBar<'a, 'b> { if new_percent != self.current_progress_percent { log::debug!("progress: {}", new_percent); self.slider.set_state(new_percent); - self.modal.modify(Some(crate::ActionType::Slider(*self.slider)), None, false, None, false, None); + self.modal.modify( + Some(crate::ActionType::Slider(self.slider.clone())), + None, + false, + None, + false, + None, + ); self.modal.redraw(); // stage the modal box pixels to the back buffer xous::yield_slice(); // this gives time for the GAM to do the sending self.current_progress_percent = new_percent; diff --git a/services/gam/src/modal/radiobuttons.rs b/services/gam/src/modal/radiobuttons.rs index aa6ed35b8..f082fff3f 100644 --- a/services/gam/src/modal/radiobuttons.rs +++ b/services/gam/src/modal/radiobuttons.rs @@ -194,8 +194,8 @@ impl ActionApi for RadioButtons { self.gam.relinquish_focus().unwrap(); xous::yield_slice(); - let buf = - Buffer::into_buf(self.action_payload).expect("couldn't convert message to payload"); + let buf = 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"); diff --git a/services/gam/src/modal/slider.rs b/services/gam/src/modal/slider.rs index 500d4caa0..3ac94fef4 100644 --- a/services/gam/src/modal/slider.rs +++ b/services/gam/src/modal/slider.rs @@ -8,7 +8,7 @@ use crate::*; // the enum_actions API to update the progress state in an efficient manner. // Thus it does not include its own GAM reference; instead we create one on // the fly when needed. -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Clone)] pub struct Slider { pub min: u32, pub max: u32, @@ -132,7 +132,7 @@ impl ActionApi for Slider { // estimate width of current setting tv.bounds_computed = None; tv.bounds_hint = TextBounds::GrowableFromTl(Point::new(0, 0), maxwidth); - write!(tv, "{}{}", self.action_payload, self.units.to_str()).unwrap(); + write!(tv, "{}{}", self.action_payload, &self.units).unwrap(); modal.gam.bounds_compute_textview(&mut tv).expect("couldn't simulate text size"); let textwidth = if let Some(bounds) = tv.bounds_computed { bounds.br.x - bounds.tl.x diff --git a/services/gam/src/modal/textentry.rs b/services/gam/src/modal/textentry.rs index 7a005ec68..98176f7ee 100644 --- a/services/gam/src/modal/textentry.rs +++ b/services/gam/src/modal/textentry.rs @@ -16,11 +16,11 @@ pub type ValidatorErr = String; pub type Payloads = [TextEntryPayload; MAX_FIELDS as usize]; -#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone, Eq, PartialEq, Default)] +#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone, Eq, PartialEq, Default)] pub struct TextEntryPayloads(Payloads, usize); impl TextEntryPayloads { - pub fn first(&self) -> TextEntryPayload { self.0[0] } + pub fn first(&self) -> TextEntryPayload { self.0[0].clone() } pub fn content(&self) -> Vec { self.0[..self.1].to_vec() } } @@ -623,7 +623,7 @@ impl ActionApi for TextEntry { } } if let Some(validator) = self.validator { - if let Some(err_msg) = validator(*payload, self.action_opcode) { + if let Some(err_msg) = validator(payload.clone(), self.action_opcode) { payload.content.clear(); // reset the input field return Some(err_msg); } @@ -646,8 +646,12 @@ impl ActionApi for TextEntry { let mut payloads: TextEntryPayloads = Default::default(); payloads.1 = self.max_field_amount as usize; - payloads.0[..self.max_field_amount as usize] - .copy_from_slice(&self.action_payloads[..self.max_field_amount as usize]); + for (dst, src) in payloads.0[..self.max_field_amount as usize] + .iter_mut() + .zip(self.action_payloads[..self.max_field_amount as usize].iter()) + { + *dst = src.clone(); + } let buf = Buffer::into_buf(payloads).expect("couldn't convert message to payload"); buf.send(self.action_conn, self.action_opcode) .map(|_| ())