[][src]Trait pixel_widgets::widget::Widget

pub trait Widget<'a, Message>: Send {
    fn widget(&self) -> &'static str;
fn len(&self) -> usize;
fn visit_children(
        &mut self,
        visitor: &mut dyn FnMut(&mut Node<'a, Message>)
    );
fn size(&self, style: &Stylesheet) -> (Size, Size);
fn draw(
        &mut self,
        layout: Rectangle,
        clip: Rectangle,
        style: &Stylesheet
    ) -> Vec<Primitive<'a>>; fn state(&self) -> StateVec { ... }
fn hit(
        &self,
        layout: Rectangle,
        clip: Rectangle,
        _style: &Stylesheet,
        x: f32,
        y: f32
    ) -> bool { ... }
fn focused(&self) -> bool { ... }
fn event(
        &mut self,
        _layout: Rectangle,
        _clip: Rectangle,
        _style: &Stylesheet,
        _event: Event,
        _context: &mut Context<Message>
    ) { ... }
fn node_event(
        &mut self,
        _layout: Rectangle,
        _style: &Stylesheet,
        _event: NodeEvent,
        _context: &mut Context<Message>
    ) { ... } }

A user interface widget.

Required methods

fn widget(&self) -> &'static str

The name of this widget, used to identify widgets of this type in stylesheets.

fn len(&self) -> usize

Should return the amount of children this widget has. Must be consistent with visit_children().

fn visit_children(&mut self, visitor: &mut dyn FnMut(&mut Node<'a, Message>))

Applies a visitor to all childs of the widget. If an widget fails to visit it's children, the children won't be able to resolve their stylesheet, resulting in a panic when calling size, hit, event or draw.

fn size(&self, 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.

fn draw(
    &mut self,
    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.
Loading content...

Provided methods

fn state(&self) -> 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".

fn hit(
    &self,
    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

fn focused(&self) -> 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.

fn event(
    &mut self,
    _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.

fn node_event(
    &mut self,
    _layout: Rectangle,
    _style: &Stylesheet,
    _event: NodeEvent,
    _context: &mut Context<Message>
)

Handle a node 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:

  • event: the event that needs to be handled
  • context: context for submitting messages and requesting redraws of the ui.
Loading content...

Implementors

impl<'a, T> Widget<'a, T> for Space[src]

impl<'a, T> Widget<'a, T> for Text[src]

impl<'a, T, F: Send + Fn(bool) -> T> Widget<'a, T> for Toggle<'a, T, F>[src]

impl<'a, T: 'a + Send> Widget<'a, T> for Button<'a, T>[src]

impl<'a, T: 'a + Send> Widget<'a, T> for Column<'a, T>[src]

impl<'a, T: 'a + Send, F: 'a + Send + Fn(String) -> T> Widget<'a, T> for Input<'a, T, F>[src]

impl<'a, T: 'a + Send, Id: 'a + Send> Widget<'a, T> for Layers<'a, T, Id>[src]

impl<'a, T: 'a + Send, S: Send + AsRef<[MenuItem<'a, T>]> + AsMut<[MenuItem<'a, T>]>> Widget<'a, T> for Menu<'a, T, S>[src]

impl<'a, T: 'a> Widget<'a, T> for &'a Image[src]

impl<'a, T: 'a> Widget<'a, T> for Dummy[src]

impl<'a, T: 'a> Widget<'a, T> for Frame<'a, T>[src]

impl<'a, T: 'a> Widget<'a, T> for Panel<'a, T>[src]

impl<'a, T: 'a> Widget<'a, T> for Progress<'a, T>[src]

impl<'a, T: 'a> Widget<'a, T> for Row<'a, T>[src]

impl<'a, T: 'a> Widget<'a, T> for Scroll<'a, T>[src]

impl<'a, T: 'a> Widget<'a, T> for Window<'a, T>[src]

impl<'a, T: DragDropId + Send, Message: 'a> Widget<'a, Message> for Drag<'a, T, Message>[src]

impl<'a, T: DragDropId, Message: 'a, OnAccept, OnDrop> Widget<'a, Message> for Drop<'a, T, Message, OnAccept, OnDrop> where
    OnAccept: Send + Fn(T) -> bool,
    OnDrop: Send + Fn(T, (f32, f32)) -> Message, 
[src]

impl<'a, T: Send + 'a> Widget<'a, T> for Dropdown<'a, T>[src]

Loading content...