pub trait Scene: Send + Sync {
// Required method
fn render(&self, context: &SceneContext<'_>) -> Node;
// Provided methods
fn validate(&self) -> Result<()> { ... }
fn duration(&self) -> Option<Duration> { ... }
fn with_duration(self, duration: Duration) -> WithDuration<Self>
where Self: Sized { ... }
}Expand description
A stateless scene evaluated from explicit authoring inputs.
Closures implement this canonical root crate::Scene protocol.
use motion_core::prelude::*;
use motion_core::{
DisplayList, RasterLimits, ResourceStore, ValidatedDisplayList, MAX_PATH_VERBS,
MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
let child = (|context: &SceneContext<'_>| {
assert_eq!(context.time(), 1.seconds().after_origin());
assert_eq!(context.global_time(), 2.seconds().after_origin());
Node::from(Rect::new(0.0, 0.0, 32.0, 24.0).fill(Color::rgb(20, 150, 125)))
})
.with_duration(2.seconds());
let cache = SceneCache::new(0);
let context = SceneContext::new(
2.seconds().after_origin(),
fps!(30),
Size::new(640.0, 360.0),
&cache,
);
let node = context.during(Time::ZERO, 4.seconds(), |local| {
local.embed(&child, 1.seconds().after_origin())
});
let frame = node.compile(
context.size(),
PixelSize::new(64, 36),
ValidationLimits::default(),
)?;Required Methods§
Sourcefn render(&self, context: &SceneContext<'_>) -> Node
fn render(&self, context: &SceneContext<'_>) -> Node
Builds one snapshot without retaining previous-frame state.
Provided Methods§
Sourcefn validate(&self) -> Result<()>
fn validate(&self) -> Result<()>
Validates deferred authoring errors without evaluating a frame.
Sourcefn duration(&self) -> Option<Duration>
fn duration(&self) -> Option<Duration>
Natural finite duration, or None when a caller must provide one.
Sourcefn with_duration(self, duration: Duration) -> WithDuration<Self>where
Self: Sized,
fn with_duration(self, duration: Duration) -> WithDuration<Self>where
Self: Sized,
Overrides clip metadata without retiming or clamping the callback.
Zero duration has an empty active interval.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".