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,
        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(
        &self,
        _state: &mut Tree,
        _layout: Layout<'_>,
        _renderer: &Renderer,
        _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(
        &self,
        _state: &Tree,
        _layout: Layout<'_>,
        _cursor_position: Point,
        _viewport: &Rectangle,
        _renderer: &Renderer
    ) -> Interaction { ... } fn overlay<'a>(
        &'a mut 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.

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§

source

fn width(&self) -> Length

Returns the width of the Widget.

source

fn height(&self) -> Length

Returns the height of the Widget.

source

fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node

Returns the layout::Node of the Widget.

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

source

fn draw(
    &self,
    state: &Tree,
    renderer: &mut Renderer,
    theme: &Renderer::Theme,
    style: &Style,
    layout: Layout<'_>,
    cursor_position: Point,
    viewport: &Rectangle
)

Draws the Widget using the associated Renderer.

Provided Methods§

source

fn tag(&self) -> Tag

Returns the Tag of the Widget.

source

fn state(&self) -> State

Returns the State of the Widget.

source

fn children(&self) -> Vec<Tree>

Returns the state Tree of the children of the Widget.

source

fn diff(&self, _tree: &mut Tree)

Reconciliates the Widget with the provided Tree.

source

fn operate(
    &self,
    _state: &mut Tree,
    _layout: Layout<'_>,
    _renderer: &Renderer,
    _operation: &mut dyn Operation<Message>
)

Applies an Operation to the Widget.

source

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

Processes a runtime Event.

By default, it does nothing.

source

fn mouse_interaction(
    &self,
    _state: &Tree,
    _layout: Layout<'_>,
    _cursor_position: Point,
    _viewport: &Rectangle,
    _renderer: &Renderer
) -> Interaction

Returns the current mouse::Interaction of the Widget.

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

source

fn overlay<'a>(
    &'a mut self,
    _state: &'a mut Tree,
    _layout: Layout<'_>,
    _renderer: &Renderer
) -> Option<Element<'a, Message, Renderer>>

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

Trait Implementations§

source§

impl<'a, Message, Renderer> Borrow<dyn Widget<Message, Renderer> + 'a> for &Element<'a, Message, Renderer>

source§

fn borrow(&self) -> &(dyn Widget<Message, Renderer> + 'a)

Immutably borrows from an owned value. Read more
source§

impl<'a, Message, Renderer> Borrow<dyn Widget<Message, Renderer> + 'a> for Element<'a, Message, Renderer>

source§

fn borrow(&self) -> &(dyn Widget<Message, Renderer> + 'a)

Immutably borrows from an owned value. Read more

Implementors§

source§

impl<'a, Message, Renderer> Widget<Message, Renderer> for Button<'a, Message, Renderer>where
    Message: 'a + Clone,
    Renderer: 'a + Renderer,
    Renderer::Theme: StyleSheet,

source§

impl<'a, Message, Renderer> Widget<Message, Renderer> for Checkbox<'a, Message, Renderer>where
    Renderer: Renderer,
    Renderer::Theme: StyleSheet + StyleSheet,

source§

impl<'a, Message, Renderer> Widget<Message, Renderer> for Column<'a, Message, Renderer>where
    Renderer: Renderer,

source§

impl<'a, Message, Renderer> Widget<Message, Renderer> for Container<'a, Message, Renderer>where
    Renderer: Renderer,
    Renderer::Theme: StyleSheet,

source§

impl<'a, Message, Renderer> Widget<Message, Renderer> for PaneGrid<'a, Message, Renderer>where
    Renderer: Renderer,
    Renderer::Theme: StyleSheet + StyleSheet,

source§

impl<'a, Message, Renderer> Widget<Message, Renderer> for Row<'a, Message, Renderer>where
    Renderer: Renderer,

source§

impl<'a, Message, Renderer> Widget<Message, Renderer> for Scrollable<'a, Message, Renderer>where
    Renderer: Renderer,
    Renderer::Theme: StyleSheet,

source§

impl<'a, Message, Renderer> Widget<Message, Renderer> for Text<'a, Renderer>where
    Renderer: Renderer,
    Renderer::Theme: StyleSheet,

source§

impl<'a, Message, Renderer> Widget<Message, Renderer> for TextInput<'a, Message, Renderer>where
    Message: Clone,
    Renderer: Renderer,
    Renderer::Theme: StyleSheet,

source§

impl<'a, Message, Renderer> Widget<Message, Renderer> for Toggler<'a, Message, Renderer>where
    Renderer: Renderer,
    Renderer::Theme: StyleSheet + StyleSheet,

source§

impl<'a, Message, Renderer> Widget<Message, Renderer> for Tooltip<'a, Message, Renderer>where
    Renderer: Renderer,
    Renderer::Theme: StyleSheet + StyleSheet,

source§

impl<'a, T, Message, Renderer> Widget<Message, Renderer> for PickList<'a, T, Message, Renderer>where
    T: Clone + ToString + Eq + 'static + 'a,
    [T]: ToOwned<Owned = Vec<T>>,
    Message: 'a,
    Renderer: Renderer + 'a,
    Renderer::Theme: StyleSheet + StyleSheet + StyleSheet + StyleSheet,
    <Renderer::Theme as StyleSheet>::Style: From<<Renderer::Theme as StyleSheet>::Style>,

source§

impl<'a, T, Message, Renderer> Widget<Message, Renderer> for Slider<'a, T, Message, Renderer>where
    T: Copy + Into<f64> + FromPrimitive,
    Message: Clone,
    Renderer: Renderer,
    Renderer::Theme: StyleSheet,

source§

impl<'a, T, Message, Renderer> Widget<Message, Renderer> for VerticalSlider<'a, T, Message, Renderer>where
    T: Copy + Into<f64> + FromPrimitive,
    Message: Clone,
    Renderer: Renderer,
    Renderer::Theme: StyleSheet,

source§

impl<Message, Renderer> Widget<Message, Renderer> for ProgressBar<Renderer>where
    Renderer: Renderer,
    Renderer::Theme: StyleSheet,

source§

impl<Message, Renderer> Widget<Message, Renderer> for Radio<Message, Renderer>where
    Message: Clone,
    Renderer: Renderer,
    Renderer::Theme: StyleSheet + StyleSheet,

source§

impl<Message, Renderer> Widget<Message, Renderer> for Rule<Renderer>where
    Renderer: Renderer,
    Renderer::Theme: StyleSheet,

source§

impl<Message, Renderer> Widget<Message, Renderer> for Spacewhere
    Renderer: Renderer,

source§

impl<Message, Renderer> Widget<Message, Renderer> for Svg<Renderer>where
    Renderer: Renderer,
    Renderer::Theme: StyleSheet,

source§

impl<Message, Renderer, Handle> Widget<Message, Renderer> for Image<Handle>where
    Renderer: Renderer<Handle = Handle>,
    Handle: Clone + Hash,

source§

impl<Message, Renderer, Handle> Widget<Message, Renderer> for Viewer<Handle>where
    Renderer: Renderer<Handle = Handle>,
    Handle: Clone + Hash,