Trait Widget

Source
pub trait Widget: 'static + Debug {
    type Props<'a>: Props;
    type Response;

    // Required methods
    fn new() -> Self;
    fn update(&mut self, props: Self::Props<'_>) -> Self::Response;

    // Provided methods
    fn flex(&self) -> (u32, FlexFit) { ... }
    fn flow(&self) -> Flow { ... }
    fn layout(&self, ctx: LayoutContext<'_>, constraints: Constraints) -> Vec2 { ... }
    fn default_layout(
        &self,
        ctx: LayoutContext<'_>,
        constraints: Constraints,
    ) -> Vec2 { ... }
    fn paint(&self, ctx: PaintContext<'_>) { ... }
    fn default_paint(&self, ctx: PaintContext<'_>) { ... }
    fn event_interest(&self) -> EventInterest { ... }
    fn event(
        &mut self,
        ctx: EventContext<'_>,
        event: &WidgetEvent,
    ) -> EventResponse { ... }
    fn navigate(
        &self,
        ctx: NavigateContext<'_>,
        dir: NavDirection,
    ) -> Option<WidgetId> { ... }
}
Expand description

A yakui widget. Implement this trait to create a custom widget if composing existing widgets does not solve your use case.

Required Associated Types§

Source

type Props<'a>: Props

The props that this widget needs to be created or updated. Props define all of the values that a widget’s user can specify every render.

Source

type Response

The type that the widget will return to the user when it is created or updated. This type should contain information like whether the widget was clicked, had keyboard input, or other info that might be useful.

Required Methods§

Source

fn new() -> Self

Create the widget.

Source

fn update(&mut self, props: Self::Props<'_>) -> Self::Response

Update the widget with new props.

Provided Methods§

Source

fn flex(&self) -> (u32, FlexFit)

Returns whether this widget should grow to fill a flexible layout, and if so, what weight should be applied to it if other widgets also want to grow.

A value of 0 indicates that this widget should not grow, while 1 means that it should stretch to take the available space.

Source

fn flow(&self) -> Flow

Returns the behavior that this widget should have when part of a layout.

By default, widgets participate in layout using Flow::Inline.

Source

fn layout(&self, ctx: LayoutContext<'_>, constraints: Constraints) -> Vec2

Calculate this widget’s layout with the given constraints and return its size. The returned size must fit within the given constraints, which can be done using constraints.constrain(size).

The default implementation will lay out all of this widget’s children on top of each other, and fit the widget tightly around them.

Source

fn default_layout( &self, ctx: LayoutContext<'_>, constraints: Constraints, ) -> Vec2

A convenience method that always performs the default layout strategy for a widget. This method is intended to be called from custom widget’s layout methods.

Source

fn paint(&self, ctx: PaintContext<'_>)

Paint the widget based on its current state.

The default implementation will paint all of the widget’s children.

Source

fn default_paint(&self, ctx: PaintContext<'_>)

A convenience method that always performs the default painting operation for a widget. This method is intended to be called from custom widget’s paint methods.

Source

fn event_interest(&self) -> EventInterest

Tells which events the widget is interested in receiving.

The default implementation will register interest in no events.

Source

fn event(&mut self, ctx: EventContext<'_>, event: &WidgetEvent) -> EventResponse

Handle the given event and update the widget’s state.

The default implementation will bubble all events.

Source

fn navigate( &self, ctx: NavigateContext<'_>, dir: NavDirection, ) -> Option<WidgetId>

Tell which widget should be navigated to if the user navigates in a given direction.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§