nuit_core/event/gesture/
drag.rs

1use serde::{Deserialize, Serialize};
2
3use crate::Vec2;
4
5/// An event emitted during a drag gesture.
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub struct DragEvent {
9    kind: DragEventKind,
10    start_location: Vec2<f64>,
11    location: Vec2<f64>,
12}
13
14impl DragEvent {
15    /// The kind of the drag event.
16    pub fn kind(&self) -> DragEventKind {
17        self.kind
18    }
19
20    /// The starting point of the drag.
21    pub fn start_location(&self) -> Vec2<f64> {
22        self.start_location
23    }
24
25    /// The current point of the drag.
26    pub fn location(&self) -> Vec2<f64> {
27        self.location
28    }
29
30    /// The distance moved during the gesture.
31    pub fn translation(&self) -> Vec2<f64> {
32        self.location - self.start_location
33    }
34}
35
36#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
37#[serde(rename_all = "camelCase")]
38pub enum DragEventKind {
39    Updated,
40    Ended,
41}