Skip to main content

Widget

Trait Widget 

Source
pub trait Widget<S: AppState> {
    // Required method
    fn build(&self, ctx: &mut BuildCtx<S>, view: &View<'_, S>) -> Node;
}
Expand description

The core trait for composable UI components.

A Widget produces a Node tree given read-only access to state (View) and a mutable build context (BuildCtx) for binding actions, registering portals, and requesting animations.

§Example

struct Greeting;

impl Widget<AppState> for Greeting {
    fn build(&self, ctx: &mut BuildCtx<AppState>, view: &View<AppState>) -> Node {
        let on_press = ctx.bind(SayHello, handle_hello as fn(&mut AppState, SayHello));
        Button {
            child: Some(Box::new(Text::new("Hello!").into_node())),
            on_press: Some(on_press),
            ..Default::default()
        }.into_node()
    }
}

Required Methods§

Source

fn build(&self, ctx: &mut BuildCtx<S>, view: &View<'_, S>) -> Node

Build the widget’s node tree.

Called once per frame. Implementations must be pure – all side-effects go through ctx (action binding, portals, animations).

Implementors§