-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake-animative.rs
40 lines (34 loc) · 1.08 KB
/
make-animative.rs
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
// anim
//
// A framework independent animation library for rust, works nicely with Iced and the others
// Copyright: 2021, Joylei <[email protected]>
// License: MIT
use anim::{timeline::Status, Animatable, Options, Timeline};
use std::time::Duration;
/// make it animatable, do not forget to derive Clone
#[derive(Clone, Debug, Animatable)]
struct MyModel {
a: f32, //animatable
b: i64, //animatable
}
// once it's animatable, you can use it with anim::timeline::Options;
fn main() {
let from = MyModel { a: 0.0, b: 32 };
let to = MyModel { a: 100.0, b: 100 };
let mut timeline: Timeline<_> = Options::new(from, to)
.duration(Duration::from_secs(2))
.times(1.5)
.into();
println!("start animation");
timeline.begin();
loop {
let status = timeline.update();
if status == Status::Completed {
break;
}
let value = timeline.value();
println!("animated: {:?}", value);
}
let value = timeline.value();
println!("animated: {:?}", value);
}