Skip to main content

flatland_client_ui/
input.rs

1//! Engine-neutral keyboard and pointer events.
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum UiKeyEventKind {
5    Press,
6    Release,
7    Repeat,
8}
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
11pub struct UiKeyModifiers {
12    pub shift: bool,
13    pub control: bool,
14    pub alt: bool,
15}
16
17impl UiKeyModifiers {
18    pub fn contains_shift(self) -> bool {
19        self.shift
20    }
21
22    pub fn contains_control(self) -> bool {
23        self.control
24    }
25
26    pub fn contains_alt(self) -> bool {
27        self.alt
28    }
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub enum UiKeyCode {
33    Char(char),
34    Up,
35    Down,
36    Left,
37    Right,
38    Esc,
39    Enter,
40    Tab,
41    BackTab,
42    Delete,
43    Backspace,
44    Space,
45    ShiftLeft,
46    ShiftRight,
47}
48
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub struct UiKeyEvent {
51    pub kind: UiKeyEventKind,
52    pub code: UiKeyCode,
53    pub modifiers: UiKeyModifiers,
54}
55
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57pub enum UiMouseButton {
58    Left,
59    Right,
60    Middle,
61}
62
63#[derive(Debug, Clone, Copy, PartialEq)]
64pub enum UiPointerEvent {
65    Move {
66        x: f32,
67        y: f32,
68    },
69    Click {
70        x: f32,
71        y: f32,
72        button: UiMouseButton,
73        /// True when Shift was held at click time (T2 combat targeting).
74        shift: bool,
75    },
76    Scroll {
77        x: f32,
78        y: f32,
79        delta: f32,
80    },
81}