Skip to main content

View

Trait View 

Source
pub trait View<State: 'static>: 'static {
    type Element: Widget;

    // Required methods
    fn build(&self, ctx: &mut BuildCtx<'_>) -> Self::Element;
    fn rebuild(
        &self,
        prev: &Self,
        element: &mut Self::Element,
        ctx: &mut BuildCtx<'_>,
    ) -> ChangeFlags;

    // Provided methods
    fn teardown(&self, _element: &mut Self::Element, _ctx: &mut BuildCtx<'_>) { ... }
    fn message(&self, _element: &mut Self::Element, _state: &mut State) { ... }
}
Expand description

A declarative description of a piece of UI.

Each View knows how to materialise itself into a retained Widget (View::build) and how to reconcile a previous version of itself against the live widget (View::rebuild). State is 'static so views never capture borrowed data — they are values, re-created every frame.

Required Associated Types§

Source

type Element: Widget

The retained widget this view produces.

Required Methods§

Source

fn build(&self, ctx: &mut BuildCtx<'_>) -> Self::Element

Materialise a fresh widget for this view.

Source

fn rebuild( &self, prev: &Self, element: &mut Self::Element, ctx: &mut BuildCtx<'_>, ) -> ChangeFlags

Reconcile prev (the previous view of the same type) against the live element, mutating it in place and reporting what changed.

Provided Methods§

Source

fn teardown(&self, _element: &mut Self::Element, _ctx: &mut BuildCtx<'_>)

Tear down element when this view is being removed.

A no-op for v0 leaf views; kept in the trait so the lifecycle is complete and container/removal logic (later phases) has a hook.

Source

fn message(&self, _element: &mut Self::Element, _state: &mut State)

Deliver an event message to this view, mutating application state.

Stubbed for v0 (no event routing yet); present so the trait shape is stable as event routing is added later.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<Outer: 'static, C: Component> View<Outer> for ComponentView<C>

Source§

impl<State: 'static> View<State> for AnyView<State>