pub struct Animation {
pub running: bool,
/* private fields */
}Expand description
This structure contains information about Animation progress with time. It does not contain any frames, making it possible to reuse those frames in multiple animations belonging to the same graphic. Also the same animation structure can be reused by multiple graphics with different frames making them appear as if they are running in sync.
Fields§
§running: boolImplementations§
Source§impl Animation
impl Animation
Sourcepub fn new(
running: bool,
looping: bool,
ordering: Vec<(usize, Timestamp)>,
start_time: Timestamp,
) -> Animation
pub fn new( running: bool, looping: bool, ordering: Vec<(usize, Timestamp)>, start_time: Timestamp, ) -> Animation
This method creates a new Animation instance. One can decide whether it should be running immediately or only after defined moment in time. One can also decide if it should run only once, or start over again and again.
Examples found in repository?
408fn build_graphic(cols: usize, rows: usize) -> (Graphic, usize) {
409 let start_frame = 0;
410 let mut library = HashMap::with_capacity(2);
411 library.insert(
412 start_frame,
413 vec![
414 Glyph::new(
415 '\u{2580}',
416 animaterm::Color::new_8bit(0, 5, 0),
417 animaterm::Color::new_8bit(0, 0, 5),
418 false,
419 true,
420 false,
421 false,
422 false,
423 false,
424 false,
425 false,
426 false,
427 false,
428 );
429 rows * cols
430 ],
431 );
432 let mut animations = HashMap::new();
433 animations.insert(
434 0,
435 Animation::new(
436 false,
437 true,
438 vec![(1, Timestamp::new(0, 500)), (0, Timestamp::new(0, 500))],
439 Timestamp::now(),
440 ),
441 );
442
443 let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
444 let pid = gr
445 .add_to_library(vec![
446 Glyph::new(
447 '\u{2580}',
448 animaterm::Color::new_truecolor(0, 255, 255),
449 animaterm::Color::new_truecolor(0, 0, 255),
450 false,
451 true,
452 false,
453 false,
454 false,
455 false,
456 false,
457 false,
458 false,
459 false,
460 );
461 rows * cols
462 ])
463 .unwrap();
464 (gr, pid)
465}More examples
5fn main() {
6 let mut mgr = Manager::new(true, None, None, None, None, None);
7
8 let mut library = HashMap::with_capacity(2);
9 let cols = 10;
10 let rows = 5;
11 let start_frame = 0;
12 let glyph_1 = Glyph::new(
13 '\u{2580}',
14 Color::new_8bit(0, 0, 5),
15 Color::new_8bit(5, 5, 0),
16 false,
17 true,
18 false,
19 false,
20 false,
21 false,
22 false,
23 false,
24 false,
25 false,
26 );
27 let glyph_2 = Glyph::new(
28 '\u{258C}',
29 Color::new_truecolor(255, 255, 255),
30 Color::new_truecolor(255, 0, 0),
31 false,
32 true,
33 false,
34 false,
35 false,
36 false,
37 false,
38 false,
39 false,
40 false,
41 );
42
43 library.insert(start_frame, vec![glyph_1; rows * cols]);
44 library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
45 let ordering = vec![
46 (start_frame, Timestamp::new(0, 500)),
47 (start_frame + 1, Timestamp::new(0, 500)),
48 ];
49 let running = false;
50 let looping = true;
51 let start_time = Timestamp::now();
52 let animation = Animation::new(running, looping, ordering, start_time);
53 let mut animations = HashMap::new();
54 let anim_id = 0;
55 animations.insert(anim_id, animation);
56 let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
57 let fast_ordering = vec![
58 (start_frame, Timestamp::new(0, 200)),
59 (start_frame + 1, Timestamp::new(0, 200)),
60 ];
61 let mut fast_anim_id = anim_id;
62 if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
63 {
64 fast_anim_id = id;
65 };
66
67 let layer = 0;
68 let offset = (15, 5);
69 let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
70 let screen_size = mgr.screen_size();
71 let title = "Navigation help".to_string();
72 let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press a|Shift+a|Ctrl+a start anim \n Press s or Shift+s stop animation\n\n Press q or Shift+q to quit\n".to_string();
73 let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
74 let mbid = mgr
75 .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
76 .unwrap();
77 mgr.set_graphic(mbid, 0, true);
78
79 let var_ordering = vec![
80 (start_frame, Timestamp::new(0, 400)),
81 (start_frame + 1, Timestamp::new(0, 400)),
82 (start_frame, Timestamp::new(0, 300)),
83 (start_frame + 1, Timestamp::new(0, 300)),
84 (start_frame, Timestamp::new(0, 200)),
85 (start_frame + 1, Timestamp::new(0, 200)),
86 (start_frame, Timestamp::new(0, 100)),
87 (start_frame + 1, Timestamp::new(0, 100)),
88 (start_frame, Timestamp::new(0, 200)),
89 (start_frame + 1, Timestamp::new(0, 200)),
90 (start_frame, Timestamp::new(0, 300)),
91 (start_frame + 1, Timestamp::new(0, 300)),
92 ];
93 // let mut all_results_read = false;
94 // while !all_results_read {
95 // let result = mgr.read_result();
96 // match result {
97 // Ok(AnimOk::AllResultsRead) => all_results_read = true,
98 // _ => continue,
99 // }
100 // }
101 mgr.add_animation(
102 graphic_id,
103 Animation::new(false, true, var_ordering, Timestamp::now()),
104 );
105 let mut var_anim_id = 0;
106
107 if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
108 var_anim_id = anim_id;
109 }
110
111 let mut keep_running = true;
112 while keep_running {
113 if let Some(key) = mgr.read_key() {
114 match key {
115 Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
116 Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
117 Key::A => mgr.start_animation(graphic_id, anim_id),
118 Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
119 Key::P => mgr.pause_animation(graphic_id),
120 Key::CtrlP => mgr.pause_animation(graphic_id),
121 Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
122 Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
123 Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
124 Key::Q | Key::ShiftQ => {
125 keep_running = false;
126 }
127 _ => continue,
128 }
129 }
130 }
131
132 mgr.terminate();
133}Sourcepub fn start(&mut self, t: Timestamp)
pub fn start(&mut self, t: Timestamp)
This method is used to start an Animation if it is not already running.
Sourcepub fn restart(&mut self, t: Timestamp)
pub fn restart(&mut self, t: Timestamp)
Use this method to start an Animation from beginning frame.
Sourcepub fn freeze(&mut self, t: Timestamp)
pub fn freeze(&mut self, t: Timestamp)
Prevent an Animation from switching to the next frame for given amount of time.
Sourcepub fn pause_on_frame(&mut self, frame_id: usize)
pub fn pause_on_frame(&mut self, frame_id: usize)
Pause an Animation when given frame is being displayed.