Skip to main content

Drawable

Trait Drawable 

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

    // Provided method
    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, ResourceStore, 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) -> Result<Rect, ValidationError>

Local layout/ink bounds before node placement; invalid content is an error.

Source

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

Emits local commands; validation errors propagate without partial output.

Provided Methods§

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>