Trait iced_native::widget::Widget
source · [−]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 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
Provided Methods
Processes a runtime Event
.
It receives:
- an
Event
describing user interaction - the computed
Layout
of theWidget
- the current cursor position
- a mutable
Message
list, allowing theWidget
to produce new messages based on user interaction. - the
Renderer
- a
Clipboard
, if available
By default, it does nothing.
fn mouse_interaction(
&self,
_layout: Layout<'_>,
_cursor_position: Point,
_viewport: &Rectangle,
_renderer: &Renderer
) -> Interaction
fn mouse_interaction(
&self,
_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
.