ravenrs_core/event.rs
1use crate::Point;
2
3/// Platform-neutral input event, already converted to logical pixels.
4#[derive(Clone, Debug, PartialEq)]
5#[non_exhaustive]
6#[cfg_attr(feature = "live", ravenrs_live::expose(part = "variants"))]
7pub enum Event {
8 /// The pointer moved without a button change.
9 PointerMove {
10 /// Pointer position in logical pixels.
11 position: Point,
12 },
13 /// A pointer button was pressed.
14 PointerDown {
15 /// Pointer position in logical pixels.
16 position: Point,
17 /// Button that was pressed.
18 button: PointerButton,
19 },
20 /// A pointer button was released.
21 PointerUp {
22 /// Pointer position in logical pixels.
23 position: Point,
24 /// Button that was released.
25 button: PointerButton,
26 },
27 /// A second primary click in quick succession, sent after its `PointerUp`.
28 DoubleClick {
29 /// Pointer position in logical pixels.
30 position: Point,
31 },
32 /// The pointer left the window or canvas.
33 PointerLeave,
34 /// Wheel or trackpad scrolling, in logical pixels. Positive `delta.y` means
35 /// the user scrolled up (content should move down), as on every platform.
36 Scroll {
37 /// Pointer position in logical pixels.
38 position: Point,
39 /// Scroll distance in logical pixels on each axis.
40 delta: Point,
41 },
42 /// A key was pressed (including auto-repeat).
43 KeyDown {
44 /// Key that was pressed.
45 key: Key,
46 /// Modifier keys held at the time of the press.
47 modifiers: Modifiers,
48 },
49 /// A key was released.
50 KeyUp {
51 /// Key that was released.
52 key: Key,
53 /// Modifier keys held at the time of the release.
54 modifiers: Modifiers,
55 },
56 /// The window or canvas lost keyboard focus.
57 FocusLost,
58 /// A pinch on a trackpad or Ctrl with the wheel: a zoom gesture.
59 Pinch {
60 /// Pointer position in logical pixels.
61 position: Point,
62 /// How much larger the user asked for, relative to now: 0.02 is 2% larger,
63 /// and a negative value is smaller.
64 delta: f32,
65 },
66}
67
68/// Mouse button or equivalent touch/pen action.
69#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
70#[non_exhaustive]
71#[cfg_attr(feature = "live", ravenrs_live::expose(part = "variants"))]
72pub enum PointerButton {
73 /// Left mouse button, or a primary touch/pen contact.
74 Primary,
75 /// Right mouse button (context menu).
76 Secondary,
77 /// Middle mouse button or wheel click.
78 Auxiliary,
79 /// Any other button, by platform index.
80 Other(u16),
81}
82
83/// The subset of keys the framework itself reacts to; everything else is
84/// forwarded as `Character` or `Other` for widgets to interpret.
85#[derive(Clone, Debug, PartialEq, Eq, Hash)]
86#[non_exhaustive]
87#[cfg_attr(feature = "live", ravenrs_live::expose(part = "variants"))]
88pub enum Key {
89 /// Enter or Return.
90 Enter,
91 /// Space bar.
92 Space,
93 /// Tab (focus traversal).
94 Tab,
95 /// Escape.
96 Escape,
97 /// Backspace (delete before the caret).
98 Backspace,
99 /// Forward delete (delete after the caret).
100 Delete,
101 /// Home (start of line).
102 Home,
103 /// End (end of line).
104 End,
105 /// Left arrow.
106 ArrowLeft,
107 /// Right arrow.
108 ArrowRight,
109 /// Up arrow.
110 ArrowUp,
111 /// Down arrow.
112 ArrowDown,
113 /// Page Up.
114 PageUp,
115 /// Page Down.
116 PageDown,
117 /// Text produced by the key, already composed with modifiers and layout.
118 Character(String),
119 /// Any other named key, by its platform name.
120 Other(String),
121}
122
123/// Modifier keys held during a key event.
124#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
125#[cfg_attr(feature = "live", ravenrs_live::expose(part = "fields"))]
126pub struct Modifiers {
127 /// Shift key held.
128 pub shift: bool,
129 /// Control key held.
130 pub ctrl: bool,
131 /// Alt / Option key held.
132 pub alt: bool,
133 /// Meta key held (Command on macOS, Windows key elsewhere).
134 pub meta: bool,
135}
136
137/// Cursor the UI asks the platform to show.
138#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
139#[non_exhaustive]
140#[cfg_attr(feature = "live", ravenrs_live::expose(part = "variants"))]
141pub enum CursorIcon {
142 /// Platform default arrow.
143 #[default]
144 Default,
145 /// Hand cursor for clickable elements.
146 Pointer,
147 /// I-beam cursor for editable text.
148 Text,
149 /// Horizontal resize, e.g. a column edge.
150 ColResize,
151 /// Vertical resize, e.g. a horizontal splitter bar.
152 RowResize,
153}