pub trait Widget: Any {
// Provided methods
fn measure(
&mut self,
cx: &mut LayoutCx<'_>,
constraints: Constraints,
) -> Size { ... }
fn layout(&mut self, cx: &mut LayoutCx<'_>, size: Size) { ... }
fn paint(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>) { ... }
fn paint_over(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>) { ... }
fn event(&mut self, cx: &mut EventCx<'_>, event: &Event<'_>) -> Handled { ... }
fn accepts_focus(&self) -> bool { ... }
fn focus_on_press(&self) -> bool { ... }
fn accessibility(&self, cx: &PaintCx<'_>, node: &mut AccessNode) { ... }
fn access_action(
&mut self,
cx: &mut EventCx<'_>,
request: &AccessRequest<'_>,
) -> Handled { ... }
}Expand description
A part of the interface: it can measure itself, paint, and handle events.
A Ui owns its widgets in a tree; their places come from each widget’s
Style and, for widgets without children, from
measure. Painting and event handling run every frame, so they must
not allocate once a widget’s content is set up; measuring and
layout run only when sizes change and may.
Every method has a default: a plain container needs to implement nothing.
Provided Methods§
Sourcefn measure(&mut self, cx: &mut LayoutCx<'_>, constraints: Constraints) -> Size
fn measure(&mut self, cx: &mut LayoutCx<'_>, constraints: Constraints) -> Size
The size the widget wants within constraints, for a widget without children (one
with children is sized by its style and its children). Physical pixels.
Sourcefn layout(&mut self, cx: &mut LayoutCx<'_>, size: Size)
fn layout(&mut self, cx: &mut LayoutCx<'_>, size: Size)
Layout decided the widget’s size: re-wrap text or recompute anything that depends on it. Called after every layout pass that changed the size.
Sourcefn paint(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>)
fn paint(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>)
Paints the widget below its children.
Sourcefn paint_over(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>)
fn paint_over(&mut self, cx: &PaintCx<'_>, canvas: &mut Canvas<'_>)
Paints the widget over its children: scroll bars, focus rings, overlays.
Sourcefn event(&mut self, cx: &mut EventCx<'_>, event: &Event<'_>) -> Handled
fn event(&mut self, cx: &mut EventCx<'_>, event: &Event<'_>) -> Handled
Handles event. An event the widget does not handle goes on to its parent.
Sourcefn accepts_focus(&self) -> bool
fn accepts_focus(&self) -> bool
Whether the widget takes keyboard focus, by click or by Tab.
Sourcefn focus_on_press(&self) -> bool
fn focus_on_press(&self) -> bool
Whether a press on the widget, or on a widget inside it that takes no focus, focuses it (if it accepts focus). A container reachable by Tab, such as a dock’s tab list, says no, so clicks on its contents do not focus it; it can still ask for focus itself.
Sourcefn accessibility(&self, cx: &PaintCx<'_>, node: &mut AccessNode)
fn accessibility(&self, cx: &PaintCx<'_>, node: &mut AccessNode)
Describes the widget to assistive technology: fills node, which starts as a
Role::Group with the widget’s rectangle. Called only while
assistive technology is listening; it may allocate.
Sourcefn access_action(
&mut self,
cx: &mut EventCx<'_>,
request: &AccessRequest<'_>,
) -> Handled
fn access_action( &mut self, cx: &mut EventCx<'_>, request: &AccessRequest<'_>, ) -> Handled
Does what assistive technology asks (only actions the widget’s node lists are asked of it). Focus and scrolling into view are done for every widget; a request the widget does not handle goes on to its parent if it is a scroll.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".