Skip to main content

DrawContext

Struct DrawContext 

Source
pub struct DrawContext { /* private fields */ }
Expand description

Drawing inputs for the frontend.

Device scale and structural limits are drawing-specific; time, quality, assets, fonts, diagnostics and compute caches live in the shared Evaluation. Neither implicitly discovers resources.

Implementations§

Source§

impl DrawContext

Source

pub fn new(device_scale: f64) -> Result<Self, ValidationError>

Creates drawing inputs with a finite, strictly positive device scale.

Source

pub fn with_evaluation(self, evaluation: Arc<Evaluation>) -> Self

Replaces the shared evaluation environment.

Source

pub fn evaluation(&self) -> &Arc<Evaluation> ⓘ

Shared time, quality, resources, diagnostics and caches.

Source

pub fn with_quality(self, quality: RenderQuality) -> Self

Selects an explicit approximation policy for deferred content recording.

Source

pub fn render_quality(&self) -> RenderQuality

Production quality is the default for every standalone drawing context.

Source

pub fn with_time(self, time: Time) -> Self

Supplies scene-local signed time to deferred content effects.

Source

pub fn time(&self) -> Time

Scene-local time; direct static recording defaults to zero.

Source

pub fn device_scale(&self) -> f64

Device pixels per logical unit; does not implicitly modify local geometry.

Source

pub fn with_fonts(self, fonts: impl Into<FontEnvironment>) -> Self

Supplies a shared explicit font snapshot to paragraph bounds and drawing.

Source

pub fn fonts(&self) -> Option<&FontEnvironment>

Font environment for paragraph text, optional for geometry-only drawing.

Source

pub fn with_assets(self, assets: &Assets) -> Self

Captures the same lazy/preloaded owner used by the enclosing session.

Source

pub fn assets(&self) -> &Assets

Explicit resource owner; an unconfigured context does not resolve relative files.

Source

pub fn record( &self, drawable: &dyn Drawable, limits: ValidationLimits, ) -> Result<Vec<DrawCommand>, ValidationError>

Records a drawable’s local commands without rendering or color quantization.

Limits charge the drawable at depth one and every command at depth two. Callback errors and ignored canvas errors both fail the recording. This local buffer is not a scene DisplayList; use crate::Node::compile for layout, global transforms and isolated subtree opacity.

use motion_core::prelude::*;
use motion_core::{
    DisplayList, RasterLimits, ResourceStore, ValidatedDisplayList, MAX_PATH_VERBS,
    MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
let bounds = Rect::new(0.1, 0.2, 10.3, 20.4);
let color = Color::from_rgb_float(1.25, -0.125, 0.333);
let commands =
    DrawContext::new(2.0)?.record(&bounds.fill(color), ValidationLimits::default())?;
assert_eq!(
    commands,
    vec![DrawCommand::FillRect {
        bounds,
        transform: Transform::IDENTITY,
        paint: Paint::Solid(color)
    }]
);
Source

pub fn with_validation_limits(self, limits: ValidationLimits) -> Self

Supplies the enclosing structural policy to deferred layout callbacks.

Source

pub fn validation_limits(&self) -> ValidationLimits

Structural policy supplied by the enclosing measurement or compilation.

Source

pub fn with_render_cache(self, cache: RenderCache) -> Self

Supplies partitioned compute caches shared by rendering workers.

Source

pub fn render_cache(&self) -> Option<&RenderCache>

Shared cache partitions, absent for standalone uncached drawing.

Source

pub fn cache_layout<Key: Eq + Hash + Send + Sync + 'static, Value: Send + Sync + 'static>( &self, key: Key, build: impl FnOnce() -> Value, cost: impl FnOnce(&Value) -> usize, ) -> Arc<Value> ⓘ

Caches immutable layout in the paragraph partition by full typed key and declared logical payload; without a render cache the value is rebuilt.

Source

pub fn with_font_usage(self, usage: FontUsage) -> Self

Carries an export-owned font observation sink into every recorded glyph.

Source

pub fn font_usage(&self) -> &FontUsage

Font sources actually painted through this context.

Source

pub fn with_invalid_geometry_marker(self, mark: bool) -> Self

Draws leaves with invalid geometry as a visible error marker instead of failing compilation. Intended for preview; export keeps the strict default.

Source

pub fn marks_invalid_geometry(&self) -> bool

Whether invalid leaf geometry is drawn as an error marker.

Source

pub fn with_diagnostics(self, diagnostics: RequestDiagnostics) -> Self

Carries request diagnostics explicitly through deferred content compilation.

Source

pub fn diagnostics(&self) -> &RequestDiagnostics

Request-owned sink; cloning this drawing context preserves its identity.

Trait Implementations§

Source§

impl Clone for DrawContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DrawContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DrawContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.