use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct BackGesture {
pub active: bool,
pub progress: f32,
}
static ACTIVE: AtomicBool = AtomicBool::new(false);
static PROGRESS_BITS: AtomicU32 = AtomicU32::new(0);
pub fn gesture() -> BackGesture {
BackGesture {
active: active(),
progress: progress(),
}
}
pub fn active() -> bool {
ACTIVE.load(Ordering::Relaxed)
}
pub fn progress() -> f32 {
if active() {
f32::from_bits(PROGRESS_BITS.load(Ordering::Relaxed))
} else {
0.0
}
}
pub fn set_gesture(active: bool, progress: f32) {
let progress = if active && progress.is_finite() {
progress.clamp(0.0, 1.0)
} else {
0.0
};
let was_active = ACTIVE.swap(active, Ordering::Relaxed);
let old_progress = PROGRESS_BITS.swap(progress.to_bits(), Ordering::Relaxed);
if was_active != active || old_progress != progress.to_bits() {
crate::request_frame();
}
}