mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
manual cleanup Copy derive: gam crate
There isn't a simple regex to deal with the loss of Copy when deprecating xous_ipc, so this has to be a manual pass. Losing the copy trait means (maybe) some loss of efficiency in the API because we have to clone some structures instead of copying them, although, I think actually what might have been happening under the hood anyways is the copy was implemented as a clone-under-the-hood for the xous-ipc. Either way, this happens in the high level management structures for modals, so it's not the end of the world to incur a clone on the description of the structures -- we'd have to pay more attention if this happened e.g. at the pixel shuffling level, but a few UI strings at human-interaction rates isn't going to kill us.
This commit is contained in:
parent
f8719d781e
commit
58527ea38b
9 changed files with 34 additions and 22 deletions
|
|
@ -244,7 +244,7 @@ pub(crate) struct GamActivation {
|
|||
pub(crate) result: Option<ActivationResult>,
|
||||
}
|
||||
|
||||
#[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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<TextEntryPayload> { 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(|_| ())
|
||||
|
|
|
|||
Loading…
Reference in a new issue