Skip to main content

RenderObject

Trait RenderObject 

Source
pub trait RenderObject: 'static {
    // Required methods
    fn layout(&mut self, constraints: Constraints) -> Size;
    fn paint(&self, canvas: &mut Canvas, size: Size);

    // Provided method
    fn hit_test(&self, point: Point, size: Size) -> bool { ... }
}
Expand description

The core trait implemented by every node in the render tree.

Each RenderObject is responsible for measuring itself given layout Constraints, painting into a Canvas, and reporting hit-test results.

Required Methods§

Source

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

Measures the object under the given constraints and returns its size.

Source

fn paint(&self, canvas: &mut Canvas, size: Size)

Paints the object into canvas at the origin, occupying size.

Provided Methods§

Source

fn hit_test(&self, point: Point, size: Size) -> bool

Returns true if point lies within the object’s bounding box.

The default implementation uses the full axis-aligned bounding box anchored at the origin.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§