devela/sys/os/browser/web/event/
button.rs1use crate::{EventButton, EventButtonState, WebEventKind};
7
8impl EventButton {
9 pub const fn from_web(js_button: u8) -> Option<Self> {
14 match js_button {
15 0 => Some(EventButton::Left),
16 1 => Some(EventButton::Middle),
17 2 => Some(EventButton::Right),
18 3 => Some(EventButton::X1),
19 4 => Some(EventButton::X2),
20 5 => Some(EventButton::X3),
22 6 => Some(EventButton::X4),
23 7 => Some(EventButton::X5),
24 255 => None, n => Some(EventButton::Other(n)),
26 }
27 }
28 pub const fn to_web(self) -> u8 {
30 match self {
31 EventButton::Left => 0,
32 EventButton::Middle => 1,
33 EventButton::Right => 2,
34 EventButton::X1 => 3,
35 EventButton::X2 => 4,
36 EventButton::X3 => 5,
38 EventButton::X4 => 6,
39 EventButton::X5 => 7,
40 EventButton::Other(n) => n,
41 }
42 }
43}
44
45impl EventButtonState {
47 pub const fn from_web(js_event: WebEventKind) -> Self {
49 use {EventButtonState as E, WebEventKind as J};
50 match js_event {
51 J::Click | J::MouseDown | J::PointerDown => E::Pressed,
52 J::MouseUp | J::PointerUp => E::Released,
53 _ => E::Moved,
54 }
55 }
56 pub const fn to_web_as_mouse(self) -> WebEventKind {
58 use {EventButtonState as E, WebEventKind as J};
59 match self {
60 E::Pressed => J::MouseDown,
61 E::Released => J::MouseUp,
62 E::Moved => J::MouseMove,
63 }
64 }
65 pub const fn to_web_as_pointer(self) -> WebEventKind {
67 use {EventButtonState as E, WebEventKind as J};
68 match self {
69 E::Pressed => J::PointerDown,
70 E::Released => J::PointerUp,
71 E::Moved => J::PointerMove,
72 }
73 }
74}