use std::cell::RefCell;
#[cfg(all(not(target_arch = "wasm32"), feature = "desktop"))]
thread_local! {
static REPAINT_CALLBACK: RefCell<Option<Box<dyn Fn()>>> = RefCell::new(None);
}
#[cfg(all(not(target_arch = "wasm32"), feature = "desktop"))]
pub fn set_repaint_callback<F: Fn() + 'static>(callback: F) {
REPAINT_CALLBACK.with(|rc| {
*rc.borrow_mut() = Some(Box::new(callback));
});
}
#[cfg(all(not(target_arch = "wasm32"), feature = "desktop"))]
pub fn trigger_repaint() {
REPAINT_CALLBACK.with(|rc| {
if let Some(callback) = rc.borrow().as_ref() {
callback();
}
});
}
#[cfg(all(not(target_arch = "wasm32"), feature = "desktop"))]
pub fn clear_repaint_callback() {
REPAINT_CALLBACK.with(|rc| {
*rc.borrow_mut() = None;
});
}