You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-firmware/core/embed/rust/src/ui/demo/anim_timer.rs

44 lines
807 B

use crate::time;
pub struct AnimTimer {
base: Option<time::Instant>,
limit: Option<time::Duration>,
}
impl AnimTimer {
pub fn new() -> Self {
Self {
base: None,
limit: None,
}
}
pub fn reset(&mut self) {
self.base = None;
}
pub fn start(&mut self) {
self.base = Some(time::Instant::now());
}
pub fn stop(&mut self) {
self.base = None;
}
pub fn is_running(&self) -> bool {
self.base.is_some()
}
pub fn elapsed(&self) -> f32 {
if let Some(t) = self.base {
time::Instant::now()
.checked_duration_since(t)
.unwrap()
.to_millis() as f32
/ 1000.0
} else {
0.0
}
}
}