animaterm

Struct Graphic

source
pub struct Graphic {
    pub rows: usize,
    pub cols: usize,
    pub current_frame: usize,
    pub invisible: bool,
    pub running_anim: Option<usize>,
    pub awaiting_anim: Option<(usize, Timestamp)>,
    pub animations: HashMap<usize, Animation>,
    /* private fields */
}
Expand description

A structure representing graphic containing current frame and animation information etc. Every frame in a graphic has to be of the same size of rows x cols.

Fields§

§rows: usize§cols: usize§current_frame: usize§invisible: bool§running_anim: Option<usize>§awaiting_anim: Option<(usize, Timestamp)>§animations: HashMap<usize, Animation>

Implementations§

source§

impl Graphic

source

pub fn new( cols: usize, rows: usize, start_frame: usize, library: HashMap<usize, Vec<Glyph>>, animations: Option<HashMap<usize, Animation>>, ) -> Self

Create a new graphic of a given size with defined frames and animations.

Examples found in repository?
examples/example_5.rs (line 443)
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
fn build_graphic(cols: usize, rows: usize) -> (Graphic, usize) {
    let start_frame = 0;
    let mut library = HashMap::with_capacity(2);
    library.insert(
        start_frame,
        vec![
            Glyph::new(
                '\u{2580}',
                animaterm::Color::new_8bit(0, 5, 0),
                animaterm::Color::new_8bit(0, 0, 5),
                false,
                true,
                false,
                false,
                false,
                false,
                false,
                false,
                false,
                false,
            );
            rows * cols
        ],
    );
    let mut animations = HashMap::new();
    animations.insert(
        0,
        Animation::new(
            false,
            true,
            vec![(1, Timestamp::new(0, 500)), (0, Timestamp::new(0, 500))],
            Timestamp::now(),
        ),
    );

    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let pid = gr
        .add_to_library(vec![
            Glyph::new(
                '\u{2580}',
                animaterm::Color::new_truecolor(0, 255, 255),
                animaterm::Color::new_truecolor(0, 0, 255),
                false,
                true,
                false,
                false,
                false,
                false,
                false,
                false,
                false,
                false,
            );
            rows * cols
        ])
        .unwrap();
    (gr, pid)
}
More examples
Hide additional examples
examples/example_3.rs (line 45)
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
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Use arrows to move graphic around \nPress q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 5);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 6))
        .unwrap();
    mgr.set_graphic(graphic_id, start_frame, true);
    mgr.set_graphic(mbid, 0, true);

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Left => mgr.move_graphic(graphic_id, layer, (-1, 0)),
                Key::Right => mgr.move_graphic(graphic_id, layer, (1, 0)),
                Key::Up => mgr.move_graphic(graphic_id, layer, (0, -1)),
                Key::Down => mgr.move_graphic(graphic_id, layer, (0, 1)),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
