pub trait Widget<Msg>: 'static {
// Required methods
fn measure(&self, cx: &mut MeasureCx<'_>, available: Size) -> Size;
fn paint(&self, cx: &mut PaintCx<'_>, area: Rect);
// Provided methods
fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect) { ... }
fn event(&self, _cx: &mut EventCx<'_, Msg>, _event: &Event) -> bool { ... }
fn focusable(&self) -> bool { ... }
fn children(&self) -> &[Node<Msg>] { ... }
fn children_mut(&mut self) -> &mut [Node<Msg>] { ... }
}Expand description
Something that can be laid out, painted and interacted with.
Widgets are plain values created in view every frame. Anything that must survive between
frames and is not application data (a cursor position, a scroll offset) is kept in runtime
memory through PaintCx::memory and EventCx::memory.
Required Methods§
Provided Methods§
Sourcefn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)
fn paint_overlay(&self, _cx: &mut PaintCx<'_>, _anchor: Rect)
Draws the widget’s overlay after the whole view was painted, when it asked for one with
PaintCx::request_overlay. anchor is the area the widget was painted in.
Sourcefn event(&self, _cx: &mut EventCx<'_, Msg>, _event: &Event) -> bool
fn event(&self, _cx: &mut EventCx<'_, Msg>, _event: &Event) -> bool
Handles input. Returns true when the event was used; unused key and scroll events
bubble to the parent widget.
Sourcefn children_mut(&mut self) -> &mut [Node<Msg>]
fn children_mut(&mut self) -> &mut [Node<Msg>]
Mutable child nodes, used to assign ids.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".