pub trait Widget<'a, Message>: Send {
    type State: Any + Send + Sync;
    // Required methods
    fn mount(&self) -> Self::State;
    fn widget(&self) -> &'static str;
    fn len(&self) -> usize;
    fn visit_children(
        &mut self,
        visitor: &mut dyn FnMut(&mut dyn GenericNode<'a, Message>),
    );
    fn size(&self, state: &Self::State, style: &Stylesheet) -> (Size, Size);
    fn draw(
        &mut self,
        state: &mut Self::State,
        layout: Rectangle,
        clip: Rectangle,
        style: &Stylesheet,
    ) -> Vec<Primitive<'a>>;
    // Provided methods
    fn key(&self) -> u64 { ... }
    fn state(&self, _state: &Self::State) -> StateVec { ... }
    fn is_empty(&self) -> bool { ... }
    fn hit(
        &self,
        _state: &Self::State,
        layout: Rectangle,
        clip: Rectangle,
        _style: &Stylesheet,
        x: f32,
        y: f32,
    ) -> bool { ... }
    fn focused(&self, _state: &Self::State) -> bool { ... }
    fn event(
        &mut self,
        _state: &mut Self::State,
        _layout: Rectangle,
        _clip: Rectangle,
        _style: &Stylesheet,
        _event: Event,
        _context: &mut Context<Message>,
    ) { ... }
}Expand description
A user interface widget.
Required Associated Types§
Required Methods§
Sourcefn widget(&self) -> &'static str
 
fn widget(&self) -> &'static str
The name of this widget, used to identify widgets of this type in stylesheets.
Sourcefn len(&self) -> usize
 
fn len(&self) -> usize
Should return the amount of children this widget has. Must be consistent with
visit_children().
Sourcefn visit_children(
    &mut self,
    visitor: &mut dyn FnMut(&mut dyn GenericNode<'a, Message>),
)
 
fn visit_children( &mut self, visitor: &mut dyn FnMut(&mut dyn GenericNode<'a, Message>), )
Sourcefn size(&self, state: &Self::State, style: &Stylesheet) -> (Size, Size)
 
fn size(&self, state: &Self::State, style: &Stylesheet) -> (Size, Size)
Returns the (width, height) of this widget.
The extents are defined as a Size,
which will later be resolved to actual dimensions.
Sourcefn draw(
    &mut self,
    state: &mut Self::State,
    layout: Rectangle,
    clip: Rectangle,
    style: &Stylesheet,
) -> Vec<Primitive<'a>>
 
fn draw( &mut self, state: &mut Self::State, layout: Rectangle, clip: Rectangle, style: &Stylesheet, ) -> Vec<Primitive<'a>>
Draw the widget. Returns a list of Primitives that should be drawn.
Arguments:
- layout: the layout assigned to the widget
- clip: a clipping rect for use with- Primitive::PushClip.
Provided Methods§
Sourcefn state(&self, _state: &Self::State) -> StateVec
 
fn state(&self, _state: &Self::State) -> StateVec
The state of this widget, used for computing the style.
If None is returned, Node will automatically compute a state, such as “hover” and “pressed”.
Sourcefn is_empty(&self) -> bool
 
fn is_empty(&self) -> bool
Returns whether this children has no children. Must be consistent with
visit_children().
Sourcefn hit(
    &self,
    _state: &Self::State,
    layout: Rectangle,
    clip: Rectangle,
    _style: &Stylesheet,
    x: f32,
    y: f32,
) -> bool
 
fn hit( &self, _state: &Self::State, layout: Rectangle, clip: Rectangle, _style: &Stylesheet, x: f32, y: f32, ) -> bool
Perform a hit detect on the widget. Most widgets are fine with the default implementation, but some
widgets (like Window need to report a miss (false) even when the queried
position is within their layout.
Arguments:
- layout: the layout assigned to the widget
- clip: a clipping rect for mouse events. Mouse events outside of this rect should be considered invalid, such as with- Scroll, where the widget would not be visible outside of the currently visible rect.
- x: x mouse coordinate being queried
- y: y mouse coordinate being queried
Sourcefn focused(&self, _state: &Self::State) -> bool
 
fn focused(&self, _state: &Self::State) -> bool
Test the widget for focus exclusivity.
If the widget or one of it’s descendants is in an exclusive focus state, this function should return true.
In all other cases, it should return false. When a widget is in an exclusive focus state it is
the only widget that is allowed to receive events in event.
Widgets that intended to use this behaviour are modal dialogs, dropdown boxes, context menu’s, etc.
Sourcefn event(
    &mut self,
    _state: &mut Self::State,
    _layout: Rectangle,
    _clip: Rectangle,
    _style: &Stylesheet,
    _event: Event,
    _context: &mut Context<Message>,
)
 
fn event( &mut self, _state: &mut Self::State, _layout: Rectangle, _clip: Rectangle, _style: &Stylesheet, _event: Event, _context: &mut Context<Message>, )
Handle an event. If an event changes the graphical appearance of an Widget,
redraw should be called to let the Ui know that
the ui should be redrawn.
Arguments:
- layout: the layout assigned to the widget
- clip: a clipping rect for mouse events. Mouse events outside of this rect should be considered invalid, such as with- Scroll, where the widget would not be visible outside of the currently visible rect.
- event: the event that needs to be handled
- context: context for submitting messages and requesting redraws of the ui.