Widget

Trait Widget 

Source
pub trait Widget:
    Brick
    + 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.

§Brick Architecture (PROBAR-SPEC-009)

Widget REQUIRES the Brick trait, enforcing the “tests define interface” philosophy:

  • Every Widget has assertions that define its contract
  • Every Widget has a performance budget
  • Rendering is blocked if assertions fail (Popperian falsification)

§Lifecycle

  1. verify: Check Brick assertions (mandatory)
  2. measure: Compute intrinsic size given constraints
  3. layout: Position self and children within allocated bounds
  4. paint: Generate draw commands (only if can_render() returns true)

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.

Source

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

Position children within allocated bounds.

Source

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

Generate draw commands for rendering.

§Panics

Panics if called when can_render() returns false (Brick verification failed).

Source

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

Handle input events.

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.

Implementors§