Skip to main content

Shape

Trait Shape 

Source
pub trait Shape: Send + Sync {
    // Required method
    fn path(&self) -> Path2D;

    // Provided methods
    fn validate(&self) -> Result<(), ValidationError> { ... }
    fn bounding_box(&self) -> Rect { ... }
    fn as_rect(&self) -> Option<Rect> { ... }
    fn fill(self, paint: impl Into<Paint>) -> Styled<Self>
       where Self: Sized { ... }
    fn stroke(self, width: f64, paint: impl Into<Paint>) -> Styled<Self>
       where Self: Sized { ... }
}
Expand description

Logical geometry independent of paint and node placement.

Custom geometry must keep path and bounds consistent and deterministic. Direct path conversion requires valid geometry; invalid raw rectangles panic there, while recording their filled nodes reports validation errors instead.

Required Methods§

Source

fn path(&self) -> Path2D

Returns a checked path snapshot without f32 narrowing.

Provided Methods§

Source

fn validate(&self) -> Result<(), ValidationError>

Reports retained authoring errors before measuring or drawing.

Source

fn bounding_box(&self) -> Rect

Geometric bounds; defaults to the path’s cached curve bounds.

Source

fn as_rect(&self) -> Option<Rect>

Exact rectangle equivalent, when available, for a rule-independent fast path.

Source

fn fill(self, paint: impl Into<Paint>) -> Styled<Self>
where Self: Sized,

Adds floating fill paint, using the nonzero rule by default.

Source

fn stroke(self, width: f64, paint: impl Into<Paint>) -> Styled<Self>
where Self: Sized,

Adds a bounded curve/path stroke without an implicit fill.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§