iced::widget::canvas

Trait Program

Source
pub trait Program<Message, Theme = Theme, Renderer = Renderer<Renderer, Renderer>>
where Renderer: Renderer,
{ type State: Default + 'static; // Required method fn draw( &self, state: &Self::State, renderer: &Renderer, theme: &Theme, bounds: Rectangle, cursor: Cursor, ) -> Vec<<Renderer as Renderer>::Geometry>; // Provided methods fn update( &self, _state: &mut Self::State, _event: Event, _bounds: Rectangle, _cursor: Cursor, ) -> Option<Action<Message>> { ... } fn mouse_interaction( &self, _state: &Self::State, _bounds: Rectangle, _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, renderer: &Renderer, theme: &Theme, bounds: Rectangle, cursor: Cursor, ) -> Vec<<Renderer as Renderer>::Geometry>

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, _cursor: Cursor, ) -> Option<Action<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 an Action to either notify an application of any meaningful interactions, capture the event, or request a redraw.

By default, this method does and returns nothing.

Source

fn mouse_interaction( &self, _state: &Self::State, _bounds: Rectangle, _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, Renderer, T> Program<Message, Theme, Renderer> for &T
where Renderer: Renderer, T: Program<Message, Theme, Renderer>,

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§