iced::widget::shader

Trait Program

pub trait Program<Message> {
    type State: Default + 'static;
    type Primitive: Primitive + 'static;

    // Required method
    fn draw(
        &self,
        state: &Self::State,
        cursor: Cursor,
        bounds: Rectangle,
    ) -> Self::Primitive;

    // 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 wgpu only.
Expand description

The state and logic of a Shader widget.

A Program can mutate the internal state of a Shader widget and produce messages for an application.

Required Associated Types§

type State: Default + 'static

The internal state of the Program.

type Primitive: Primitive + 'static

The type of primitive this Program can draw.

Required Methods§

fn draw( &self, state: &Self::State, cursor: Cursor, bounds: Rectangle, ) -> Self::Primitive

Draws the Primitive.

Provided Methods§

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

Update the internal State of the Program. This can be used to reflect state changes based on mouse & other events. You can return an Action to publish a message, request a redraw, or capture the event.

By default, this method returns None.

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 Shader’s program.

Implementations on Foreign Types§

§

impl<Message, T> Program<Message> for &T
where T: Program<Message>,

§

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

§

type Primitive = <T as Program<Message>>::Primitive

§

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

§

fn draw( &self, state: &<&T as Program<Message>>::State, cursor: Cursor, bounds: Rectangle, ) -> <&T as Program<Message>>::Primitive

§

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

Implementors§