Widget

Derive Macro Widget 

Source
#[derive(Widget)]
{
    // Attributes available to this derive:
    #[widget]
    #[base]
}
Expand description

Derive macro for implementing the Widget trait.

This macro generates the boilerplate implementation of the Widget trait for a struct that contains a WidgetBase field.

§Requirements

  • The struct must have a field marked with #[base] of type WidgetBase
  • The struct must have a type_name attribute specifying the widget type

§Example

use openkit_macros::Widget;

#[derive(Widget)]
#[widget(type_name = "my-widget")]
struct MyWidget {
    #[base]
    base: WidgetBase,

    label: String,
    value: i32,
}

// The macro generates:
// - id() -> WidgetId
// - type_name() -> &'static str
// - element_id() -> Option<&str>
// - classes() -> &ClassList
// - state() -> WidgetState
// - bounds() -> Rect
// - set_bounds(&mut self, Rect)