handsfree mode
This commit is contained in:
@@ -123,6 +123,11 @@ impl ComponentCheckbox {
|
||||
common.alterables.mark_redraw();
|
||||
}
|
||||
|
||||
pub fn get_checked(&self) -> bool {
|
||||
let state = self.state.borrow_mut();
|
||||
state.checked
|
||||
}
|
||||
|
||||
pub fn get_value(&self) -> Option<Rc<str>> {
|
||||
self.data.value.clone()
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ impl ComponentRadioGroup {
|
||||
self.state.borrow().selected.as_ref().and_then(|b| b.get_value())
|
||||
}
|
||||
|
||||
pub fn set_value(&self, value: &str) -> anyhow::Result<()> {
|
||||
pub fn set_value_simple(&self, value: &str) -> anyhow::Result<()> {
|
||||
let mut state = self.state.borrow_mut();
|
||||
for radio_box in &state.radio_boxes {
|
||||
if radio_box.get_value().is_some_and(|box_val| &*box_val == value) {
|
||||
@@ -97,6 +97,26 @@ impl ComponentRadioGroup {
|
||||
anyhow::bail!("No RadioBox found with value '{value}'")
|
||||
}
|
||||
|
||||
pub fn set_value(&self, common: &mut CallbackDataCommon, value: &str) -> anyhow::Result<()> {
|
||||
let mut state = self.state.borrow_mut();
|
||||
let mut selected = None;
|
||||
for radio_box in &state.radio_boxes {
|
||||
if radio_box.get_value().is_some_and(|box_val| &*box_val == value) {
|
||||
selected = Some(radio_box.clone());
|
||||
radio_box.set_checked(common, true);
|
||||
} else {
|
||||
radio_box.set_checked(common, false);
|
||||
}
|
||||
}
|
||||
|
||||
if selected.is_some() {
|
||||
state.selected = selected;
|
||||
Ok(())
|
||||
} else {
|
||||
anyhow::bail!("No RadioBox found with value '{value}'")
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_value_changed(&self, callback: RadioValueChangeCallback) {
|
||||
self.state.borrow_mut().on_value_changed = Some(callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user