examples/example_1.rs (line 57)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
fn main() {
    let macros = Some(vec![
        (Key::AltM, MacroSequence::empty()),
        (
            Key::T,
            MacroSequence::from_text(
                "This text was typed with a single key press!".to_string(),
                Duration::from_millis(100),
                false,
            ),
        ),
    ]);
    let mut mgr = Manager::new(true, None, None, None, None, macros);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let gr = Graphic::new(cols, rows, start_frame, library, None);

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    let text = "Press 0 to set current frame to 0\n Press 1 to set current frame to 1\n Press t to type text using macro\n Press AltM to define a macro\n\nPress q or Shift+q to quit\n".to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 37, 7);
    let mbid = mgr.add_graphic(mbox, 1, (1, screen_size.1 as isize - 10));
    if let Some(mid) = mbid {
        mgr.set_graphic(mid, 0, true);
    }

    let mut keep_running = true;
    mgr.move_cursor(1, 1);
    let mut macro_mode: u8 = 0;
    let mut looped = false;
    while keep_running {
        let read_result = mgr.read_key();
        if read_result.is_none() {
            continue;
        }
        let key = read_result.unwrap();
        if let Some(ch) = map_key_to_char(&key) {
            if macro_mode == 0 {
                print!("{}", ch);
            }
        }
        match key {
            Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
            Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
            Key::AltM => match macro_mode {
                0 => {
                    // let (max_x, may_y)=mgr.screen_size();
                    // mgr.clear_area(0, (0,1),(max_x,4) );
                    println!("Press trigger key (or AltM again to toggle macro looping)");
                    macro_mode = 1;
                }
                1 => {
                    looped = !looped;
                    println!("Macro looping: {}", looped);
                }
                2 => {
                    println!("Macro is defined!");
                    macro_mode = 0;
                    looped = false;
                }
                _ => {
                    println!("This should not happen");
                }
            },
            Key::Q | Key::ShiftQ => {
                keep_running = false;
            }
            other => {
                if macro_mode == 1 {
                    println!("Macro trigger: {}", other);
                    println!("Not type macro sequence, followed by AltM");
                    macro_mode = 2;
                } else if macro_mode == 2 {
                    println!("Macro sequence add: {}", other)
                } else {
                    continue;
                }
            }
        }
    }

    mgr.terminate();
}
examples/example_2.rs (line 56)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    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();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
source

pub fn from_file<P>(filename: P) -> Option<Self>
where P: AsRef<Path> + Debug,

Read a graphic from file.

