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§
Required Methods§
Sourcefn build(&self, ctx: &mut BuildCtx<'_>) -> Self::Element
fn build(&self, ctx: &mut BuildCtx<'_>) -> Self::Element
Materialise a fresh widget for this view.
Sourcefn rebuild(
&self,
prev: &Self,
element: &mut Self::Element,
ctx: &mut BuildCtx<'_>,
) -> ChangeFlags
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§
Sourcefn teardown(&self, _element: &mut Self::Element, _ctx: &mut BuildCtx<'_>)
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.
Sourcefn message(&self, _element: &mut Self::Element, _state: &mut State)
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".