pub trait Widget<Message, Renderer>where
    Renderer: Renderer,
{ fn width(&self) -> Length; fn height(&self) -> Length; fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node; fn draw(
        state: &Tree,
        renderer: &mut Renderer,
        theme: &Renderer::Theme,
        style: &Style,
        layout: Layout<'_>,
        cursor_position: Point,
        viewport: &Rectangle
    ); fn tag(&self) -> Tag { ... } fn state(&self) -> State { ... } fn children(&self) -> Vec<Tree> { ... } fn diff(&self, _tree: &mut Tree) { ... } fn operate(
        _state: &mut Tree,
        _layout: Layout<'_>,
        _operation: &mut dyn Operation<Message>
    ) { ... } fn on_event(
        &mut self,
        _state: &mut Tree,
        _event: Event,
        _layout: Layout<'_>,
        _cursor_position: Point,
        _renderer: &Renderer,
        _clipboard: &mut dyn Clipboard,
        _shell: &mut Shell<'_, Message>
    ) -> Status { ... } fn mouse_interaction(
        _state: &Tree,
        _layout: Layout<'_>,
        _cursor_position: Point,
        _viewport: &Rectangle,
        _renderer: &Renderer
    ) -> Interaction { ... } fn overlay<'a>(
        &'a self,
        _state: &'a mut Tree,
        _layout: Layout<'_>,
        _renderer: &Renderer
    ) -> Option<Element<'a, Message, Renderer>> { ... } }
Expand description

A component that displays information and allows interaction.

If you want to build your own widgets, you will need to implement this trait.


The repository has some examples showcasing how to implement a custom widget:

  • bezier_tool, a Paint-like tool for drawing Bézier curves using lyon.
  • custom_widget, a demonstration of how to build a custom widget that draws a circle.
  • geometry, a custom widget showcasing how to draw geometry with the Mesh2D primitive in iced_wgpu.

Required Methods

Returns the width of the Widget.

Returns the height of the Widget.

Returns the layout::Node of the Widget.

This layout::Node is used by the runtime to compute the Layout of the user interface.

Draws the Widget using the associated Renderer.

Provided Methods

Returns the Tag of the Widget.

Returns the State of the Widget.

Returns the state Tree of the children of the Widget.

Reconciliates the Widget with the provided Tree.

Applies an Operation to the Widget.

Processes a runtime Event.

By default, it does nothing.

Returns the current mouse::Interaction of the Widget.

By default, it returns mouse::Interaction::Idle.

Returns the overlay of the Widget, if there is any.

Trait Implementations

Immutably borrows from an owned value. Read more
Immutably borrows from an owned value. Read more