Examples found in repository?
examples/example_5.rs (line 86)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
fn main() {
    let args = parse_arguments();
    let cols = args.cols;
    let rows = args.rows;
    verify_cols_and_rows(cols, rows);
    let mut g = Glyph::default();
    g.set_background(Color::green());
    g.set_char(char::from_u32(9626).unwrap());
    g.set_bright(true);

    let mut mgr = Manager::new(true, cols, rows, Some(g), None, None);
    let (cols, rows) = mgr.screen_size();

    let title = "Navigation help".to_string();
    let text = "CtrlPgUp,CtrlPgDn, -------------------------------------
AltPgUp,AltPgDn, ---------------------------------------
PgUp,PgDn, ---------------------------------------------
U,D, ---------------------------------------------------
CtrlU,CtrlD -------------------------------------------- 
AltU,AltD ----------------------------------------------
AltUp | AltK -------------------------------------------
CtrlUp | CtrlK -----------------------------------------
Up | K -------------------------------------------------
AltDown | AltJ -----------------------------------------
CtrlDown -----------------------------------------------
Down | J -----------------------------------------------
AltLeft | AltH -----------------------------------------
CtrlLeft | Backspace -----------------------------------
Left | H -----------------------------------------------
AltRight | AltL ----------------------------------------
CtrlRight | CtrlL --------------------------------------
Right | L - all above move graphics around the screen --
----------- and up/down layers. ------------------------
Tab - show a message box -------------------------------
Enter - type some text and hit Enter again -------------
        "
    .to_string();
    let mbox = message_box(Some(title), text, Glyph::default(), 60, 23);
    let mbid = mgr.add_graphic(mbox, 4, (1, 10)).unwrap();
    mgr.set_graphic(mbid, 0, true);
    let (gr, pid) = build_graphic(130, 10);
    let gr_layer = 1;
    let gid;
    let result = mgr.add_graphic(gr, gr_layer, (3, 15));
    if let Some(id) = result {
        gid = id;
    } else {
        eprintln!("Did not receive first graphic id");
        exit(2);
    }
    mgr.set_graphic(gid, pid, true);

    let pbid;
    let mut pb_layer = 3;
    let result = mgr.add_graphic(
        build_progress_bar(cols - 4),
        pb_layer,
        (2, (rows - 2) as isize),
    );
    if let Some(id) = result {
        pbid = id;
    } else {
        eprintln!("Did not receive progress bar graphic id");
        exit(2);
    }
    mgr.set_graphic(pbid, 0, true);
    mgr.start_animation(pbid, 0);
    let mut mbox_created = false;
    let mut mbox_id = 100;
    let mut mbox_layer = 2;
    if Path::new("index.txg").exists() {
        if let Some(id) =
            mgr.add_graphic(Graphic::from_file("index.txg").unwrap(), mbox_layer, (1, 0))
        {
            mgr.move_graphic(id, 2, (-1, 0));
            mbox_id = id;
            mbox_layer = 4;
        }
    } else {
        eprintln!("\x1b[97;41;5mERR\x1b[m Unable to load index.txg. Run this example from within top examples directory!");
        eprintln!("\x1b[97;41;5mERR\x1b[m Or copy *.txf and index.txg from there to current dir.");
        exit(1);
    }

    loop {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::AltUnicode(uni) => match (uni[2], uni[4]) {
                    (53, 53) => {
                        //CtrlPgUp
                        mgr.move_graphic(1, 4, (0, 0));
                    }
                    (54, 53) => {
                        //CtrlPgDn
                        mgr.move_graphic(1, 1, (0, 0));
                    }
                    (53, 51) => {
                        //AltPgUp
                        mgr.move_graphic(2, 5, (0, 0));
                    }
                    (54, 51) => {
                        //AltPgDn
                        mgr.move_graphic(2, 2, (0, 0));
                    }
                    _ => {}
                },
                Key::PgUp | Key::U => {
                    mgr.move_graphic(0, 3, (0, 0));
                }
                Key::PgDn | Key::D => {
                    mgr.move_graphic(0, 0, (0, 0));
                }
                Key::CtrlU => {
                    pb_layer = 4;
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::CtrlD => {
                    mgr.move_graphic(pbid, pb_layer, (0, 0));
                }
                Key::AltU => {
                    mbox_layer = 5;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltD => {
                    mbox_layer = 2;
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 0));
                }
                Key::AltUp | Key::AltK => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, -1));
                }
                Key::CtrlUp | Key::CtrlK => {
                    mgr.move_graphic(pbid, pb_layer, (0, -1));
                }
                Key::Up | Key::K => {
                    mgr.stop_animation(gid);
                    mgr.move_graphic(gid, 1, (0, -1));
                    mgr.set_graphic(gid, 1, true);
                }
                Key::AltDown | Key::AltJ => {
                    mgr.move_graphic(mbox_id, mbox_layer, (0, 1));
                }
                Key::CtrlDown => {
                    mgr.move_graphic(pbid, pb_layer, (0, 1));
                }
                Key::Down | Key::J => {
                    mgr.pause_animation_on_frame(pbid, 100);
                    mgr.move_graphic(gid, 1, (0, 1));
                    mgr.set_graphic(gid, pid, true);
                }
                Key::AltLeft | Key::AltH => {
                    mgr.move_graphic(mbox_id, mbox_layer, (-1, 0));
                }
                Key::CtrlLeft | Key::Backspace => {
                    mgr.move_graphic(pbid, pb_layer, (-1, 0));
                }
                Key::Left | Key::H => {
                    mgr.move_graphic(gid, 1, (-1, 0));
                    mgr.start_animation(gid, 0);
                    mgr.start_animation(pbid, 0);
                }
                Key::AltRight | Key::AltL => {
                    mgr.move_graphic(mbox_id, mbox_layer, (1, 0));
                }
                Key::CtrlRight | Key::CtrlL => {
                    mgr.move_graphic(pbid, pb_layer, (1, 0));
                }
                Key::Right | Key::L => {
                    mgr.move_graphic(gid, 1, (1, 0));
                }
                Key::Tab => {
                    mbox_layer += 1;
                    if !mbox_created {
                        if let  Some(mbid) = mgr.add_graphic(
                            build_mbox(60, 20, "La ku ka ra cza ga wi ga ba ga da da da ja nie".to_string(),
                            "lastBuildDate: Tue, 12 Apr 2022 07:52:44 GMT
* generator: Oddmuse
* copyright: This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under
 any other license that grants the right to use, copy, modify, and distribute the work, as long as that license imposes the restriction that derivative
 works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free
 Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.
* license: https://creativecommons.org/licenses/sa/1.0/
* license: https://www.gnu.org/copyleft/fdl.html
* license: https://www.gnu.org/copyleft/gpl.html".to_string()                        ),
                        mbox_layer,
                        (0, 0),
                    ){
                        mgr.set_graphic(mbid, 0, true);
                            mbox_created = true;
                            mbox_id = mbid;
                        }
                    }
                }
                Key::CtrlA => {
                    mgr.start_animation(gid, 0);
                }
                Key::CtrlB => {
                    mgr.stop_animation(gid);
                }
                Key::Insert => {
                    mgr.set_graphic(gid, 2, false);
                }
                Key::Delete => {}
                Key::Home => {
                    mgr.set_glyph(gid, Glyph::default(), 1, 1);
                    mgr.move_graphic(gid, 1, (0, 0));
                    mgr.empty_frame(gid);
                }
                Key::Escape | Key::Q | Key::CtrlQ => {
                    break;
                }
                Key::Enter => {
                    if !mbox_created {
                        mbox_layer += 1;
                        if let Some(tid) = mgr.add_graphic(
                            build_mbox(
                                40,
                                1,
                                "Please enter title and hit Enter".to_string(),
                                String::new(),
                            ),
                            mbox_layer,
                            (cols as isize / 2 - 20, rows as isize / 2),
                        ) {
                            mgr.set_graphic(tid, 0, true);
                            let line = mgr.read_line();
                            if let Some(mbid) = mgr.add_graphic(
                                build_mbox(
                                    60,
                                    20,
                                    line,
                                    "Hit Enter to type content in.".to_string(),
                                ),
                                mbox_layer,
                                (0, 0),
                            ) {
                                mgr.delete_graphic(tid);
                                mbox_id = mbid;
                                mgr.set_graphic(mbid, 0, true);
                                mbox_created = true;
                            }
                        }
                    } else {
                        let mut x = 1;
                        let mut y = 1;
                        mbox_created = false;
                        let mut rev = Glyph::default();
                        rev.set_reverse(true);
                        for i in 1..31 {
                            mgr.set_glyph(mbox_id, rev, i, 1);
                        }
                        loop {
                            if let Some(c) = mgr.read_char() {
                                if c == '\t' {
                                    break;
                                }
                                if c as u8 == 8 || c as u8 == 127 {
                                    x -= 1;
                                    if x == 0 {
                                        if y > 1 {
                                            y -= 1;
                                            x = 58;
                                        } else {
                                            x = 1;
                                        }
                                    }
                                    mgr.set_glyph(mbox_id, Glyph::default(), x, y);
                                    continue;
                                }
                                if c == '\n' {
                                    break;
                                }

                                mgr.set_glyph(mbox_id, Glyph::default_with_char(c), x, y);
                                x += 1;
                                if x > 58 {
                                    x = 1;
                                    y += 1;
                                }
                            }
                        }
                    }
                }
                _ => {
                    println!("You pressed: {:?}", key);
                }
            }
        }
    }
    mgr.terminate();
}
source

