feat(comp/timer): add shifting inital duration

This commit is contained in:
Dmitriy Pleshevskiy 2022-02-12 15:27:36 +03:00
parent 2c76d826c4
commit fdedff21dd
2 changed files with 6 additions and 2 deletions

View File

@ -64,9 +64,12 @@ where
let full_duration = self.full_duration(env);
match event {
Event::WindowConnected => {
self.start_time = Instant::now();
let shift_start_time = Duration::from_secs_f64(
env.try_get(env::TIMER_INIT_DURATION).unwrap_or_default(),
);
self.start_time = Instant::now() - shift_start_time;
self.render_timer_id = ctx.request_timer(TIMER_INTERVAL);
self.finish_timer_id = ctx.request_timer(duration);
self.finish_timer_id = ctx.request_timer(duration - shift_start_time);
data.reset(duration);
child.event(ctx, event, data, env);
}

View File

@ -1,6 +1,7 @@
use crate::state;
use druid::{Env, Key};
pub const TIMER_INIT_DURATION: Key<f64> = Key::new("hwt.env.comp.timer.init_duration");
pub const TIMER_DURATION: Key<f64> = Key::new("hwt.env.comp.timer.duration");
pub const TIMER_POSTPONE_DURATION: Key<f64> = Key::new("hwt.env.comp.timer.postpone_duration");
pub const TIMER_WAIT_DURATION: Key<f64> = Key::new("hwt.env.comp.timer.wait_duration");