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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! An event associated with an [`crate::Animated`] value.
//!
//! Spring events can represent three general types of events:
//! - A tick event that updates the animated value
//! - A target event that sets the animated target value
//! - A settle event that ends the animation early.
//!
//! This event can be passed to [`crate::Animated::update`] to update the current value.
//! You can also use the `From` impl to create a [`Event::Target`] from a
//! value, e.g. `Message::ChangeSize(5.0.into())` instead of
//! `Message::ChangeSize(Event::Target(5.0))`.
//!
//! ```rust
//! # use iced_anim::{Animated, spring::Motion, Event};
//! let mut spring_1 = Animated::spring(0.0, Motion::default());
//! spring_1.update(Event::Target(5.0));
//!
//! let mut spring_2 = Animated::spring(0.0, Motion::default());
//! spring_2.update(5.0.into());
//!
//! assert_eq!(spring_1.target(), &5.0);
//! assert_eq!(spring_2.target(), &5.0);
//! ```
use crateAnimate;
use Instant;
/// An event associated with an animated `Spring` value.
///
/// This event represents one of three things:
/// - A tick event that updates the spring's value, e.g. a frame is rendered
/// and the spring's value should be updated.
/// - A target event that sets the spring's target value, e.g. a user presses
/// a button and changes the target size of an animated value.
/// - A settle event that ends the animation early by jumping to the target
/// value.
///
/// This event can be passed to [`crate::Animated::update`] to update the spring's value.
// Impl `Copy` for `Event` when `T` is `Copy`.
// Any `From` usages should return a `Event::Target` variant.