Trait View

Source
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§

Source

type State: SendSync + 'static

The state of the view.

Required Methods§

Source

fn build(&self) -> Self::State

Builds the state of the view.

Provided Methods§

Source

fn style(&self) -> Style

Returns the style of the view.

Source

fn event( &self, state: &mut Self::State, cx: &mut EventContext<'_>, event: &Event, )

Handles an event.

Source

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.

Source

fn draw(&self, state: &mut Self::State, cx: &mut DrawContext<'_>)

Draws the view.

Implementations on Foreign Types§

Source§

impl View for ()

Source§

type State = ()

Source§

fn build(&self) -> Self::State

Source§

fn event( &self, _state: &mut Self::State, _cx: &mut EventContext<'_>, _event: &Event, )

Source§

fn layout( &self, _state: &mut Self::State, _cx: &mut LayoutContext<'_>, bc: BoxConstraints, ) -> Vec2

Source§

fn draw(&self, _state: &mut Self::State, _cx: &mut DrawContext<'_>)

Implementors§

Source§

impl View for Button

Source§

impl View for Checkbox

Source§

impl View for Comment

Source§

impl View for Div

Source§

impl View for Image

Source§

impl View for Knob

Source§

impl View for Scroll

Source§

impl View for Text

Source§

impl View for TextInput

Source§

impl<T: View> View for Styled<T>

Source§

type State = <T as View>::State

Source§

impl<V: View + SendSync> View for SharedSignal<V>

When a view is wrapped in a signal, the view will be redrawn when the signal changes.

Source§

type State = (Callback<'static>, <V as View>::State)