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
verify: Check Brick assertions (mandatory)measure: Compute intrinsic size given constraintslayout: Position self and children within allocated boundspaint: Generate draw commands (only ifcan_render()returns true)
Required Methods§
Sourcefn measure(&self, constraints: Constraints) -> Size
fn measure(&self, constraints: Constraints) -> Size
Compute intrinsic size constraints.
Sourcefn layout(&mut self, bounds: Rect) -> LayoutResult
fn layout(&mut self, bounds: Rect) -> LayoutResult
Position children within allocated bounds.
Sourcefn paint(&self, canvas: &mut dyn Canvas)
fn paint(&self, canvas: &mut dyn Canvas)
Generate draw commands for rendering.
§Panics
Panics if called when can_render() returns false (Brick verification failed).
Sourcefn children_mut(&mut self) -> &mut [Box<dyn Widget>]
fn children_mut(&mut self) -> &mut [Box<dyn Widget>]
Get mutable child widgets.
Provided Methods§
Sourcefn is_interactive(&self) -> bool
fn is_interactive(&self) -> bool
Check if this widget is interactive (can receive focus/events).
Sourcefn is_focusable(&self) -> bool
fn is_focusable(&self) -> bool
Check if this widget can receive keyboard focus.
Sourcefn accessible_name(&self) -> Option<&str>
fn accessible_name(&self) -> Option<&str>
Get the accessible name for screen readers.
Sourcefn accessible_role(&self) -> AccessibleRole
fn accessible_role(&self) -> AccessibleRole
Get the accessible role.