Skip to main content

Widget

Trait Widget 

Source
pub trait Widget {
Show 13 methods // Provided methods fn style(&self) -> Style { ... } fn children(&self) -> &[Element] { ... } fn expand(&self, _cx: &mut BuildCx<'_>) { ... } fn layer(&self) -> Option<Layer> { ... } fn inert(&self) -> bool { ... } fn focus(&self) -> Option<Focus> { ... } fn provide(&self) -> Option<&dyn Any> { ... } fn measure( &self, _known: Size<Option<f32>>, _available: Size<AvailableSpace>, _text: &Text, ) -> Size<f32> { ... } fn measure_key(&self) -> u64 { ... } fn scroll( &self, _state: &mut State, _at: Placement, _now: Instant, ) -> Option<(f32, f32)> { ... } fn clips(&self) -> bool { ... } fn paint(&self, _cx: &mut PaintCx<'_>) { ... } fn event(&self, _ev: &Event, _cx: &mut EventCx<'_>) { ... }
}
Expand description

Primitive building block. Composite widgets are plain functions returning Element; implement this only for new layout/paint/input behavior.

Provided Methods§

Source

fn style(&self) -> Style

Source

fn children(&self) -> &[Element]

Source

fn expand(&self, _cx: &mut BuildCx<'_>)

Runs before children with this node’s id, state slot and providers; lets a widget build its subtree from framework-owned state.

Source

fn layer(&self) -> Option<Layer>

Takes this subtree out of the layout flow: it covers Layer’s box, isn’t clipped by ancestors, paints above and gets input before the rest of the tree.

Source

fn inert(&self) -> bool

Whether this subtree is drawn but ignores the pointer.

Source

fn focus(&self) -> Option<Focus>

Lets Tab move keyboard focus here. The focused widget gets keys first and handles Enter, Space or arrows when EventCx::focused.

Source

fn provide(&self) -> Option<&dyn Any>

Value made available to descendants through Scope::get.

Source

fn measure( &self, _known: Size<Option<f32>>, _available: Size<AvailableSpace>, _text: &Text, ) -> Size<f32>

Intrinsic size of a leaf (children-less) widget.

Source

fn measure_key(&self) -> u64

Hash of everything measure reads besides its arguments. Layout is kept across rebuilds and a leaf is only re-measured when this changes, so widgets whose size depends on their data must override it.

Source

fn scroll( &self, _state: &mut State, _at: Placement, _now: Instant, ) -> Option<(f32, f32)>

Children are clipped to at.clip and shifted by the returned offset, as of frame time now.

Source

fn clips(&self) -> bool

Whether children moved by scroll are clipped to this widget’s box.

Source

fn paint(&self, _cx: &mut PaintCx<'_>)

Source

fn event(&self, _ev: &Event, _cx: &mut EventCx<'_>)

Pointer events reach a widget while the pointer is over it, once more when it leaves, and throughout a press that began on it; layers get them all.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§