1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! State-driven animation helpers.
//!
//! Use this module when application states should map to reusable animation
//! timelines. A [`StateTransitionSet`] matches `(from, to)` pairs and
//! [`StateAnimator`] registers the matching timeline against one runtime target.
//!
//! ```
//! use aura_anim_iced::{
//! AnimationRuntime, AnimationTargetId, Duration, OPACITY, PropertyValue,
//! StateAnimator, StateTransition, StateTransitionSet, Timeline, Track,
//! };
//!
//! #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
//! enum Panel {
//! Closed,
//! Open,
//! }
//!
//! fn fade(from: f32, to: f32) -> Timeline {
//! Timeline::track(
//! Track::from(OPACITY, from)
//! .to(to)
//! .duration(Duration::from_millis(100.0)),
//! )
//! }
//!
//! let mut runtime = AnimationRuntime::testing();
//! let target = AnimationTargetId::new();
//! let transitions = StateTransitionSet::from_transitions([
//! StateTransition::new(Panel::Closed, Panel::Open, fade(0.0, 1.0)),
//! ]);
//! let mut animator = StateAnimator::new(target, Panel::Closed);
//!
//! let registration = animator
//! .transition_to(&mut runtime, Panel::Open, &transitions)
//! .expect("closed to open transition");
//! assert_eq!(animator.active_handle(), Some(registration.handle()));
//!
//! runtime.clock_mut().set_now(Duration::from_millis(50.0));
//! let tick = runtime.tick();
//! let entry = tick
//! .properties_for(target)
//! .unwrap()
//! .find_property(&OPACITY.raw())
//! .unwrap();
//! assert!(matches!(entry.value(), PropertyValue::Scalar(value) if (*value - 0.5).abs() < 0.001));
//! ```
pub use StateAnimator;
pub use StateTransitionSet;
pub use ;
pub use StateTransitionRegistration;
pub use StateTransition;