pub trait Widget<Message, Theme, Renderer>where
Renderer: Renderer,{
Show 15 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 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 usinglyon
.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 theMesh2D
primitive iniced_wgpu
.
Required Methods§
sourcefn layout(&self, tree: &mut Tree, renderer: &Renderer, limits: &Limits) -> Node
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.
Provided Methods§
sourcefn operate(
&self,
_state: &mut Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
_operation: &mut dyn Operation,
)
fn operate( &self, _state: &mut Tree, _layout: Layout<'_>, _renderer: &Renderer, _operation: &mut dyn Operation, )
sourcefn 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 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.
sourcefn mouse_interaction(
&self,
_state: &Tree,
_layout: Layout<'_>,
_cursor: Cursor,
_viewport: &Rectangle,
_renderer: &Renderer,
) -> Interaction
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
.
sourcefn overlay<'a>(
&'a mut self,
_state: &'a mut Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
_translation: Vector,
) -> Option<Element<'a, Message, Theme, Renderer>>
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.
sourcefn set_id(&mut self, _id: Id)
fn set_id(&mut self, _id: Id)
Sets the id of the widget This may be called while diffing the widget tree
sourcefn drag_destinations(
&self,
_state: &Tree,
_layout: Layout<'_>,
_renderer: &Renderer,
_dnd_rectangles: &mut DndDestinationRectangles,
)
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.