1#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
5pub struct ClickEvent {
6 pub x: i16,
7 pub y: i16,
8}
9
10#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
12pub enum PointerButton {
13 #[default]
15 Left,
16 Right,
18 Middle,
20}
21
22#[repr(u8)]
24#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
25pub enum PointerKind {
26 #[default]
28 Touch = 0,
29 Mouse = 1,
31 Pen = 2,
33}
34
35#[repr(u8)]
37#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
38pub enum CursorShape {
39 #[default]
41 Default = 0,
42 Pointer = 1,
44 Text = 2,
46 Grab = 3,
48 Grabbing = 4,
50 NotAllowed = 5,
52 Progress = 6,
54 Move = 7,
56 Crosshair = 8,
58 ResizeNS = 9,
60 ResizeEW = 10,
62 ResizeNWSE = 11,
64 ResizeNESW = 12,
66}
67
68impl CursorShape {
69 #[inline(always)]
71 pub const fn as_css_str(self) -> &'static str {
72 match self {
73 Self::Default => "default",
74 Self::Pointer => "pointer",
75 Self::Text => "text",
76 Self::Grab => "grab",
77 Self::Grabbing => "grabbing",
78 Self::NotAllowed => "not-allowed",
79 Self::Progress => "progress",
80 Self::Move => "move",
81 Self::Crosshair => "crosshair",
82 Self::ResizeNS => "ns-resize",
83 Self::ResizeEW => "ew-resize",
84 Self::ResizeNWSE => "nwse-resize",
85 Self::ResizeNESW => "nesw-resize",
86 }
87 }
88}
89
90#[derive(Copy, Clone, PartialEq, Eq, Debug)]
92pub enum SwipeDir {
93 Left,
95 Right,
97 Up,
99 Down,
101}
102
103#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
105pub struct DragEvent {
106 pub x: i16,
108 pub y: i16,
110 pub local_x: i16,
112 pub local_y: i16,
114 pub width: i16,
116 pub height: i16,
118 pub delta_x: i16,
120 pub delta_y: i16,
122}
123
124#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
126pub enum KeyCode {
127 Tab,
129 BackTab,
131 Up,
133 Down,
135 Left,
137 Right,
139 Enter,
141 Space,
143 Escape,
145 Backspace,
147 Delete,
149 Home,
151 End,
153 PageUp,
155 PageDown,
157 Char(char),
159}
160
161#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Default)]
163pub struct KeyModifiers(pub u8);
164
165impl KeyModifiers {
166 pub const NONE: Self = Self(0);
168 pub const SHIFT: Self = Self(1 << 0);
170 pub const CTRL: Self = Self(1 << 1);
172 pub const ALT: Self = Self(1 << 2);
174 pub const LOGO: Self = Self(1 << 3);
176
177 #[inline(always)]
179 pub const fn is_empty(self) -> bool {
180 self.0 == 0
181 }
182
183 #[inline(always)]
185 pub const fn shift(self) -> bool {
186 (self.0 & Self::SHIFT.0) != 0
187 }
188
189 #[inline(always)]
191 pub const fn ctrl(self) -> bool {
192 (self.0 & Self::CTRL.0) != 0
193 }
194
195 #[inline(always)]
197 pub const fn alt(self) -> bool {
198 (self.0 & Self::ALT.0) != 0
199 }
200
201 #[inline(always)]
203 pub const fn logo(self) -> bool {
204 (self.0 & Self::LOGO.0) != 0
205 }
206
207 #[inline(always)]
209 pub const fn union(self, other: Self) -> Self {
210 Self(self.0 | other.0)
211 }
212
213 #[inline(always)]
215 pub const fn with(self, other: Self) -> Self {
216 Self(self.0 | other.0)
217 }
218
219 #[inline(always)]
221 pub const fn without(self, other: Self) -> Self {
222 Self(self.0 & !other.0)
223 }
224
225 #[inline(always)]
227 pub const fn has_shortcut_modifier(self) -> bool {
228 (self.0 & (Self::LOGO.0 | Self::ALT.0 | Self::CTRL.0)) != 0
229 }
230}
231
232#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
234pub struct SafeAreaInsets {
235 pub top: i16,
236 pub right: i16,
237 pub bottom: i16,
238 pub left: i16,
239}
240
241impl SafeAreaInsets {
242 pub const ZERO: Self = Self {
244 top: 0,
245 right: 0,
246 bottom: 0,
247 left: 0,
248 };
249
250 #[inline(always)]
252 pub const fn new(top: i16, right: i16, bottom: i16, left: i16) -> Self {
253 Self {
254 top,
255 right,
256 bottom,
257 left,
258 }
259 }
260
261 #[inline(always)]
263 pub const fn phone_portrait() -> Self {
264 Self {
265 top: 44,
266 right: 0,
267 bottom: 34,
268 left: 0,
269 }
270 }
271
272 #[inline(always)]
274 pub const fn phone_landscape() -> Self {
275 Self {
276 top: 0,
277 right: 44,
278 bottom: 21,
279 left: 44,
280 }
281 }
282
283 #[inline(always)]
285 pub const fn android_portrait() -> Self {
286 Self {
287 top: 48,
288 right: 0,
289 bottom: 34,
290 left: 0,
291 }
292 }
293
294 #[inline(always)]
296 pub const fn android_landscape() -> Self {
297 Self {
298 top: 0,
299 right: 0,
300 bottom: 24,
301 left: 48,
302 }
303 }
304
305 #[inline(always)]
307 pub const fn ios_portrait() -> Self {
308 Self {
309 top: 59,
310 right: 0,
311 bottom: 34,
312 left: 0,
313 }
314 }
315
316 #[inline(always)]
318 pub const fn ios_landscape() -> Self {
319 Self {
320 top: 0,
321 right: 59,
322 bottom: 21,
323 left: 59,
324 }
325 }
326
327 #[inline(always)]
329 pub const fn harmony_portrait() -> Self {
330 Self {
331 top: 38,
332 right: 0,
333 bottom: 28,
334 left: 0,
335 }
336 }
337
338 #[inline(always)]
340 pub const fn harmony_landscape() -> Self {
341 Self {
342 top: 0,
343 right: 38,
344 bottom: 20,
345 left: 38,
346 }
347 }
348}
349
350#[derive(Copy, Clone, PartialEq, Eq, Debug)]
354pub struct ImePreedit {
355 pub buf: [u8; 64],
356 pub len: u8,
357 pub cursor_start: u8,
358 pub cursor_end: u8,
359 pub has_cursor: bool,
360}
361
362impl Default for ImePreedit {
363 #[inline(always)]
364 fn default() -> Self {
365 Self::empty()
366 }
367}
368
369impl ImePreedit {
370 #[inline(always)]
372 pub const fn empty() -> Self {
373 Self {
374 buf: [0; 64],
375 len: 0,
376 cursor_start: 0,
377 cursor_end: 0,
378 has_cursor: false,
379 }
380 }
381
382 pub fn from_str(text: &str, cursor: Option<(usize, usize)>) -> Self {
384 let mut out = Self::empty();
385 let bytes = text.as_bytes();
386 let mut copy_len = bytes.len().min(64);
387 while copy_len > 0 && !text.is_char_boundary(copy_len) {
388 copy_len -= 1;
389 }
390 out.buf[..copy_len].copy_from_slice(&bytes[..copy_len]);
391 out.len = copy_len as u8;
392 if let Some((s, e)) = cursor {
393 out.cursor_start = s.min(copy_len) as u8;
394 out.cursor_end = e.min(copy_len) as u8;
395 out.has_cursor = true;
396 }
397 out
398 }
399
400 #[inline]
402 pub fn as_str(&self) -> &str {
403 let n = (self.len as usize).min(64);
404 core::str::from_utf8(&self.buf[..n]).unwrap_or("")
405 }
406
407 #[inline(always)]
409 pub const fn is_empty(&self) -> bool {
410 self.len == 0
411 }
412
413 #[inline(always)]
415 pub const fn cursor(&self) -> Option<(usize, usize)> {
416 if self.has_cursor {
417 Some((self.cursor_start as usize, self.cursor_end as usize))
418 } else {
419 None
420 }
421 }
422}
423
424#[derive(Copy, Clone, PartialEq, Eq, Debug)]
426pub enum InputEvent {
427 PointerDown { x: i16, y: i16 },
429 PointerMove { x: i16, y: i16 },
431 PointerUp { x: i16, y: i16 },
433 PointerSecondaryDown { x: i16, y: i16 },
435 PointerSecondaryUp { x: i16, y: i16 },
437 PointerLeave,
439 PointerCancel,
441 PointerKindChanged(PointerKind),
443 Scroll {
445 x: i16,
446 y: i16,
447 delta_y: i16,
448 },
449 ScrollX {
451 x: i16,
452 y: i16,
453 delta_x: i16,
454 },
455 KeyDown(KeyCode),
457 KeyUp(KeyCode),
459 ModifiersChanged(KeyModifiers),
461 Backspace,
463 Delete,
465 TextCommit(char),
467 ImeEnabled,
469 ImeDisabled,
471 ImePreedit(ImePreedit),
473 NavigateBack,
475 SafeAreaChanged(SafeAreaInsets),
477 KeyboardInsetChanged(i16),
479 Pinch {
481 x: i16,
482 y: i16,
483 delta_scale_x1000: i16,
484 },
485 Rotate {
487 x: i16,
488 y: i16,
489 delta_deg10: i16,
490 },
491 ScrollPixel {
493 x: i16,
494 y: i16,
495 dx: i16,
496 dy: i16,
497 },
498 FileHovered { x: i16, y: i16 },
500 FileDropped { x: i16, y: i16 },
502 FileHoverCancelled,
504 SystemThemeChanged { dark: bool },
506}
507
508#[repr(u8)]
510#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
511pub enum EventPhase {
512 Capture = 0,
513 #[default]
514 Target = 1,
515 Bubble = 2,
516}
517
518#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
520pub struct DragPayload {
521 pub kind_tag: u32,
523 pub payload_id: u64,
525 pub source_id: u32,
527}
528