Trait cosmic::iced_winit::graphics::core::widget::Widget

source ·
pub trait Widget<Message, Theme, Renderer>
where Renderer: Renderer,
{
Show 16 methods // 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(&mut self, _tree: &mut Tree) { ... } fn operate( &self, _state: &mut Tree, _layout: Layout<'_>, _renderer: &Renderer, _operation: &mut dyn Operation, ) { ... } fn on_event( &mut self, _state: &mut Tree, _event: Event, _layout: Layout<'_>, _cursor: Cursor, _renderer: &Renderer, _clipboard: &mut dyn Clipboard, _shell: &mut Shell<'_, Message>, _viewport: &Rectangle, ) -> Status { ... } 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>> { ... } fn a11y_nodes( &self, _layout: Layout<'_>, _state: &Tree, _cursor: Cursor, ) -> A11yTree { ... } fn id(&self) -> Option<Id> { ... } fn set_id(&mut self, _id: Id) { ... } fn drag_destinations( &self, _state: &Tree, _layout: Layout<'_>, _renderer: &Renderer, _dnd_rectangles: &mut DndDestinationRectangles, ) { ... }
}
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(&mut 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, )

Applies an Operation to the Widget.

source

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

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.

source

fn a11y_nodes( &self, _layout: Layout<'_>, _state: &Tree, _cursor: Cursor, ) -> A11yTree

get the a11y nodes for the widget and its children

source

fn id(&self) -> Option<Id>

Returns the id of the widget

source

fn set_id(&mut self, _id: Id)

Sets the id of the widget This may be called while diffing the widget tree

source

fn drag_destinations( &self, _state: &Tree, _layout: Layout<'_>, _renderer: &Renderer, _dnd_rectangles: &mut DndDestinationRectangles, )

Adds the drag destination rectangles of the widget. Runs after the layout phase for each widget in the tree.

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 &mut 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
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more

Implementors§

source§

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

source§

impl<'a, Key, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for cosmic::iced_widget::keyed::Column<'a, Key, Message, Theme, Renderer>
where Renderer: Renderer, Key: Copy + PartialEq + 'static,

source§

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

source§

impl<'a, Message> Widget<Message, Theme, Renderer> for ColorPicker<'a, Message>
where Message: Clone + 'static,

source§

impl<'a, Message> Widget<Message, Theme, Renderer> for cosmic::widget::text_input::TextInput<'a, Message>
where Message: Clone + 'static,

source§

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

source§

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

source§

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

source§

impl<'a, Message, Renderer> Widget<Message, Theme, Renderer> for cosmic::widget::Radio<'a, Message, Renderer>
where Message: Clone, Renderer: Renderer,

source§

impl<'a, Message, Renderer, I> Widget<Message, Theme, Renderer> for RectangleTrackingContainer<'a, Message, Renderer, I>
where Renderer: Renderer, I: 'a + Hash + Copy + Send + Sync + Debug,

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl<'a, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for cosmic::iced_widget::Radio<'a, Message, Theme, Renderer>
where Message: Clone, Theme: Catalog, Renderer: Renderer,

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl<'a, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for cosmic::iced_widget::TextInput<'a, Message, Theme, Renderer>
where Message: Clone, Theme: Catalog, Renderer: Renderer,

source§

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

source§

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

source§

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

source§

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

source§

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,

source§

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

source§

impl<'a, Message: 'a + Clone> Widget<Message, Theme, Renderer> for cosmic::widget::button::Button<'a, Message>

source§

impl<'a, Message: 'static + Clone> Widget<Message, Theme, Renderer> for FlexRow<'a, Message>

source§

impl<'a, Message: 'static + Clone> Widget<Message, Theme, Renderer> for Grid<'a, Message>

source§

impl<'a, Message: 'static> Widget<Message, Theme, Renderer> for DndDestination<'a, Message>

source§

impl<'a, Message: Clone + 'static, D: AsMimeTypes + Send + 'static> Widget<Message, Theme, Renderer> for DndSource<'a, Message, D>

source§

impl<'a, Message: Clone> Widget<Message, Theme, Renderer> for ContextDrawer<'a, Message>

source§

impl<'a, Message: Clone> Widget<Message, Theme, Renderer> for ContextMenu<'a, Message>

source§

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

source§

impl<'a, S: AsRef<str>, Message: 'a> Widget<Message, Theme, Renderer> for cosmic::widget::dropdown::Dropdown<'a, S, Message>

source§

impl<'a, S: AsRef<str>, Message: 'a, Item: Clone + PartialEq + 'static> Widget<Message, Theme, Renderer> for cosmic::widget::dropdown::multi::Dropdown<'a, S, Message, Item>

source§

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,

source§

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

source§

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

source§

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

source§

impl<'a, Variant, SelectionMode, Message> Widget<Message, Theme, Renderer> for SegmentedButton<'a, Variant, SelectionMode, Message>
where Self: SegmentedVariant, Model<SelectionMode>: Selectable, SelectionMode: Default, Message: 'static + Clone,

source§

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

source§

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

source§

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