pub struct MotionRuntime { /* private fields */ }Expand description
Stores animations, advances active values, and queues lifecycle events.
§Examples
use aura_anim_core::{runtime::MotionRuntime, timing::Timing};
use std::time::Duration;
let mut runtime = MotionRuntime::new();
let opacity = runtime.motion_with(0.0_f32, Timing::new(100.0));
opacity.transition_to(1.0, &mut runtime).unwrap();
runtime.tick(Duration::from_millis(50));
assert_eq!(opacity.value(&runtime).unwrap(), 0.5);
assert!(opacity.is_active(&runtime).unwrap());
assert!(runtime.events().is_empty());Implementations§
Source§impl MotionRuntime
impl MotionRuntime
Sourcepub fn motion<T: Animatable>(&mut self, initial: T) -> Motion<T>
pub fn motion<T: Animatable>(&mut self, initial: T) -> Motion<T>
Inserts an idle motion with the default transition timing.
Sourcepub fn motion_with<T: Animatable>(
&mut self,
initial: T,
timing: Timing,
) -> Motion<T>
pub fn motion_with<T: Animatable>( &mut self, initial: T, timing: Timing, ) -> Motion<T>
Inserts an idle motion with the provided transition timing.
Sourcepub fn insert<T: Animatable>(
&mut self,
animation: impl Animation<T>,
transition: Timing,
) -> Motion<T>
pub fn insert<T: Animatable>( &mut self, animation: impl Animation<T>, transition: Timing, ) -> Motion<T>
Inserts an animation that remains stored after it settles.
Sourcepub fn play_once<T: Animatable>(
&mut self,
animation: impl Animation<T>,
) -> Motion<T>
pub fn play_once<T: Animatable>( &mut self, animation: impl Animation<T>, ) -> Motion<T>
Inserts an animation that is removed after it settles.
Sourcepub fn insert_with_policy<T: Animatable>(
&mut self,
animation: impl Animation<T>,
transition: Timing,
retain_policy: RetainPolicy,
) -> Motion<T>
pub fn insert_with_policy<T: Animatable>( &mut self, animation: impl Animation<T>, transition: Timing, retain_policy: RetainPolicy, ) -> Motion<T>
Inserts an animation with transition timing and a retention policy.
Sourcepub fn tick_at(&mut self, now: Instant)
pub fn tick_at(&mut self, now: Instant)
Advances active animations using elapsed wall-clock time.
The first call establishes the clock origin and advances by zero.
Sourcepub fn events(&self) -> &[MotionEvent]
pub fn events(&self) -> &[MotionEvent]
Returns queued lifecycle events without consuming them.
Sourcepub fn take_events(&mut self) -> Vec<MotionEvent>
pub fn take_events(&mut self) -> Vec<MotionEvent>
Takes all queued lifecycle events.
Events remain queued until they are taken or explicitly cleared.
Sourcepub fn clear_events(&mut self)
pub fn clear_events(&mut self)
Removes all queued lifecycle events.
Sourcepub fn pending_event_count(&self) -> usize
pub fn pending_event_count(&self) -> usize
Returns the number of queued lifecycle events.
Sourcepub fn active_count(&self) -> usize
pub fn active_count(&self) -> usize
Returns the number of animations currently marked active.
Sourcepub fn has_active(&self) -> bool
pub fn has_active(&self) -> bool
Returns whether at least one animation is active.
Sourcepub fn motion_count(&self) -> usize
pub fn motion_count(&self) -> usize
Returns the number of stored animations.
Sourcepub fn slot_capacity(&self) -> usize
pub fn slot_capacity(&self) -> usize
Returns the allocated capacity of the runtime slot storage.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Releases unused slot and queue capacity.
Sourcepub fn value<T: Animatable>(&self, motion: Motion<T>) -> Result<&T, MotionError>
pub fn value<T: Animatable>(&self, motion: Motion<T>) -> Result<&T, MotionError>
Returns the current value for motion.
Sourcepub fn state<T: Animatable>(
&self,
motion: Motion<T>,
) -> Result<AnimationState, MotionError>
pub fn state<T: Animatable>( &self, motion: Motion<T>, ) -> Result<AnimationState, MotionError>
Returns the lifecycle state for motion.
Sourcepub fn playback<T: Animatable>(
&self,
motion: Motion<T>,
) -> Result<PlaybackId, MotionError>
pub fn playback<T: Animatable>( &self, motion: Motion<T>, ) -> Result<PlaybackId, MotionError>
Returns the ID of the motion’s current playback.
Sourcepub fn is_active<T: Animatable>(
&self,
motion: Motion<T>,
) -> Result<bool, MotionError>
pub fn is_active<T: Animatable>( &self, motion: Motion<T>, ) -> Result<bool, MotionError>
Returns whether motion is active.
Sourcepub fn transition_to<T: Animatable>(
&mut self,
motion: Motion<T>,
target: T,
) -> Result<(), MotionError>
pub fn transition_to<T: Animatable>( &mut self, motion: Motion<T>, target: T, ) -> Result<(), MotionError>
Transitions motion toward target.
Sourcepub fn transition_to_tracked<T: Animatable>(
&mut self,
motion: Motion<T>,
target: T,
) -> Result<PlaybackId, MotionError>
pub fn transition_to_tracked<T: Animatable>( &mut self, motion: Motion<T>, target: T, ) -> Result<PlaybackId, MotionError>
Transitions motion toward target and returns its new playback ID.
Sourcepub fn play<T, P, Kind>(
&mut self,
motion: Motion<T>,
playback: P,
) -> Result<(), MotionError>where
T: Animatable,
P: IntoMotionAnimation<T, Kind>,
pub fn play<T, P, Kind>(
&mut self,
motion: Motion<T>,
playback: P,
) -> Result<(), MotionError>where
T: Animatable,
P: IntoMotionAnimation<T, Kind>,
Replaces the animation associated with motion.
Sourcepub fn play_tracked<T, P, Kind>(
&mut self,
motion: Motion<T>,
playback: P,
) -> Result<PlaybackId, MotionError>where
T: Animatable,
P: IntoMotionAnimation<T, Kind>,
pub fn play_tracked<T, P, Kind>(
&mut self,
motion: Motion<T>,
playback: P,
) -> Result<PlaybackId, MotionError>where
T: Animatable,
P: IntoMotionAnimation<T, Kind>,
Replaces the animation associated with motion and returns its playback ID.
Sourcepub fn command<T: Animatable>(
&mut self,
motion: Motion<T>,
command: AnimationCommand,
) -> Result<(), MotionError>
pub fn command<T: Animatable>( &mut self, motion: Motion<T>, command: AnimationCommand, ) -> Result<(), MotionError>
Applies a command to motion.
Sourcepub fn command_all(&mut self, command: AnimationCommand)
pub fn command_all(&mut self, command: AnimationCommand)
Applies command to every stored motion.
This includes idle, running, paused, and settled motions. Commands keep
their normal per-animation semantics, including terminal events and
RetainPolicy::DropWhenSettled removal.
Sourcepub fn remove<T: Animatable>(
&mut self,
motion: Motion<T>,
) -> Result<(), MotionError>
pub fn remove<T: Animatable>( &mut self, motion: Motion<T>, ) -> Result<(), MotionError>
Removes the animation referenced by motion.