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.

A View builds itself into a retained Widget (View::build) and reconciles a previous version against the live widget (View::rebuild). State is 'static, so views 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, in place.

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 leaf views.

Source

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

Deliver an event message to this view, mutating application state (stubbed: no event routing goes through it yet).

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>