[][src]Trait iced_native::widget::Widget

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,
        defaults: &Renderer::Defaults,
        layout: Layout<'_>,
        cursor_position: Point
    ) -> Renderer::Output;
fn hash_layout(&self, state: &mut Hasher); fn on_event(
        &mut self,
        _event: Event,
        _layout: Layout<'_>,
        _cursor_position: Point,
        _messages: &mut Vec<Message>,
        _renderer: &Renderer,
        _clipboard: Option<&dyn Clipboard>
    ) { ... }
fn overlay(
        &mut self,
        _layout: Layout<'_>
    ) -> Option<Element<'_, Message, Renderer>> { ... } }

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:

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

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.

Loading content...

Provided methods

fn on_event(
    &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 the Widget
  • the current cursor position
  • a mutable Message list, allowing the Widget 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>>

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

Loading content...

Implementors

impl<'a, Message, Renderer> Widget<Message, Renderer> for Button<'a, Message, Renderer> where
    Renderer: Renderer,
    Message: Clone
[src]

impl<'a, Message, Renderer> Widget<Message, Renderer> for Column<'a, Message, Renderer> where
    Renderer: Renderer
[src]

impl<'a, Message, Renderer> Widget<Message, Renderer> for Container<'a, Message, Renderer> where
    Renderer: Renderer
[src]

impl<'a, Message, Renderer> Widget<Message, Renderer> for PaneGrid<'a, Message, Renderer> where
    Renderer: Renderer + Renderer
[src]

impl<'a, Message, Renderer> Widget<Message, Renderer> for Row<'a, Message, Renderer> where
    Renderer: Renderer
[src]

impl<'a, Message, Renderer> Widget<Message, Renderer> for Scrollable<'a, Message, Renderer> where
    Renderer: Renderer
[src]

impl<'a, Message, Renderer> Widget<Message, Renderer> for TextInput<'a, Message, Renderer> where
    Renderer: Renderer,
    Message: Clone
[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]

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]

impl<Message, Renderer> Widget<Message, Renderer> for Checkbox<Message, Renderer> where
    Renderer: Renderer + Renderer + Renderer
[src]

impl<Message, Renderer> Widget<Message, Renderer> for Image where
    Renderer: Renderer
[src]

impl<Message, Renderer> Widget<Message, Renderer> for ProgressBar<Renderer> where
    Renderer: Renderer
[src]

impl<Message, Renderer> Widget<Message, Renderer> for Radio<Message, Renderer> where
    Renderer: Renderer + Renderer + Renderer,
    Message: Clone
[src]

impl<Message, Renderer> Widget<Message, Renderer> for Rule<Renderer> where
    Renderer: Renderer
[src]

impl<Message, Renderer> Widget<Message, Renderer> for Space where
    Renderer: Renderer
[src]

impl<Message, Renderer> Widget<Message, Renderer> for Svg where
    Renderer: Renderer
[src]

impl<Message, Renderer> Widget<Message, Renderer> for Text<Renderer> where
    Renderer: Renderer
[src]

Loading content...