logo
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(
        &self,
        renderer: &mut Renderer,
        style: &Style,
        layout: Layout<'_>,
        cursor_position: Point,
        viewport: &Rectangle
    ); fn on_event(
        &mut self,
        _event: Event,
        _layout: Layout<'_>,
        _cursor_position: Point,
        _renderer: &Renderer,
        _clipboard: &mut dyn Clipboard,
        _shell: &mut Shell<'_, Message>
    ) -> Status { ... } fn mouse_interaction(
        &self,
        _layout: Layout<'_>,
        _cursor_position: Point,
        _viewport: &Rectangle,
        _renderer: &Renderer
    ) -> Interaction { ... } fn overlay(
        &mut self,
        _layout: Layout<'_>,
        _renderer: &Renderer
    ) -> Option<Element<'_, 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.

Examples

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 Node of the Widget.

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

Draws the Widget using the associated Renderer.

Provided Methods

Processes a runtime Event.

It receives:

  • an Event describing user interaction
  • the computed Layout of the Widget
  • the current cursor position
  • a mutable Message list, allowing the Widget to produce new messages based on user interaction.
  • the Renderer
  • a Clipboard, if available

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.

Implementors