pub struct Timestamp(/* private fields */);Expand description
Time representation.
Implementations§
source§impl Timestamp
impl Timestamp
sourcepub fn now() -> Self
pub fn now() -> Self
Create a new timestamp representing it’s moment of creation.
Examples found in repository?
examples/example_5.rs (line 439)
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
examples/example_2.rs (line 51)
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();
}sourcepub fn new(sec: u64, msec: u32) -> Self
pub fn new(sec: u64, msec: u32) -> Self
Create a new timestamp representing a moment in future.
Examples found in repository?
examples/example_5.rs (line 438)
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
examples/example_2.rs (line 46)
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();
}Trait Implementations§
source§impl AddAssign for Timestamp
impl AddAssign for Timestamp
source§fn add_assign(&mut self, o: Self)
fn add_assign(&mut self, o: Self)
Performs the
+= operation. Read moresource§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
impl Copy for Timestamp
Auto Trait Implementations§
impl Freeze for Timestamp
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)