[−][src]Trait iced_native::widget::Widget
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
fn width(&self) -> Length
Returns the width of the Widget
.
fn height(&self) -> Length
Returns the height of the Widget
.
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
Returns the Node
of the Widget
.
This Node
is used by the runtime to compute the Layout
of the
user interface.
fn draw(
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
Draws the Widget
using the associated Renderer
.
fn hash_layout(&self, state: &mut Hasher)
Computes the layout hash of the Widget
.
The produced hash is used by the runtime to decide if the Layout
needs to be recomputed between frames. Therefore, to ensure maximum
efficiency, the hash should only be affected by the properties of the
Widget
that can affect layouting.
For example, the Text
widget does not hash its color property, as
its value cannot affect the overall Layout
of the user interface.
Provided methods
fn on_event(
&mut self,
_event: Event,
_layout: Layout<'_>,
_cursor_position: Point,
_messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
&mut self,
_event: Event,
_layout: Layout<'_>,
_cursor_position: Point,
_messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
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 overlay(
&mut self,
_layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
&mut self,
_layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
Returns the overlay of the Element
, if there is any.
Implementors
impl<'a, Message, Renderer> Widget<Message, Renderer> for Button<'a, Message, Renderer> where
Renderer: Renderer,
Message: Clone,
[src]
Renderer: Renderer,
Message: Clone,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
impl<'a, Message, Renderer> Widget<Message, Renderer> for Column<'a, Message, Renderer> where
Renderer: Renderer,
[src]
Renderer: Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
fn overlay(
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
[src]
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
impl<'a, Message, Renderer> Widget<Message, Renderer> for Container<'a, Message, Renderer> where
Renderer: Renderer,
[src]
Renderer: Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
fn overlay(
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
[src]
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
impl<'a, Message, Renderer> Widget<Message, Renderer> for PaneGrid<'a, Message, Renderer> where
Renderer: Renderer + Renderer,
[src]
Renderer: Renderer + Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
fn overlay(
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
[src]
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
impl<'a, Message, Renderer> Widget<Message, Renderer> for Row<'a, Message, Renderer> where
Renderer: Renderer,
[src]
Renderer: Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
fn overlay(
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
[src]
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
impl<'a, Message, Renderer> Widget<Message, Renderer> for Scrollable<'a, Message, Renderer> where
Renderer: Renderer,
[src]
Renderer: Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
fn overlay(
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
[src]
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
impl<'a, Message, Renderer> Widget<Message, Renderer> for TextInput<'a, Message, Renderer> where
Renderer: Renderer,
Message: Clone,
[src]
Renderer: Renderer,
Message: Clone,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
renderer: &Renderer,
clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
impl<'a, T, Message, Renderer> Widget<Message, Renderer> for Slider<'a, T, Message, Renderer> where
T: Copy + Into<f64> + FromPrimitive,
Renderer: Renderer,
Message: Clone,
[src]
T: Copy + Into<f64> + FromPrimitive,
Renderer: Renderer,
Message: Clone,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, _renderer: &Renderer, limits: &Limits) -> Node
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
impl<'a, T: 'a, Message, Renderer> Widget<Message, Renderer> for PickList<'a, T, Message, Renderer> where
T: Clone + ToString + Eq,
[T]: ToOwned<Owned = Vec<T>>,
Message: 'static,
Renderer: Renderer + Renderer + 'a,
[src]
T: Clone + ToString + Eq,
[T]: ToOwned<Owned = Vec<T>>,
Message: 'static,
Renderer: Renderer + Renderer + 'a,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn hash_layout(&self, state: &mut Hasher)
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
fn overlay(
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
[src]
&mut self,
layout: Layout<'_>
) -> Option<Element<'_, Message, Renderer>>
impl<Message, Renderer> Widget<Message, Renderer> for Checkbox<Message, Renderer> where
Renderer: Renderer + Renderer + Renderer,
[src]
Renderer: Renderer + Renderer + Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
impl<Message, Renderer> Widget<Message, Renderer> for Image where
Renderer: Renderer,
[src]
Renderer: Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn draw(
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
impl<Message, Renderer> Widget<Message, Renderer> for ProgressBar<Renderer> where
Renderer: Renderer,
[src]
Renderer: Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, _renderer: &Renderer, limits: &Limits) -> Node
[src]
fn draw(
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
impl<Message, Renderer> Widget<Message, Renderer> for Radio<Message, Renderer> where
Renderer: Renderer + Renderer + Renderer,
Message: Clone,
[src]
Renderer: Renderer + Renderer + Renderer,
Message: Clone,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn on_event(
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
[src]
&mut self,
event: Event,
layout: Layout<'_>,
cursor_position: Point,
messages: &mut Vec<Message>,
_renderer: &Renderer,
_clipboard: Option<&dyn Clipboard>
)
fn draw(
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
impl<Message, Renderer> Widget<Message, Renderer> for Rule<Renderer> where
Renderer: Renderer,
[src]
Renderer: Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, _renderer: &Renderer, limits: &Limits) -> Node
[src]
fn draw(
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
impl<Message, Renderer> Widget<Message, Renderer> for Space where
Renderer: Renderer,
[src]
Renderer: Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, _renderer: &Renderer, limits: &Limits) -> Node
[src]
fn draw(
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
impl<Message, Renderer> Widget<Message, Renderer> for Svg where
Renderer: Renderer,
[src]
Renderer: Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn draw(
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
_defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output
fn hash_layout(&self, state: &mut Hasher)
[src]
impl<Message, Renderer> Widget<Message, Renderer> for Text<Renderer> where
Renderer: Renderer,
[src]
Renderer: Renderer,
fn width(&self) -> Length
[src]
fn height(&self) -> Length
[src]
fn layout(&self, renderer: &Renderer, limits: &Limits) -> Node
[src]
fn draw(
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output
[src]
&self,
renderer: &mut Renderer,
defaults: &Renderer::Defaults,
layout: Layout<'_>,
_cursor_position: Point
) -> Renderer::Output