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