1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! Input as a view reads it, from any platform: a browser canvas translates its events into these.
/// A pointer, wheel, or key event, with points in CSS pixels from the view's top left.
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Input {
/// A pointer pressed.
Down {
/// Tells pointers apart while several are down.
pointer: u32,
/// Where.
point: [f32; 2],
/// Which button.
button: Button,
/// Keys held.
modifiers: Modifiers,
/// What pressed: a finger's picks reach farther.
device: Device,
},
/// A pointer moved.
Move {
/// Which pointer.
pointer: u32,
/// Where to.
point: [f32; 2],
/// Keys held.
modifiers: Modifiers,
/// What moved.
device: Device,
},
/// A pointer let go.
Up {
/// Which pointer.
pointer: u32,
/// Where.
point: [f32; 2],
/// Keys held.
modifiers: Modifiers,
},
/// The platform took a pointer away.
Cancel {
/// Which pointer.
pointer: u32,
},
/// The wheel turned: CSS pixels, positive down and right.
Wheel {
/// Where the pointer is.
point: [f32; 2],
/// How far.
delta: [f32; 2],
/// Keys held.
modifiers: Modifiers,
},
/// A key went down or up while the view had focus.
Key {
/// Which key.
key: Key,
/// Whether it went down.
down: bool,
/// Keys held.
modifiers: Modifiers,
},
/// The pointer left the view.
Leave,
}
/// A pointer button.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Button {
/// The main button: left, or a touch.
Primary,
/// The context button: right.
Secondary,
/// The middle button or wheel press.
Middle,
}
/// What the user acts with.
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, serde::Serialize, schemars::JsonSchema)]
#[serde(rename_all = "lowercase")]
pub enum Device {
/// A mouse or a trackpad.
#[default]
Mouse,
/// A pen.
Pen,
/// A finger: picks reach 8 CSS pixels farther.
Touch,
/// The keys.
Keyboard,
}
/// Keys held during an input.
#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, serde::Serialize, schemars::JsonSchema)]
pub struct Modifiers {
/// Shift.
pub shift: bool,
/// Control.
pub control: bool,
/// Alt or Option.
pub alt: bool,
/// Meta: Command or Windows.
pub meta: bool,
}
impl Modifiers {
/// Whether a click adds its row to the selection or takes it out: Shift, Control, or Meta held.
pub fn toggles(self) -> bool {
self.shift || self.control || self.meta
}
}
/// The keys a view answers.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Key {
/// Escape.
Escape,
/// Enter or Return.
Enter,
/// Delete.
Delete,
/// Backspace.
Backspace,
/// Home.
Home,
/// Tab.
Tab,
/// Space.
Space,
/// Plus or equals.
Plus,
/// Minus.
Minus,
/// Left arrow.
Left,
/// Right arrow.
Right,
/// Up arrow.
Up,
/// Down arrow.
Down,
/// The context menu key.
Menu,
/// Any other key.
Other,
}