handsfree mode

This commit is contained in:
galister
2026-01-13 19:15:16 +09:00
parent 1318f23947
commit fd24060d7b
23 changed files with 434 additions and 105 deletions

View File

@@ -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()
}

View File

@@ -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);
}