macro_rules! event_property {
($(
$(#[$meta:meta])+
$vis:vis fn $on_ident:ident $(< $on_pre_ident:ident $(,)?>)? (
$child:ident: impl $IntoUiNode:path,
$handler:ident: $Handler:ty $(,)?
) -> $UiNode:path {
$($body:tt)+
}
)+) => { ... };
}Expand description
Declare event properties.
Each declaration can expand to an on_event and optionally an on_pre_event. The body can be declared using EventNodeBuilder or
VarEventNodeBuilder.
§Examples
event_property! {
/// Docs copied for `on_key_input` and `on_pre_key_input`.
///
/// The macro also generates docs linking between the two properties.
#[property(EVENT)]
pub fn on_key_input<on_pre_key_input>(child: impl IntoUiNode, handler: Handler<KeyInputArgs>) -> UiNode {
// Preview flag, only if the signature contains the `<on_pre...>` part,
// the macro matches `const $IDENT: bool;` and expands to `const IDENT: bool = true/false;`.
const PRE: bool;
// rest of the body can be anything the builds a node.
EventNodeBuilder::new(KEY_INPUT_EVENT).build::<PRE>(child, handler)
}
/// Another property.
#[property(EVENT)]
pub fn on_key_down<on_pre_key_down>(child: impl IntoUiNode, handler: Handler<KeyInputArgs>) -> UiNode {
const PRE: bool;
EventNodeBuilder::new(KEY_INPUT_EVENT)
.filter(|| |a| a.state == KeyState::Pressed)
.build::<PRE>(child, handler)
}
/// Another, this time derived from a var source, and without the optional preview property.
#[property(EVENT)]
pub fn on_state(child: impl IntoUiNode, handler: Handler<bool>) -> UiNode {
VarEventNodeBuilder::new(|| CONTEXT.state())
.map_args(|b| !*b)
.build::<false>(child, handler)
}
}The example above generates five event properties.
§Route
Note that is an event property has an on_pre_* pair it is expected to be representing a fully routing event, with args that
implement EventArgs. If the property does not have a preview pair it is expected to be a direct event. This is the event
property pattern and is explained in the generated documentation, don’t declare a non-standard pair using this macro.
§Commands
You can use command_property to declare command event properties, it also generates enabled control properties.