Skip to main content

DeriveEvent

Derive Macro DeriveEvent 

Source
#[derive(DeriveEvent)]
{
    // Attributes available to this derive:
    #[event]
}
Expand description

Generate getters and setters on an element type from its data struct.

Fields marked with #[prop] get a getter (fn field(&self) -> T) and a setter (fn set_field(&self, value: impl Into<T>)).

§Attributes

  • element = TypeName(required) the element handle type

§Example

#[derive(Default, Props)]
#[props(element = Button)]
pub struct ButtonData {
    #[prop]
    pub label: String,
    #[prop]
    pub disabled: bool,
}

Derive the Event trait for an event struct.

§Attributes

  • bubbles — the event bubbles up through the tree
  • cancelable — the event can be cancelled via prevent_default()

§Example

#[derive(Event)]
#[event(bubbles, cancelable)]
pub struct ClickEvent {
    pub x: f32,
    pub y: f32,
}