Skip to main content

repose_core/
input.rs

1use crate::Vec2;
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
4pub struct PointerId(pub u64);
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum PointerKind {
8    Mouse,
9    Touch,
10    Pen,
11}
12
13#[derive(Clone, Copy, Debug)]
14pub enum PointerButton {
15    Primary,   // Left mouse, touch
16    Secondary, // Right mouse
17    Tertiary,  // Middle mouse
18}
19
20#[derive(Clone, Copy, Debug)]
21pub enum PointerEventKind {
22    Down(PointerButton),
23    Up(PointerButton),
24    Move,
25    Cancel,
26    Enter,
27    Leave,
28}
29
30#[derive(Clone, Debug)]
31pub struct PointerEvent {
32    pub id: PointerId,
33    pub kind: PointerKind,
34    pub event: PointerEventKind,
35    pub position: Vec2,
36    pub pressure: f32,
37    pub modifiers: Modifiers,
38}
39
40#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
41pub struct Modifiers {
42    pub shift: bool,
43    pub ctrl: bool,
44    pub alt: bool,
45    pub meta: bool,    // Cmd on Mac, Win key on Windows
46    pub command: bool, // egui like (Cmd on macOS, Ctrl elsewhere)
47}
48
49#[derive(Clone, Debug, PartialEq, Eq, Hash)]
50pub enum Key {
51    Character(char),
52    Enter,
53    Tab,
54    Backspace,
55    Delete,
56    Escape,
57    ArrowLeft,
58    ArrowRight,
59    ArrowUp,
60    ArrowDown,
61    Home,
62    End,
63    PageUp,
64    PageDown,
65    Space,
66    F(u8), // F1-F12
67    Unknown,
68}
69
70#[derive(Clone, Debug)]
71pub struct KeyEvent {
72    pub key: Key,
73    pub modifiers: Modifiers,
74    pub is_repeat: bool,
75}
76
77#[derive(Clone, Debug)]
78pub struct TextInputEvent {
79    pub text: String,
80}
81
82#[derive(Clone, Debug)]
83pub enum ImeEvent {
84    /// IME composition started
85    Start,
86    /// Composition text updated
87    Update {
88        text: String,
89        cursor: Option<(usize, usize)>, // (start, end) of composition range
90    },
91    /// Composition committed (finalized)
92    Commit(String),
93    /// Composition cancelled
94    Cancel,
95}
96
97#[derive(Clone, Debug)]
98pub enum InputEvent {
99    Pointer(PointerEvent),
100    Key(KeyEvent),
101    Text(TextInputEvent),
102    Ime(ImeEvent),
103}