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§
Required Methods§
Provided Methods§
Sourcefn flex(&self) -> (u32, FlexFit)
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.
Sourcefn flow(&self) -> Flow
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.
Sourcefn layout(&self, ctx: LayoutContext<'_>, constraints: Constraints) -> Vec2
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.
Sourcefn default_layout(
&self,
ctx: LayoutContext<'_>,
constraints: Constraints,
) -> Vec2
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.
Sourcefn paint(&self, ctx: PaintContext<'_>)
fn paint(&self, ctx: PaintContext<'_>)
Paint the widget based on its current state.
The default implementation will paint all of the widget’s children.
Sourcefn default_paint(&self, ctx: PaintContext<'_>)
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.
Sourcefn event_interest(&self) -> EventInterest
fn event_interest(&self) -> EventInterest
Tells which events the widget is interested in receiving.
The default implementation will register interest in no events.
Sourcefn event(&mut self, ctx: EventContext<'_>, event: &WidgetEvent) -> EventResponse
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.
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.