use std::fmt::Debug;
use r3bl_redux::*;
use tokio::task::JoinHandle;
#[derive(Debug, Default)]
pub struct Animator {
pub animation_task_handle: Option<JoinHandle<()>>,
}
impl Animator {
pub fn start<S, A>(
&mut self,
shared_store: &SharedStore<S, A>,
start_animator_task_fn: fn(&SharedStore<S, A>) -> JoinHandle<()>,
) where
S: Default + Clone + PartialEq + Debug + Sync + Send,
A: Debug + Default + Clone + Sync + Send,
{
if self.is_animation_started() {
return;
}
self.animation_task_handle = Some(start_animator_task_fn(shared_store));
}
pub fn is_animation_started(&self) -> bool {
matches!(&self.animation_task_handle, Some(_handle))
}
pub fn stop(&mut self) {
if let Some(handle) = &self.animation_task_handle {
handle.abort();
}
self.animation_task_handle = None;
}
}