Skip to main content

Component

Derive Macro Component 

#[derive(Component)]
{
    // Attributes available to this derive:
    #[component]
}
Expand description

Derive tilo_ui::component::Component for a widget’s props: the struct an instance of the widget is made from. The widget’s component description is generated from it, so the description cannot drift from the widget.

Struct attribute: #[component(name = "ListRow", role = "ListItem")], with optional label = "prop" (the prop that names it to assistive technology) and presents = "prop" (the prop holding the resource it shows). The struct’s doc text is the component’s.

Each field is one part of the description, with its doc text:

  • no attribute, or #[component(required)], #[component(positional)]: a prop, whose type implements PropType; #[component(data)] says its text is data the component reads (a key, an address), not words it shows, so a view’s literal there is no message; #[component(identity)] says it names the value among its siblings (a list’s chosen item), which takes a typed filter in its place, the query it asks;
  • #[component(slot)], #[component(slot(default))]: a slot, whose type implements SlotType (Option<Element>, Vec<Element>, or Option<P> of another component’s props: the slot accepts only that component);
  • #[component(event)], #[component(event(value = T))]: an event, of type Event; event(value = T, at = i64) also says where the value lands (a drop’s place);
  • #[component(bind)], #[component(bind(merge = "splice"))]: a binding, of type Bound<T>; bind(ty = Type) describes it as another type the field holds differently (a moment a widget edits as its ISO text);
  • #[component(state)]: the widget’s own state (lens state) to restore, a PropType;
  • #[component(key)]: the instance’s stable key, a String, not described;
  • #[component(skip)]: Rust only, not described.

A field of any other type does not compile: an event is data (Event), never a closure.