Skip to main content

Drawable

Trait Drawable 

Source
pub trait Drawable: Send + Sync {
    // Required methods
    fn bounds(&self, context: &DrawContext) -> Rect;
    fn draw(
        &self,
        context: &DrawContext,
        canvas: &mut Canvas<'_>,
    ) -> Result<(), ValidationError>;

    // Provided methods
    fn resolve_node(
        &self,
        _context: &DrawContext,
    ) -> Result<Option<Node>, ValidationError> { ... }
    fn try_bounds(&self, context: &DrawContext) -> Result<Rect, ValidationError> { ... }
    fn baseline(&self, _context: &DrawContext) -> Option<f64> { ... }
}
Expand description

Content whose bounds and drawing share the same logical coordinates.

Implementations must be deterministic and time independent for fixed inputs. Bounds are supplied by content. Custom content must enclose its own drawing; the frontend validates bounds and commands but cannot prove arbitrary callbacks return conservative bounds.

use motion_core::prelude::*;
use motion_core::{
    DisplayList, RasterLimits, ResourcePool, ValidatedDisplayList, MAX_PATH_VERBS,
    MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
let row = Row::new()
    .gap(4.0)
    .children([
        Rect::new(0.0, 0.0, 10.0, 20.0).fill(Color::from_hex(0x24a49b)),
        Rect::new(0.0, 0.0, 5.0, 10.0).fill(Color::WHITE),
    ])
    .at(Point::new(100.0, 80.0));
assert_eq!(
    row.measure(ValidationLimits::default())?,
    Rect::new(90.5, 70.0, 109.5, 90.0)
);
let list = row.compile(
    Size::new(200.0, 160.0),
    PixelSize::new(200, 160),
    ValidationLimits::default(),
)?;
assert_eq!(list.commands.len(), 2);

Required Methods§

Source

fn bounds(&self, context: &DrawContext) -> Rect

Local layout/ink bounds before node placement.

Source

fn draw( &self, context: &DrawContext, canvas: &mut Canvas<'_>, ) -> Result<(), ValidationError>

Emits local commands; validation errors propagate without partial output.

Provided Methods§

Source

fn resolve_node( &self, _context: &DrawContext, ) -> Result<Option<Node>, ValidationError>

Resolves deferred content to ordinary nodes at the current drawing time.

Source

fn try_bounds(&self, context: &DrawContext) -> Result<Rect, ValidationError>

Checked bounds for fallible content such as explicit-font paragraphs. Existing geometry implementations may keep the infallible bounds method.

Source

fn baseline(&self, _context: &DrawContext) -> Option<f64>

Real horizontal text baseline in local coordinates; geometry has none.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<Geometry: Shape> Drawable for Styled<Geometry>