pub fn from_frame(cols: usize, frame: Vec<Glyph>) -> Self

Convert a single frame into a graphic instance.

source

pub fn from_text(cols: usize, text: &str, glyph: Glyph) -> Self

Create a graphic from &str.

source

pub fn from_texts(cols: usize, texts: Vec<(&str, Glyph)>) -> Self

Create a graphic from a vector of &str, each one representing a separate frame.

source

pub fn add_to_library(&mut self, item: Vec<Glyph>) -> Option<usize>

Add a new frame to a library.

Examples found in repository?
examples/example_5.rs (lines 445-462)
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
fn build_graphic(cols: usize, rows: usize) -> (Graphic, usize) {
    let start_frame = 0;
    let mut library = HashMap::with_capacity(2);
    library.insert(
        start_frame,
        vec![
            Glyph::new(
                '\u{2580}',
                animaterm::Color::new_8bit(0, 5, 0),
                animaterm::Color::new_8bit(0, 0, 5),
                false,
                true,
                false,
                false,
                false,
                false,
                false,
                false,
                false,
                false,
            );
            rows * cols
        ],
    );
    let mut animations = HashMap::new();
    animations.insert(
        0,
        Animation::new(
            false,
            true,
            vec![(1, Timestamp::new(0, 500)), (0, Timestamp::new(0, 500))],
            Timestamp::now(),
        ),
    );

    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let pid = gr
        .add_to_library(vec![
            Glyph::new(
                '\u{2580}',
                animaterm::Color::new_truecolor(0, 255, 255),
                animaterm::Color::new_truecolor(0, 0, 255),
                false,
                true,
                false,
                false,
                false,
                false,
                false,
                false,
                false,
                false,
            );
            rows * cols
        ])
        .unwrap();
    (gr, pid)
}
source

