Skip to main content

Widget

Trait Widget 

Source
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§

Source

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

Step 1: Compute intrinsic size given constraints

Source

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

Step 2: Position self and children within bounds

Source

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

Step 3: Generate draw commands (only called if verified!)

Source

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

Handle interaction events

Provided Methods§

Source

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

Get children widgets (for tree traversal)

Source

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".

Implementors§