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)]
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}
47
48#[derive(Clone, Debug)]
49pub enum Key {
50    Character(char),
51    Enter,
52    Tab,
53    Backspace,
54    Delete,
55    Escape,
56    ArrowLeft,
57    ArrowRight,
58    ArrowUp,
59    ArrowDown,
60    Home,
61    End,
62    PageUp,
63    PageDown,
64    Space,
65    F(u8), // F1-F12
66}
67
68#[derive(Clone, Debug)]
69pub struct KeyEvent {
70    pub key: Key,
71    pub modifiers: Modifiers,
72    pub is_repeat: bool,
73}
74
75#[derive(Clone, Debug)]
76pub struct TextInputEvent {
77    pub text: String,
78}
79
80#[derive(Clone, Debug)]
81pub enum ImeEvent {
82    /// IME composition started
83    Start,
84    /// Composition text updated
85    Update {
86        text: String,
87        cursor: Option<(usize, usize)>, // (start, end) of composition range
88    },
89    /// Composition committed (finalized)
90    Commit(String),
91    /// Composition cancelled
92    Cancel,
93}
94
95#[derive(Clone, Debug)]
96pub enum InputEvent {
97    Pointer(PointerEvent),
98    Key(KeyEvent),
99    Text(TextInputEvent),
100    Ime(ImeEvent),
101}