pub fn set_invisible( &mut self, invisible: bool, offset: (isize, isize), ) -> Vec<Pixel>

Set a graphic to invisible. offset defines current location of a graphic on screen.

source

pub fn empty_frame(&mut self) -> Option<usize>

Add an empty frame to a graphic.

source

pub fn clone_frame(&mut self, frame_id: usize) -> Option<usize>

Clone a frame from given source frame.

source

pub fn add_animation(&mut self, anim: Animation) -> Option<usize>

Add an animation to a graphic.

Examples found in repository?
examples/example_2.rs (line 62)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn main() {
    let mut mgr = Manager::new(true, None, None, None, None, None);

    let mut library = HashMap::with_capacity(2);
    let cols = 10;
    let rows = 5;
    let start_frame = 0;
    let glyph_1 = Glyph::new(
        '\u{2580}',
        Color::new_8bit(0, 0, 5),
        Color::new_8bit(5, 5, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );
    let glyph_2 = Glyph::new(
        '\u{258C}',
        Color::new_truecolor(255, 255, 255),
        Color::new_truecolor(255, 0, 0),
        false,
        true,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
        false,
    );

    library.insert(start_frame, vec![glyph_1; rows * cols]);
    library.insert(start_frame + 1, vec![glyph_2; rows * cols]);
    let ordering = vec![
        (start_frame, Timestamp::new(0, 500)),
        (start_frame + 1, Timestamp::new(0, 500)),
    ];
    let running = false;
    let looping = true;
    let start_time = Timestamp::now();
    let animation = Animation::new(running, looping, ordering, start_time);
    let mut animations = HashMap::new();
    let anim_id = 0;
    animations.insert(anim_id, animation);
    let mut gr = Graphic::new(cols, rows, start_frame, library, Some(animations));
    let fast_ordering = vec![
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
    ];
    let mut fast_anim_id = anim_id;
    if let Some(id) = gr.add_animation(Animation::new(running, looping, fast_ordering, start_time))
    {
        fast_anim_id = id;
    };

    let layer = 0;
    let offset = (15, 5);
    let graphic_id = mgr.add_graphic(gr, layer, offset).unwrap();
    let screen_size = mgr.screen_size();
    let title = "Navigation help".to_string();
    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();
    let mbox = message_box(Some(title), text, Glyph::default(), 80, 17);
    let mbid = mgr
        .add_graphic(mbox, 1, (1, screen_size.1 as isize - 8))
        .unwrap();
    mgr.set_graphic(mbid, 0, true);

    let var_ordering = vec![
        (start_frame, Timestamp::new(0, 400)),
        (start_frame + 1, Timestamp::new(0, 400)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 100)),
        (start_frame + 1, Timestamp::new(0, 100)),
        (start_frame, Timestamp::new(0, 200)),
        (start_frame + 1, Timestamp::new(0, 200)),
        (start_frame, Timestamp::new(0, 300)),
        (start_frame + 1, Timestamp::new(0, 300)),
    ];
    // let mut all_results_read = false;
    // while !all_results_read {
    //     let result = mgr.read_result();
    //     match result {
    //         Ok(AnimOk::AllResultsRead) => all_results_read = true,
    //         _ => continue,
    //     }
    // }
    mgr.add_animation(
        graphic_id,
        Animation::new(false, true, var_ordering, Timestamp::now()),
    );
    let mut var_anim_id = 0;

    if let Ok(AnimOk::AnimationAdded(anim_id)) = mgr.read_result() {
        var_anim_id = anim_id;
    }

    let mut keep_running = true;
    while keep_running {
        if let Some(key) = mgr.read_key() {
            match key {
                Key::Zero => mgr.set_graphic(graphic_id, start_frame, true),
                Key::One => mgr.set_graphic(graphic_id, start_frame + 1, true),
                Key::A => mgr.start_animation(graphic_id, anim_id),
                Key::ShiftA => mgr.start_animation(graphic_id, fast_anim_id),
                Key::P => mgr.pause_animation(graphic_id),
                Key::CtrlP => mgr.pause_animation(graphic_id),
                Key::ShiftP => mgr.pause_animation_on_frame(graphic_id, start_frame),
                Key::CtrlA => mgr.start_animation(graphic_id, var_anim_id),
                Key::S | Key::ShiftS => mgr.stop_animation(graphic_id),
                Key::Q | Key::ShiftQ => {
                    keep_running = false;
                }
                _ => continue,
            }
        }
    }

    mgr.terminate();
}
source

