use nuit_derive::Bind;
use crate::{Context, Gesture, GestureEvent, GestureNode, IdPath};
#[derive(Bind)]
pub struct TapGesture<F> {
count: usize,
action: F,
}
impl<F> TapGesture<F> where F: Fn() {
pub const fn new(count: usize, action: F) -> Self {
Self { count, action }
}
pub const fn new_single(action: F) -> Self {
Self::new(1, action)
}
}
impl<F> Gesture for TapGesture<F> where F: Fn() {
fn fire(&self, event: &GestureEvent, event_path: &IdPath, _context: &Context) {
assert!(event_path.is_root());
if let GestureEvent::Tap {} = event {
(self.action)();
} else {
eprintln!("Warning: Ignoring non-tap gesture event {:?} targeted to TapGesture at {:?}", event, event_path)
}
}
fn render(&self, _context: &Context) -> GestureNode {
GestureNode::Tap { count: self.count }
}
}