iced::advanced

Trait Widget

Source
pub trait Widget<Message, Theme, Renderer>
where Renderer: Renderer,
{ // Required methods fn size(&self) -> Size<Length>; fn layout( &self, tree: &mut Tree, renderer: &Renderer, limits: &Limits, ) -> Node; fn draw( &self, tree: &Tree, renderer: &mut Renderer, theme: &Theme, style: &Style, layout: Layout<'_>, cursor: Cursor, viewport: &Rectangle, ); // Provided methods fn size_hint(&self) -> Size<Length> { ... } 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, ) { ... } fn update( &mut self, _state: &mut Tree, _event: Event, _layout: Layout<'_>, _cursor: Cursor, _renderer: &Renderer, _clipboard: &mut dyn Clipboard, _shell: &mut Shell<'_, Message>, _viewport: &Rectangle, ) { ... } fn mouse_interaction( &self, _state: &Tree, _layout: Layout<'_>, _cursor: Cursor, _viewport: &Rectangle, _renderer: &Renderer, ) -> Interaction { ... } fn overlay<'a>( &'a mut self, _state: &'a mut Tree, _layout: Layout<'_>, _renderer: &Renderer, _translation: Vector, ) -> Option<Element<'a, Message, Theme, Renderer>> { ... } }
Available on crate feature advanced only.
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 size(&self) -> Size<Length>

Returns the Size of the Widget in lengths.

Source

fn layout(&self, tree: &mut Tree, 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, tree: &Tree, renderer: &mut Renderer, theme: &Theme, style: &Style, layout: Layout<'_>, cursor: Cursor, viewport: &Rectangle, )

Draws the Widget using the associated Renderer.

Provided Methods§

Source

fn size_hint(&self) -> Size<Length>

Returns a Size hint for laying out the Widget.

This hint may be used by some widget containers to adjust their sizing strategy during construction.

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)

Reconciles the Widget with the provided Tree.

Source

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

Applies an Operation to the Widget.

Source

fn update( &mut self, _state: &mut Tree, _event: Event, _layout: Layout<'_>, _cursor: Cursor, _renderer: &Renderer, _clipboard: &mut dyn Clipboard, _shell: &mut Shell<'_, Message>, _viewport: &Rectangle, )

Processes a runtime Event.

By default, it does nothing.

Source

fn mouse_interaction( &self, _state: &Tree, _layout: Layout<'_>, _cursor: Cursor, _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, _translation: Vector, ) -> Option<Element<'a, Message, Theme, Renderer>>

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

Trait Implementations§

Source§

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

Source§

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

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Immutably borrows from an owned value. Read more

Implementors§

§

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

§

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

§

impl<'a, Message, Theme, Renderer, Dependency, View> Widget<Message, Theme, Renderer> for Lazy<'a, Message, Theme, Renderer, Dependency, View>
where View: Into<Element<'static, Message, Theme, Renderer>> + 'static, Dependency: Hash + 'a, Message: 'static, Theme: 'static, Renderer: Renderer + 'static,

§

impl<'a, T, L, V, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for PickList<'a, T, L, V, Message, Theme, Renderer>
where T: Clone + ToString + PartialEq + 'a, L: Borrow<[T]>, V: Borrow<T>, Message: Clone + 'a, Theme: Catalog + 'a, Renderer: Renderer + 'a,

§

impl<Highlighter, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for TextEditor<'_, Highlighter, Message, Theme, Renderer>
where Highlighter: Highlighter, Theme: Catalog, Renderer: Renderer,

§

impl<Key, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for iced::widget::keyed::Column<'_, Key, Message, Theme, Renderer>
where Renderer: Renderer, Key: Copy + PartialEq + 'static,

§

impl<Link, Theme, Renderer> Widget<Link, Theme, Renderer> for Rich<'_, Link, Theme, Renderer>
where Link: Clone + 'static, Theme: Catalog, Renderer: Renderer,

§

impl<Message, Theme> Widget<Message, Theme, Renderer<Renderer, Renderer>> for QRCode<'_, Theme>
where Theme: Catalog,

§

impl<Message, Theme, NewTheme, F, Renderer> Widget<Message, Theme, Renderer> for Themer<'_, Message, Theme, NewTheme, F, Renderer>
where F: Fn(&Theme) -> NewTheme, Renderer: Renderer,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Checkbox<'_, Message, Theme, Renderer>
where Renderer: Renderer, Theme: Catalog,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for iced::widget::Column<'_, Message, Theme, Renderer>
where Renderer: Renderer,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Container<'_, Message, Theme, Renderer>
where Theme: Catalog, Renderer: Renderer,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for MouseArea<'_, Message, Theme, Renderer>
where Renderer: Renderer, Message: Clone,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for PaneGrid<'_, Message, Theme, Renderer>
where Theme: Catalog, Renderer: Renderer,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Pin<'_, Message, Theme, Renderer>
where Renderer: Renderer,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for ProgressBar<'_, Theme>
where Theme: Catalog, Renderer: Renderer,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Radio<'_, Message, Theme, Renderer>
where Message: Clone, Theme: Catalog, Renderer: Renderer,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Responsive<'_, Message, Theme, Renderer>
where Renderer: Renderer,

§

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

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Rule<'_, Theme>
where Renderer: Renderer, Theme: Catalog,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Scrollable<'_, Message, Theme, Renderer>
where Theme: Catalog, Renderer: Renderer,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Space
where Renderer: Renderer,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Svg<'_, Theme>
where Renderer: Renderer, Theme: Catalog,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for TextInput<'_, Message, Theme, Renderer>
where Message: Clone, Theme: Catalog, Renderer: Renderer,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Toggler<'_, Message, Theme, Renderer>
where Theme: Catalog, Renderer: Renderer,

§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Tooltip<'_, Message, Theme, Renderer>
where Theme: Catalog, Renderer: Renderer,

Source§

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Text<'_, Theme, Renderer>
where Theme: Catalog, Renderer: Renderer,

§

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

§

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

§

impl<P, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Canvas<P, Message, Theme, Renderer>
where Renderer: Renderer, P: Program<Message, Theme, Renderer>,

§

impl<P, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Shader<Message, P>
where P: Program<Message>, Renderer: Renderer,

§

impl<T, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for ComboBox<'_, T, Message, Theme, Renderer>
where T: Display + Clone + 'static, Message: Clone, Theme: Catalog, Renderer: Renderer,

§

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

§

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