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, Debug, Default)]
126pub struct WheelEvent {
127 pub x: i16,
129 pub y: i16,
131 pub local_x: i16,
133 pub local_y: i16,
135 pub width: i16,
137 pub height: i16,
139 pub delta_x: i16,
141 pub delta_y: i16,
143}
144
145#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
147pub struct PinchEvent {
148 pub x: i16,
150 pub y: i16,
152 pub local_x: i16,
154 pub local_y: i16,
156 pub width: i16,
158 pub height: i16,
160 pub delta_scale_x1000: i16,
162}
163
164#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
166pub enum KeyCode {
167 Tab,
169 BackTab,
171 Up,
173 Down,
175 Left,
177 Right,
179 Enter,
181 Space,
183 Escape,
185 Backspace,
187 Delete,
189 Home,
191 End,
193 PageUp,
195 PageDown,
197 Char(char),
199}
200
201#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Default)]
203pub struct KeyModifiers(pub u8);
204
205impl KeyModifiers {
206 pub const NONE: Self = Self(0);
208 pub const SHIFT: Self = Self(1 << 0);
210 pub const CTRL: Self = Self(1 << 1);
212 pub const ALT: Self = Self(1 << 2);
214 pub const LOGO: Self = Self(1 << 3);
216
217 #[inline(always)]
219 pub const fn is_empty(self) -> bool {
220 self.0 == 0
221 }
222
223 #[inline(always)]
225 pub const fn shift(self) -> bool {
226 (self.0 & Self::SHIFT.0) != 0
227 }
228
229 #[inline(always)]
231 pub const fn ctrl(self) -> bool {
232 (self.0 & Self::CTRL.0) != 0
233 }
234
235 #[inline(always)]
237 pub const fn alt(self) -> bool {
238 (self.0 & Self::ALT.0) != 0
239 }
240
241 #[inline(always)]
243 pub const fn logo(self) -> bool {
244 (self.0 & Self::LOGO.0) != 0
245 }
246
247 #[inline(always)]
249 pub const fn union(self, other: Self) -> Self {
250 Self(self.0 | other.0)
251 }
252
253 #[inline(always)]
255 pub const fn with(self, other: Self) -> Self {
256 Self(self.0 | other.0)
257 }
258
259 #[inline(always)]
261 pub const fn without(self, other: Self) -> Self {
262 Self(self.0 & !other.0)
263 }
264
265 #[inline(always)]
267 pub const fn has_shortcut_modifier(self) -> bool {
268 (self.0 & (Self::LOGO.0 | Self::ALT.0 | Self::CTRL.0)) != 0
269 }
270}
271
272#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
274pub struct SafeAreaInsets {
275 pub top: i16,
276 pub right: i16,
277 pub bottom: i16,
278 pub left: i16,
279}
280
281impl SafeAreaInsets {
282 pub const ZERO: Self = Self {
284 top: 0,
285 right: 0,
286 bottom: 0,
287 left: 0,
288 };
289
290 #[inline(always)]
292 pub const fn new(top: i16, right: i16, bottom: i16, left: i16) -> Self {
293 Self {
294 top,
295 right,
296 bottom,
297 left,
298 }
299 }
300
301 #[inline(always)]
303 pub const fn phone_portrait() -> Self {
304 Self {
305 top: 44,
306 right: 0,
307 bottom: 34,
308 left: 0,
309 }
310 }
311
312 #[inline(always)]
314 pub const fn phone_landscape() -> Self {
315 Self {
316 top: 0,
317 right: 44,
318 bottom: 21,
319 left: 44,
320 }
321 }
322
323 #[inline(always)]
325 pub const fn android_portrait() -> Self {
326 Self {
327 top: 48,
328 right: 0,
329 bottom: 34,
330 left: 0,
331 }
332 }
333
334 #[inline(always)]
336 pub const fn android_landscape() -> Self {
337 Self {
338 top: 0,
339 right: 0,
340 bottom: 24,
341 left: 48,
342 }
343 }
344
345 #[inline(always)]
347 pub const fn ios_portrait() -> Self {
348 Self {
349 top: 59,
350 right: 0,
351 bottom: 34,
352 left: 0,
353 }
354 }
355
356 #[inline(always)]
358 pub const fn ios_landscape() -> Self {
359 Self {
360 top: 0,
361 right: 59,
362 bottom: 21,
363 left: 59,
364 }
365 }
366
367 #[inline(always)]
369 pub const fn harmony_portrait() -> Self {
370 Self {
371 top: 38,
372 right: 0,
373 bottom: 28,
374 left: 0,
375 }
376 }
377
378 #[inline(always)]
380 pub const fn harmony_landscape() -> Self {
381 Self {
382 top: 0,
383 right: 38,
384 bottom: 20,
385 left: 38,
386 }
387 }
388}
389
390#[derive(Copy, Clone, PartialEq, Eq, Debug)]
394pub struct ImePreedit {
395 pub buf: [u8; 64],
396 pub len: u8,
397 pub cursor_start: u8,
398 pub cursor_end: u8,
399 pub has_cursor: bool,
400}
401
402impl Default for ImePreedit {
403 #[inline(always)]
404 fn default() -> Self {
405 Self::empty()
406 }
407}
408
409impl ImePreedit {
410 #[inline(always)]
412 pub const fn empty() -> Self {
413 Self {
414 buf: [0; 64],
415 len: 0,
416 cursor_start: 0,
417 cursor_end: 0,
418 has_cursor: false,
419 }
420 }
421
422 pub fn from_str(text: &str, cursor: Option<(usize, usize)>) -> Self {
424 let mut out = Self::empty();
425 let bytes = text.as_bytes();
426 let mut copy_len = bytes.len().min(64);
427 while copy_len > 0 && !text.is_char_boundary(copy_len) {
428 copy_len -= 1;
429 }
430 out.buf[..copy_len].copy_from_slice(&bytes[..copy_len]);
431 out.len = copy_len as u8;
432 if let Some((s, e)) = cursor {
433 out.cursor_start = s.min(copy_len) as u8;
434 out.cursor_end = e.min(copy_len) as u8;
435 out.has_cursor = true;
436 }
437 out
438 }
439
440 #[inline]
442 pub fn as_str(&self) -> &str {
443 let n = (self.len as usize).min(64);
444 core::str::from_utf8(&self.buf[..n]).unwrap_or("")
445 }
446
447 #[inline(always)]
449 pub const fn is_empty(&self) -> bool {
450 self.len == 0
451 }
452
453 #[inline(always)]
455 pub const fn cursor(&self) -> Option<(usize, usize)> {
456 if self.has_cursor {
457 Some((self.cursor_start as usize, self.cursor_end as usize))
458 } else {
459 None
460 }
461 }
462}
463
464#[derive(Copy, Clone, PartialEq, Eq, Debug)]
466pub enum InputEvent {
467 PointerDown { x: i16, y: i16 },
469 PointerMove { x: i16, y: i16 },
471 PointerUp { x: i16, y: i16 },
473 PointerSecondaryDown { x: i16, y: i16 },
475 PointerSecondaryUp { x: i16, y: i16 },
477 PointerLeave,
479 PointerCancel,
481 PointerKindChanged(PointerKind),
483 Scroll {
485 x: i16,
486 y: i16,
487 delta_y: i16,
488 },
489 ScrollX {
491 x: i16,
492 y: i16,
493 delta_x: i16,
494 },
495 KeyDown(KeyCode),
497 KeyUp(KeyCode),
499 ModifiersChanged(KeyModifiers),
501 Backspace,
503 Delete,
505 TextCommit(char),
507 ImeEnabled,
509 ImeDisabled,
511 ImePreedit(ImePreedit),
513 NavigateBack,
515 SafeAreaChanged(SafeAreaInsets),
517 KeyboardInsetChanged(i16),
519 Pinch {
521 x: i16,
522 y: i16,
523 delta_scale_x1000: i16,
524 },
525 Rotate {
527 x: i16,
528 y: i16,
529 delta_deg10: i16,
530 },
531 ScrollPixel {
533 x: i16,
534 y: i16,
535 dx: i16,
536 dy: i16,
537 },
538 FileHovered { x: i16, y: i16 },
540 FileDropped { x: i16, y: i16 },
542 FileHoverCancelled,
544 SystemThemeChanged { dark: bool },
546}
547
548#[repr(u8)]
550#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
551pub enum EventPhase {
552 Capture = 0,
553 #[default]
554 Target = 1,
555 Bubble = 2,
556}
557
558#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
560pub struct DragPayload {
561 pub kind_tag: u32,
563 pub payload_id: u64,
565 pub source_id: u32,
567}
568