Skip to main content

ranim_core/animation/compose/
mod.rs

1//! User-facing composition helpers built on the core node language.
2//!
3//! `AnimSequence`, `AnimStack`, and `AnimLagged` are sugar/elaboration
4//! constructors: they own their child definitions and lower to the closed
5//! [`crate::animation::node::NodeContent`] vocabulary in
6//! [`crate::animation::build::IntoAnimNode::into_anim_node`]. The primitives they
7//! lower to stay in core so every interpreter (visual eval, audio bake, preview
8//! info) can see the same structure.
9//!
10pub mod lagged;
11pub mod sequence;
12pub mod stack;
13
14use crate::animation::build::{IntoAnimNode, Unplaced};
15use crate::animation::compose::{lagged::AnimLagged, sequence::AnimSequence, stack::AnimStack};
16
17/// Collect iterators of animations into containers.
18pub trait AnimIterExt: Iterator + Sized {
19    /// Collect the animations into an [`AnimStack`] (all at the same origin).
20    fn into_stack(self) -> AnimStack
21    where
22        Self::Item: IntoAnimNode + 'static,
23    {
24        self.collect()
25    }
26
27    /// Collect the animations into an [`AnimSequence`] (played in order).
28    fn into_seq(self) -> AnimSequence
29    where
30        Self::Item: Unplaced + 'static,
31    {
32        self.collect()
33    }
34
35    /// Collect the animations into an [`AnimLagged`] with the given stagger ratio.
36    fn into_lagged(self, lag_ratio: f64) -> AnimLagged
37    where
38        Self::Item: Unplaced + 'static,
39    {
40        let mut lagged = AnimLagged::new(lag_ratio);
41        for animation in self {
42            lagged.push(animation);
43        }
44        lagged
45    }
46}
47
48impl<I: Iterator> AnimIterExt for I {}