pub fn start_animation(&mut self, anim_id: usize, when: Timestamp)

Start an animation.

source

pub fn stop_animation(&mut self)

Stop an animation.

source

pub fn pause_animation(&mut self, anim_id: usize, when: Timestamp)

Pause an animation.

source

pub fn pause_animation_on_frame(&mut self, anim_id: usize, frame_id: usize)

Pause an animation when it is set to a particular frame.

source

pub fn restart_animation(&mut self, anim_id: usize, when: Timestamp)

Start an animation from beginning.

source

pub fn enqueue_animation(&mut self, anim_id: usize, when: Timestamp)

Start selected animation after current one ends.

source

pub fn get_pixels(&self, offset: (isize, isize)) -> Vec<Pixel>

Get current frame of a graphic in a vector of pixels format including their current on screen placement.

source

pub fn get_glyphs(&self) -> Vec<Glyph>

Get current frame of a graphic in a vector of glyphs format.

source

pub fn get_frame(&self, frame_id: usize) -> Result<Vec<Glyph>, AnimError>

Get requested frame of a graphic in a vector of glyphs format.

source

pub fn set_glyph( &mut self, glyph: Glyph, col: usize, row: usize, offset: (isize, isize), ) -> Vec<Pixel>

Set new value of selected glyph in current frame.

source

pub fn get_glyph(&self, col: usize, row: usize) -> Option<Glyph>

Get value of particular glyph in current frame.

source

pub fn set_current_frame_color(&mut self, color: Color)

Set color of all glyphs in current frame to specific value.

source

pub fn set_current_frame_background(&mut self, color: Color)

Set background of all glyphs in current frame to specific value.

source

pub fn set_current_frame_style(&mut self, style: Glyph)

Set style of all glyphs in current frame to specific value.

source

pub fn set_frame( &mut self, frame_id: &usize, offset: (isize, isize), force: bool, ) -> Vec<Pixel>

Set current frame to specific value, returning a vector of changed pixels.

Trait Implementations§

source§

impl Debug for Graphic

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.