Trait iced::widget::canvas::Program

source ·
pub trait Program<Message, Theme = Theme> {
    type State: Default + 'static;

    // Required method
    fn draw(
        &self,
        state: &Self::State,
        theme: &Theme,
        bounds: Rectangle<f32>,
        cursor: Cursor
    ) -> Vec<Geometry, Global> ;

    // Provided methods
    fn update(
        &self,
        _state: &mut Self::State,
        _event: Event,
        _bounds: Rectangle<f32>,
        _cursor: Cursor
    ) -> (Status, Option<Message>) { ... }
    fn mouse_interaction(
        &self,
        _state: &Self::State,
        _bounds: Rectangle<f32>,
        _cursor: Cursor
    ) -> Interaction { ... }
}
Available on crate feature canvas only.
Expand description

The state and logic of a Canvas.

A Program can mutate internal state and produce messages for an application.

Required Associated Types§

source

type State: Default + 'static

The internal state mutated by the Program.

Required Methods§

source

fn draw( &self, state: &Self::State, theme: &Theme, bounds: Rectangle<f32>, cursor: Cursor ) -> Vec<Geometry, Global>

Draws the state of the Program, producing a bunch of Geometry.

Geometry can be easily generated with a Frame or stored in a Cache.

Provided Methods§

source

fn update( &self, _state: &mut Self::State, _event: Event, _bounds: Rectangle<f32>, _cursor: Cursor ) -> (Status, Option<Message>)

Updates the State of the Program.

When a Program is used in a Canvas, the runtime will call this method for each Event.

This method can optionally return a Message to notify an application of any meaningful interactions.

By default, this method does and returns nothing.

source

fn mouse_interaction( &self, _state: &Self::State, _bounds: Rectangle<f32>, _cursor: Cursor ) -> Interaction

Returns the current mouse interaction of the Program.

The interaction returned will be in effect even if the cursor position is out of bounds of the program’s Canvas.

Implementations on Foreign Types§

source§

impl<Message, Theme, T> Program<Message, Theme> for &Twhere T: Program<Message, Theme>,

§

type State = <T as Program<Message, Theme>>::State

source§

fn update( &self, state: &mut <&T as Program<Message, Theme>>::State, event: Event, bounds: Rectangle<f32>, cursor: Cursor ) -> (Status, Option<Message>)

source§

fn draw( &self, state: &<&T as Program<Message, Theme>>::State, theme: &Theme, bounds: Rectangle<f32>, cursor: Cursor ) -> Vec<Geometry, Global>

source§

fn mouse_interaction( &self, state: &<&T as Program<Message, Theme>>::State, bounds: Rectangle<f32>, cursor: Cursor ) -> Interaction

Implementors§