mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
add stateful list creation
this allows us to have "pre-checked" checklists
This commit is contained in:
parent
7d7fa75e7d
commit
98e9d99de8
3 changed files with 37 additions and 22 deletions
|
|
@ -28,6 +28,7 @@ pub struct ManagedPromptWithFixedResponse {
|
||||||
pub struct ManagedListItem {
|
pub struct ManagedListItem {
|
||||||
pub token: [u32; 4],
|
pub token: [u32; 4],
|
||||||
pub item: ItemName,
|
pub item: ItemName,
|
||||||
|
pub state: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)]
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)]
|
||||||
|
|
|
||||||
|
|
@ -595,6 +595,13 @@ impl Modals {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_stateful_list(&self, items: Vec<(bool, &str)>) -> Result<(), xous::Error> {
|
||||||
|
for (_, &(state, text)) in items.iter().enumerate() {
|
||||||
|
self.add_stateful_list_item(state, text).or(Err(xous::Error::InternalError))?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Add individual items to a list to be used by get_radiobutton or get_checkbox.
|
/// Add individual items to a list to be used by get_radiobutton or get_checkbox.
|
||||||
/// - Does not display on its own, the above mentioned methods prompt display of the list.
|
/// - Does not display on its own, the above mentioned methods prompt display of the list.
|
||||||
///
|
///
|
||||||
|
|
@ -610,7 +617,15 @@ impl Modals {
|
||||||
/// ```
|
/// ```
|
||||||
pub fn add_list_item(&self, item: &str) -> Result<(), xous::Error> {
|
pub fn add_list_item(&self, item: &str) -> Result<(), xous::Error> {
|
||||||
self.lock();
|
self.lock();
|
||||||
let itemname = ManagedListItem { token: self.token, item: ItemName::new(item) };
|
let itemname = ManagedListItem { token: self.token, item: ItemName::new(item), state: false };
|
||||||
|
let buf = Buffer::into_buf(itemname).or(Err(xous::Error::InternalError))?;
|
||||||
|
buf.lend(self.conn, Opcode::AddModalItem.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_stateful_list_item(&self, state: bool, item: &str) -> Result<(), xous::Error> {
|
||||||
|
self.lock();
|
||||||
|
let itemname = ManagedListItem { token: self.token, item: ItemName::new(item), state };
|
||||||
let buf = Buffer::into_buf(itemname).or(Err(xous::Error::InternalError))?;
|
let buf = Buffer::into_buf(itemname).or(Err(xous::Error::InternalError))?;
|
||||||
buf.lend(self.conn, Opcode::AddModalItem.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
buf.lend(self.conn, Opcode::AddModalItem.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -739,10 +754,8 @@ impl Modals {
|
||||||
.or(Err(xous::Error::InternalError))?;
|
.or(Err(xous::Error::InternalError))?;
|
||||||
let selected_items = buf.to_original::<CheckBoxPayload, _>().unwrap();
|
let selected_items = buf.to_original::<CheckBoxPayload, _>().unwrap();
|
||||||
let mut ret = Vec::<String>::new();
|
let mut ret = Vec::<String>::new();
|
||||||
for maybe_item in selected_items.payload() {
|
for item in selected_items.payload() {
|
||||||
if let Some(item) = maybe_item {
|
ret.push(String::from(item.as_str()));
|
||||||
ret.push(String::from(item.as_str()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self.unlock();
|
self.unlock();
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ fn wrapped_main() -> ! {
|
||||||
text_action.action_conn = renderer_cid;
|
text_action.action_conn = renderer_cid;
|
||||||
text_action.action_opcode = Opcode::TextEntryReturn.to_u32().unwrap();
|
text_action.action_opcode = Opcode::TextEntryReturn.to_u32().unwrap();
|
||||||
|
|
||||||
let mut fixed_items = Vec::<ItemName>::new();
|
let mut fixed_items = Vec::<(bool, ItemName)>::new();
|
||||||
let mut progress_action = Slider::new(
|
let mut progress_action = Slider::new(
|
||||||
renderer_cid,
|
renderer_cid,
|
||||||
Opcode::SliderReturn.to_u32().unwrap(),
|
Opcode::SliderReturn.to_u32().unwrap(),
|
||||||
|
|
@ -386,7 +386,7 @@ fn wrapped_main() -> ! {
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fixed_items.push(manageditem.item);
|
fixed_items.push((manageditem.state, manageditem.item));
|
||||||
}
|
}
|
||||||
Some(Opcode::GetModalIndex) => {
|
Some(Opcode::GetModalIndex) => {
|
||||||
xous::return_scalar(msg.sender, list_selected as usize)
|
xous::return_scalar(msg.sender, list_selected as usize)
|
||||||
|
|
@ -635,7 +635,7 @@ fn wrapped_main() -> ! {
|
||||||
RadioButtons::new(renderer_cid, Opcode::RadioReturn.to_u32().unwrap());
|
RadioButtons::new(renderer_cid, Opcode::RadioReturn.to_u32().unwrap());
|
||||||
list_hash.clear();
|
list_hash.clear();
|
||||||
list_selected = 0u32;
|
list_selected = 0u32;
|
||||||
for item in fixed_items.iter() {
|
for (_, item) in fixed_items.iter() {
|
||||||
radiobuttons.add_item(item.clone());
|
radiobuttons.add_item(item.clone());
|
||||||
list_hash.insert(item.as_str().to_string(), list_hash.len());
|
list_hash.insert(item.as_str().to_string(), list_hash.len());
|
||||||
}
|
}
|
||||||
|
|
@ -660,8 +660,12 @@ fn wrapped_main() -> ! {
|
||||||
CheckBoxes::new(renderer_cid, Opcode::CheckBoxReturn.to_u32().unwrap());
|
CheckBoxes::new(renderer_cid, Opcode::CheckBoxReturn.to_u32().unwrap());
|
||||||
list_hash.clear();
|
list_hash.clear();
|
||||||
list_selected = 0u32;
|
list_selected = 0u32;
|
||||||
for item in fixed_items.iter() {
|
for (checked, item) in fixed_items.iter() {
|
||||||
checkbox.add_item(item.clone());
|
if *checked {
|
||||||
|
checkbox.add_checked_item(item.clone());
|
||||||
|
} else {
|
||||||
|
checkbox.add_item(item.clone());
|
||||||
|
}
|
||||||
list_hash.insert(item.as_str().to_string(), list_hash.len());
|
list_hash.insert(item.as_str().to_string(), list_hash.len());
|
||||||
}
|
}
|
||||||
fixed_items.clear();
|
fixed_items.clear();
|
||||||
|
|
@ -981,18 +985,15 @@ fn wrapped_main() -> ! {
|
||||||
};
|
};
|
||||||
response.replace(item.clone()).unwrap();
|
response.replace(item.clone()).unwrap();
|
||||||
op = RendererState::None;
|
op = RendererState::None;
|
||||||
for (_, check_item) in item.payload().iter().enumerate() {
|
for (_, item) in item.payload().iter().enumerate() {
|
||||||
match check_item {
|
match list_hash.get(item.as_str()) {
|
||||||
Some(item) => match list_hash.get(item.as_str()) {
|
Some(index) => {
|
||||||
Some(index) => {
|
match index {
|
||||||
match index {
|
0..=31 => drop(list_selected.set_bit(*index, true)),
|
||||||
0..=31 => drop(list_selected.set_bit(*index, true)),
|
_ => log::warn!("invalid bitfield index"),
|
||||||
_ => log::warn!("invalid bitfield index"),
|
};
|
||||||
};
|
}
|
||||||
}
|
None => log::warn!("failed to set list_selected index"),
|
||||||
None => log::warn!("failed to set list_selected index"),
|
|
||||||
},
|
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue