Widget

Trait Widget 

Source
pub trait Widget: Send + Sync {
Show 13 methods // Required methods fn type_id(&self) -> TypeId; fn measure(&self, constraints: Constraints) -> Size; fn layout(&mut self, bounds: Rect) -> LayoutResult; fn paint(&self, canvas: &mut dyn Canvas); fn event(&mut self, event: &Event) -> Option<Box<dyn Any + Send>>; fn children(&self) -> &[Box<dyn Widget>]; fn children_mut(&mut self) -> &mut [Box<dyn Widget>]; // Provided methods fn is_interactive(&self) -> bool { ... } fn is_focusable(&self) -> bool { ... } fn accessible_name(&self) -> Option<&str> { ... } fn accessible_role(&self) -> AccessibleRole { ... } fn test_id(&self) -> Option<&str> { ... } fn bounds(&self) -> Rect { ... }
}
Expand description

Core widget trait that all UI elements implement.

Widgets follow a measure-layout-paint cycle:

  1. measure: Compute intrinsic size given constraints
  2. layout: Position self and children within allocated bounds
  3. paint: Generate draw commands

Required Methods§

Source

fn type_id(&self) -> TypeId

Get the type identifier for this widget type.

Source

fn measure(&self, constraints: Constraints) -> Size

Compute intrinsic size constraints.

Called during the measure phase to determine the widget’s preferred size.

Source

fn layout(&mut self, bounds: Rect) -> LayoutResult

Position children within allocated bounds.

Called during the layout phase after sizes are known.

Source

fn paint(&self, canvas: &mut dyn Canvas)

Generate draw commands for rendering.

Called during the paint phase to produce GPU draw commands.

Source

fn event(&mut self, event: &Event) -> Option<Box<dyn Any + Send>>

Handle input events.

Returns a message if the event triggered a state change.

Source

fn children(&self) -> &[Box<dyn Widget>]

Get child widgets for tree traversal.

Source

fn children_mut(&mut self) -> &mut [Box<dyn Widget>]

Get mutable child widgets.

Provided Methods§

Source

fn is_interactive(&self) -> bool

Check if this widget is interactive (can receive focus/events).

Source

fn is_focusable(&self) -> bool

Check if this widget can receive keyboard focus.

Source

fn accessible_name(&self) -> Option<&str>

Get the accessible name for screen readers.

Source

fn accessible_role(&self) -> AccessibleRole

Get the accessible role.

Source

fn test_id(&self) -> Option<&str>

Get the test ID for this widget (if any).

Source

fn bounds(&self) -> Rect

Get the current bounds of this widget.

Returns the rectangle set during the last layout phase. Default returns zero-sized bounds at origin.

Implementors§