event.rs

 1use crate::{geometry::vector::Vector2F, keymap::Keystroke};
 2
 3#[derive(Copy, Clone, Debug)]
 4pub enum NavigationDirection {
 5    Back,
 6    Forward,
 7}
 8
 9#[derive(Clone, Debug)]
10pub enum Event {
11    KeyDown {
12        keystroke: Keystroke,
13        input: Option<String>,
14        is_held: bool,
15    },
16    ScrollWheel {
17        position: Vector2F,
18        delta: Vector2F,
19        precise: bool,
20    },
21    LeftMouseDown {
22        position: Vector2F,
23        ctrl: bool,
24        alt: bool,
25        shift: bool,
26        cmd: bool,
27        click_count: usize,
28    },
29    LeftMouseUp {
30        position: Vector2F,
31        click_count: usize,
32    },
33    LeftMouseDragged {
34        position: Vector2F,
35    },
36    RightMouseDown {
37        position: Vector2F,
38        ctrl: bool,
39        alt: bool,
40        shift: bool,
41        cmd: bool,
42        click_count: usize,
43    },
44    RightMouseUp {
45        position: Vector2F,
46    },
47    NavigateMouseDown {
48        position: Vector2F,
49        direction: NavigationDirection,
50        ctrl: bool,
51        alt: bool,
52        shift: bool,
53        cmd: bool,
54        click_count: usize,
55    },
56    NavigateMouseUp {
57        position: Vector2F,
58        direction: NavigationDirection,
59    },
60    MouseMoved {
61        position: Vector2F,
62        left_mouse_down: bool,
63    },
64}
65
66impl Event {
67    pub fn position(&self) -> Option<Vector2F> {
68        match self {
69            Event::KeyDown { .. } => None,
70            Event::ScrollWheel { position, .. }
71            | Event::LeftMouseDown { position, .. }
72            | Event::LeftMouseUp { position, .. }
73            | Event::LeftMouseDragged { position }
74            | Event::RightMouseDown { position, .. }
75            | Event::RightMouseUp { position }
76            | Event::NavigateMouseDown { position, .. }
77            | Event::NavigateMouseUp { position, .. }
78            | Event::MouseMoved { position, .. } => Some(*position),
79        }
80    }
81}