Skip to main content

Scene

Trait Scene 

Source
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§

Source

fn render(&self, context: &SceneContext<'_>) -> Node

Builds one snapshot without retaining previous-frame state.

Provided Methods§

Source

fn validate(&self) -> Result<()>

Validates deferred authoring errors without evaluating a frame.

Source

fn duration(&self) -> Option<Duration>

Natural finite duration, or None when a caller must provide one.

Source

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".

Implementations on Foreign Types§

Source§

impl Scene for Arc<dyn Scene>

Source§

fn validate(&self) -> Result<()>

Source§

fn render(&self, context: &SceneContext<'_>) -> Node

Source§

fn duration(&self) -> Option<Duration>

Implementors§

Source§

impl Scene for TimelineVisual

Source§

impl<Callback> Scene for Callback
where Callback: Fn(&SceneContext<'_>) -> Node + Send + Sync,

Source§

impl<Content: Scene> Scene for WithDuration<Content>