gooey/widget/
form.rs

1//! Generic widget for submitting callbacks with current model state
2
3use crate::{Tree, TreeHelper};
4use crate::tree::NodeId;
5use crate::interface::{model, view, Action, Element};
6use crate::interface::controller::{self, controls};
7use super::Widget;
8
9/// Form is a generic widget (components can be of any type) that allows generating a
10/// `SubmitCallback` action with the model component's current callback ID
11// TODO: currently the submit_callback control doesn't need to construct an instance of
12// a form widget, since the model callback is not stored in the variant data; eventually
13// there may be controls for operating on generic model data, although reflecting
14// changes in controller or view state could be a challenge without specializing
15pub type Form <'element> =
16  Widget <'element, controller::Component, model::Component, view::Component>;
17
18/// Builtin button control ID `FormSubmitCallback`: get the application callback ID
19/// stored in the model component of the target node, and produce a submit action.
20///
21/// /!\ Model must have a callback ID set.
22pub fn submit_callback (
23  _ : &controls::button::Release, elements : &Tree <Element>, node_id : &NodeId,
24  action_buffer : &mut Vec <(NodeId, Action)>
25) {
26  log::trace!("submit_callback...");
27  // no need to get create form widget
28  let element     = elements.get_element (node_id);
29  let callback_id = element.model.callback_id.as_ref().unwrap_or_else (||{
30    log::error!("submit callback: no callback id in model");
31    panic!("submit callback: no callback id in model")
32  }).clone();
33  action_buffer.push ((node_id.clone(), Action::SubmitCallback (callback_id)));
34  log::trace!("...submit_callback");
35}