Function zng_wgt::node::on_command
source · pub fn on_command<U, CB, E, EB, H>(
child: U,
command_builder: CB,
enabled_builder: EB,
handler: H,
) -> impl UiNodewhere
U: UiNode,
CB: FnMut() -> Command + Send + 'static,
E: Var<bool>,
EB: FnMut() -> E + Send + 'static,
H: WidgetHandler<CommandArgs>,
Expand description
Helper for declaring command event properties.
This function is used by the command_property!
macro.
§Command
The command_builder
closure is called on init to generate the command, it is a closure to allow
creation of widget scoped commands. The event handler
will receive events for the command
and scope that target the widget where it is set.
If the command is scoped on the root widget and on_command
is set on the same root widget a second handle
is taken for the window scope too, so callers can target the window using the window ID or the root widget ID.
§Enabled
The enabled_builder
closure is called on init to generate a boolean variable that defines
if the command handle is enabled. Command event handlers track both their existence and
the enabled flag, see Command::subscribe
for details.
Note that the command handler can be enabled even when the widget is disabled, the widget will receive the event while disabled in this case, you can use this to show feedback explaining why the command cannot run.
§Route
The event handler
is called after the on_pre_command
equivalent at the same context level. If the command
event targets more then one widget and one widget contains the other, the handler
is called on the inner widget first.
§Async
Async event handlers are called like normal, but code after the first .await
only runs in subsequent updates. This means
that propagation
must be stopped before the first .await
, otherwise you are only signaling
other async tasks handling the same event, if they are monitoring the propagation handle.