use super::EventControl;
use crate::core::NodeId;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TouchPhase {
Start,
Move,
End,
Cancel,
}
#[derive(Debug, Clone)]
pub struct TouchEvent {
pub id: u64,
pub phase: TouchPhase,
pub x: f32,
pub y: f32,
pub force: Option<f32>,
pub target_id: NodeId,
pub(crate) control: EventControl,
}
#[derive(Debug, Clone)]
pub struct LongPressEvent {
pub x: f32,
pub y: f32,
pub target_id: NodeId,
pub(crate) control: EventControl,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GesturePhase {
Start,
Change,
End,
}
#[derive(Debug, Clone)]
pub struct PinchEvent {
pub phase: GesturePhase,
pub scale: f32,
pub delta: f32,
pub x: f32,
pub y: f32,
pub target_id: NodeId,
pub(crate) control: EventControl,
}
#[derive(Debug, Clone)]
pub struct RotateEvent {
pub phase: GesturePhase,
pub rotation: f32,
pub delta: f32,
pub x: f32,
pub y: f32,
pub target_id: NodeId,
pub(crate) control: EventControl,
}
#[derive(Debug, Clone)]
pub struct TapEvent {
pub fingers: u32,
pub count: u32,
pub x: f32,
pub y: f32,
pub target_id: NodeId,
pub(crate) control: EventControl,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SwipeDirection {
Left,
Right,
Up,
Down,
}
#[derive(Debug, Clone)]
pub struct SwipeEvent {
pub direction: SwipeDirection,
pub fingers: u32,
pub velocity: f32,
pub x: f32,
pub y: f32,
pub target_id: NodeId,
pub(crate) control: EventControl,
}
#[derive(Debug, Clone)]
pub struct PanEvent {
pub phase: GesturePhase,
pub fingers: u32,
pub translation_x: f32,
pub translation_y: f32,
pub delta_x: f32,
pub delta_y: f32,
pub velocity_x: f32,
pub velocity_y: f32,
pub x: f32,
pub y: f32,
pub target_id: NodeId,
pub(crate) control: EventControl,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ScreenEdge {
Left,
Right,
Top,
Bottom,
}
#[derive(Debug, Clone)]
pub struct EdgePanEvent {
pub phase: GesturePhase,
pub edge: ScreenEdge,
pub translation: f32,
pub velocity: f32,
pub x: f32,
pub y: f32,
pub target_id: NodeId,
pub(crate) control: EventControl,
}
macro_rules! event_control {
($event:ty) => {
impl $event {
pub fn prevent_default(&self) {
self.control.prevent_default();
}
pub fn default_prevented(&self) -> bool {
self.control.default_prevented()
}
pub fn stop_propagation(&self) {
self.control.stop_propagation();
}
pub fn propagation_stopped(&self) -> bool {
self.control.propagation_stopped()
}
pub fn stop_immediate_propagation(&self) {
self.control.stop_immediate_propagation();
}
pub fn immediate_propagation_stopped(&self) -> bool {
self.control.immediate_propagation_stopped()
}
}
};
}
event_control!(TouchEvent);
event_control!(LongPressEvent);
event_control!(PinchEvent);
event_control!(RotateEvent);
event_control!(TapEvent);
event_control!(SwipeEvent);
event_control!(PanEvent);
event_control!(EdgePanEvent);