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()
}
}