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
impl DrawContext
Sourcepub fn new(device_scale: f64) -> Result<Self, ValidationError>
pub fn new(device_scale: f64) -> Result<Self, ValidationError>
Creates drawing inputs with a finite, strictly positive device scale.
Sourcepub fn with_evaluation(self, evaluation: Arc<Evaluation>) -> Self
pub fn with_evaluation(self, evaluation: Arc<Evaluation>) -> Self
Replaces the shared evaluation environment.
Sourcepub fn evaluation(&self) -> &Arc<Evaluation> ⓘ
pub fn evaluation(&self) -> &Arc<Evaluation> ⓘ
Shared time, quality, resources, diagnostics and caches.
Sourcepub fn with_quality(self, quality: RenderQuality) -> Self
pub fn with_quality(self, quality: RenderQuality) -> Self
Selects an explicit approximation policy for deferred content recording.
Sourcepub fn render_quality(&self) -> RenderQuality
pub fn render_quality(&self) -> RenderQuality
Production quality is the default for every standalone drawing context.
Sourcepub fn with_time(self, time: Time) -> Self
pub fn with_time(self, time: Time) -> Self
Supplies scene-local signed time to deferred content effects.
Sourcepub fn device_scale(&self) -> f64
pub fn device_scale(&self) -> f64
Device pixels per logical unit; does not implicitly modify local geometry.
Sourcepub fn with_fonts(self, fonts: impl Into<FontEnvironment>) -> Self
pub fn with_fonts(self, fonts: impl Into<FontEnvironment>) -> Self
Supplies a shared explicit font snapshot to paragraph bounds and drawing.
Sourcepub fn fonts(&self) -> Option<&FontEnvironment>
pub fn fonts(&self) -> Option<&FontEnvironment>
Font environment for paragraph text, optional for geometry-only drawing.
Sourcepub fn with_assets(self, assets: &Assets) -> Self
pub fn with_assets(self, assets: &Assets) -> Self
Captures the same lazy/preloaded owner used by the enclosing session.
Sourcepub fn assets(&self) -> &Assets
pub fn assets(&self) -> &Assets
Explicit resource owner; an unconfigured context does not resolve relative files.
Sourcepub fn record(
&self,
drawable: &dyn Drawable,
limits: ValidationLimits,
) -> Result<Vec<DrawCommand>, ValidationError>
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)
}]
);Sourcepub fn with_validation_limits(self, limits: ValidationLimits) -> Self
pub fn with_validation_limits(self, limits: ValidationLimits) -> Self
Supplies the enclosing structural policy to deferred layout callbacks.
Sourcepub fn validation_limits(&self) -> ValidationLimits
pub fn validation_limits(&self) -> ValidationLimits
Structural policy supplied by the enclosing measurement or compilation.
Sourcepub fn with_render_cache(self, cache: RenderCache) -> Self
pub fn with_render_cache(self, cache: RenderCache) -> Self
Supplies partitioned compute caches shared by rendering workers.
Sourcepub fn render_cache(&self) -> Option<&RenderCache>
pub fn render_cache(&self) -> Option<&RenderCache>
Shared cache partitions, absent for standalone uncached drawing.
Sourcepub 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> ⓘ
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.
Sourcepub fn with_font_usage(self, usage: FontUsage) -> Self
pub fn with_font_usage(self, usage: FontUsage) -> Self
Carries an export-owned font observation sink into every recorded glyph.
Sourcepub fn font_usage(&self) -> &FontUsage
pub fn font_usage(&self) -> &FontUsage
Font sources actually painted through this context.
Sourcepub fn with_invalid_geometry_marker(self, mark: bool) -> Self
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.
Sourcepub fn marks_invalid_geometry(&self) -> bool
pub fn marks_invalid_geometry(&self) -> bool
Whether invalid leaf geometry is drawn as an error marker.
Sourcepub fn with_diagnostics(self, diagnostics: RequestDiagnostics) -> Self
pub fn with_diagnostics(self, diagnostics: RequestDiagnostics) -> Self
Carries request diagnostics explicitly through deferred content compilation.
Sourcepub fn diagnostics(&self) -> &RequestDiagnostics
pub fn diagnostics(&self) -> &RequestDiagnostics
Request-owned sink; cloning this drawing context preserves its identity.