mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
fix interfaces in GAM for stateful lists
This commit is contained in:
parent
49456db837
commit
381dee01eb
2 changed files with 16 additions and 28 deletions
|
|
@ -153,46 +153,29 @@ impl RadioButtonPayload {
|
||||||
pub fn clear(&mut self) { self.0.0.clear(); }
|
pub fn clear(&mut self) { self.0.0.clear(); }
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
#[derive(Debug, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||||
pub struct CheckBoxPayload(pub [Option<ItemName>; MAX_ITEMS]); // returns a list of potential items that could be selected
|
pub struct CheckBoxPayload(Vec<ItemName>); // returns a list of potential items that could be selected
|
||||||
impl CheckBoxPayload {
|
impl CheckBoxPayload {
|
||||||
pub fn new() -> Self { CheckBoxPayload([const { None }; MAX_ITEMS]) }
|
pub fn new() -> Self { CheckBoxPayload(Vec::new()) }
|
||||||
|
|
||||||
pub fn payload(self) -> [Option<ItemName>; MAX_ITEMS] { self.0 }
|
pub fn payload(self) -> Vec<ItemName> { self.0 }
|
||||||
|
|
||||||
pub fn contains(&self, name: &str) -> bool {
|
pub fn contains(&self, name: &str) -> bool { self.0.iter().any(|item| item.0 == name) }
|
||||||
for maybe_item in self.0.iter() {
|
|
||||||
if let Some(item) = maybe_item {
|
|
||||||
if item.as_str() == name {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add(&mut self, name: &str) -> bool {
|
pub fn add(&mut self, name: &str) -> bool {
|
||||||
if self.contains(name) {
|
if self.contains(name) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for maybe_item in self.0.iter_mut() {
|
self.0.push(ItemName::new(name));
|
||||||
if maybe_item.is_none() {
|
true
|
||||||
*maybe_item = Some(ItemName::new(name));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&mut self, name: &str) -> bool {
|
pub fn remove(&mut self, name: &str) -> bool {
|
||||||
for maybe_item in self.0.iter_mut() {
|
if let Some(pos) = self.0.iter().position(|item| item.0 == name) {
|
||||||
if let Some(item) = maybe_item {
|
self.0.remove(pos);
|
||||||
if item.as_str() == name {
|
true
|
||||||
*maybe_item = None;
|
} else {
|
||||||
return true;
|
false
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,11 @@ impl CheckBoxes {
|
||||||
|
|
||||||
pub fn add_item(&mut self, new_item: ItemName) { self.items.push(new_item); }
|
pub fn add_item(&mut self, new_item: ItemName) { self.items.push(new_item); }
|
||||||
|
|
||||||
|
pub fn add_checked_item(&mut self, new_item: ItemName) {
|
||||||
|
self.action_payload.add(&new_item.0);
|
||||||
|
self.items.push(new_item);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn clear_items(&mut self) { self.items.clear(); }
|
pub fn clear_items(&mut self) { self.items.clear(); }
|
||||||
}
|
}
|
||||||
impl ActionApi for CheckBoxes {
|
impl ActionApi for CheckBoxes {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue