pub trait View: SendSync + 'static {
type State: SendSync + 'static;
// Required method
fn build(&self) -> Self::State;
// Provided methods
fn style(&self) -> Style { ... }
fn event(
&self,
state: &mut Self::State,
cx: &mut EventContext<'_>,
event: &Event
) { ... }
fn layout(
&self,
state: &mut Self::State,
cx: &mut LayoutContext<'_>,
bc: BoxConstraints
) -> Vec2 { ... }
fn draw(&self, state: &mut Self::State, cx: &mut DrawContext<'_>) { ... }
}
Expand description
A View
is a component that can be rendered to the screen.
Required Associated Types§
Required Methods§
Provided Methods§
sourcefn event(
&self,
state: &mut Self::State,
cx: &mut EventContext<'_>,
event: &Event
)
fn event( &self, state: &mut Self::State, cx: &mut EventContext<'_>, event: &Event )
Handles an event.
sourcefn layout(
&self,
state: &mut Self::State,
cx: &mut LayoutContext<'_>,
bc: BoxConstraints
) -> Vec2
fn layout( &self, state: &mut Self::State, cx: &mut LayoutContext<'_>, bc: BoxConstraints ) -> Vec2
Handle layout and returns the size of the view.
This method should return a size that fits the BoxConstraints
.
The default implementation returns the minimum size.
sourcefn draw(&self, state: &mut Self::State, cx: &mut DrawContext<'_>)
fn draw(&self, state: &mut Self::State, cx: &mut DrawContext<'_>)
Draws the view.