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    KeyUp {
 17        keystroke: Keystroke,
 18        input: Option<String>,
 19    },
 20    ModifiersChanged {
 21        ctrl: bool,
 22        alt: bool,
 23        shift: bool,
 24        cmd: bool,
 25    },
 26    ScrollWheel {
 27        position: Vector2F,
 28        delta: Vector2F,
 29        precise: bool,
 30    },
 31    LeftMouseDown {
 32        position: Vector2F,
 33        ctrl: bool,
 34        alt: bool,
 35        shift: bool,
 36        cmd: bool,
 37        click_count: usize,
 38    },
 39    LeftMouseUp {
 40        position: Vector2F,
 41        click_count: usize,
 42    },
 43    LeftMouseDragged {
 44        position: Vector2F,
 45        ctrl: bool,
 46        alt: bool,
 47        shift: bool,
 48        cmd: bool,
 49    },
 50    RightMouseDown {
 51        position: Vector2F,
 52        ctrl: bool,
 53        alt: bool,
 54        shift: bool,
 55        cmd: bool,
 56        click_count: usize,
 57    },
 58    RightMouseUp {
 59        position: Vector2F,
 60        click_count: usize,
 61    },
 62    NavigateMouseDown {
 63        position: Vector2F,
 64        direction: NavigationDirection,
 65        ctrl: bool,
 66        alt: bool,
 67        shift: bool,
 68        cmd: bool,
 69        click_count: usize,
 70    },
 71    NavigateMouseUp {
 72        position: Vector2F,
 73        direction: NavigationDirection,
 74    },
 75    MouseMoved {
 76        position: Vector2F,
 77        left_mouse_down: bool,
 78        ctrl: bool,
 79        cmd: bool,
 80        alt: bool,
 81        shift: bool,
 82    },
 83}
 84
 85impl Event {
 86    pub fn position(&self) -> Option<Vector2F> {
 87        match self {
 88            Event::KeyDown { .. } => None,
 89            Event::KeyUp { .. } => None,
 90            Event::ModifiersChanged { .. } => None,
 91            Event::ScrollWheel { position, .. }
 92            | Event::LeftMouseDown { position, .. }
 93            | Event::LeftMouseUp { position, .. }
 94            | Event::LeftMouseDragged { position, .. }
 95            | Event::RightMouseDown { position, .. }
 96            | Event::RightMouseUp { position, .. }
 97            | Event::NavigateMouseDown { position, .. }
 98            | Event::NavigateMouseUp { position, .. }
 99            | Event::MouseMoved { position, .. } => Some(*position),
100        }
101    }
102}