pub trait Widget: Brick {
// Required methods
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>>;
// Provided methods
fn children(&self) -> &[Box<dyn Widget>] { ... }
fn children_mut(&mut self) -> &mut [Box<dyn Widget>] { ... }
}Expand description
Widget trait: Every widget must also be a Brick (PROBAR-SPEC-009)
This unifies UI components with verifiable assertions, ensuring that no widget can render without passing its assertions.
Required Methods§
Sourcefn measure(&self, constraints: Constraints) -> Size
fn measure(&self, constraints: Constraints) -> Size
Step 1: Compute intrinsic size given constraints
Sourcefn layout(&mut self, bounds: Rect) -> LayoutResult
fn layout(&mut self, bounds: Rect) -> LayoutResult
Step 2: Position self and children within bounds
Provided Methods§
Sourcefn children_mut(&mut self) -> &mut [Box<dyn Widget>]
fn children_mut(&mut self) -> &mut [Box<dyn Widget>]
Get mutable children
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".