example_3/
example_3.rs

1use animaterm::prelude::*;
2use animaterm::utilities::message_box;
3use std::collections::HashMap;
4
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 gr = Graphic::new(cols, rows, start_frame, library, None);
46
47    let layer = 0;
48    let offset = (15, 5);
49    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
50    let screen_size = mgr.screen_size();
51    let title = "Navigation help".to_string();
52    let text = "Use arrows to move graphic around \nPress q or Shift+q to quit\n".to_string();
53    let mbox = message_box(Some(title), text, Glyph::default(), 37, 5);
54    let mbid = mgr
55        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
56        .unwrap();
57    mgr.set_graphic(graphic_id, start_frame, true);
58    mgr.set_graphic(mbid, 0, true);
59
60    let mut keep_running = true;
61    while keep_running {
62        if let Some(key) = mgr.read_key() {
63            match key {
64                Key::Left => mgr.move_graphic(graphic_id, layer, (-1, 0)),
65                Key::Right => mgr.move_graphic(graphic_id, layer, (1, 0)),
66                Key::Up => mgr.move_graphic(graphic_id, layer, (0, -1)),
67                Key::Down => mgr.move_graphic(graphic_id, layer, (0, 1)),
68                Key::Q | Key::ShiftQ => {
69                    keep_running = false;
70                }
71                _ => continue,
72            }
73        }
74    }
75
76    mgr.terminate();
77}