use crate::{EventButton, EventButtonState, WebEventKind};
impl EventButton {
pub const fn from_web(js_button: u8) -> Option<Self> {
match js_button {
0 => Some(EventButton::Left),
1 => Some(EventButton::Middle),
2 => Some(EventButton::Right),
3 => Some(EventButton::X1),
4 => Some(EventButton::X2),
5 => Some(EventButton::X3),
6 => Some(EventButton::X4),
7 => Some(EventButton::X5),
255 => None, n => Some(EventButton::Other(n)),
}
}
pub const fn to_web(self) -> u8 {
match self {
EventButton::Left => 0,
EventButton::Middle => 1,
EventButton::Right => 2,
EventButton::X1 => 3,
EventButton::X2 => 4,
EventButton::X3 => 5,
EventButton::X4 => 6,
EventButton::X5 => 7,
EventButton::Other(n) => n,
}
}
}
impl EventButtonState {
pub const fn from_web(js_event: WebEventKind) -> Self {
use {EventButtonState as E, WebEventKind as J};
match js_event {
J::Click | J::MouseDown | J::PointerDown => E::Pressed,
J::MouseUp | J::PointerUp => E::Released,
_ => E::Moved,
}
}
pub const fn to_web_as_mouse(self) -> WebEventKind {
use {EventButtonState as E, WebEventKind as J};
match self {
E::Pressed => J::MouseDown,
E::Released => J::MouseUp,
E::Moved => J::MouseMove,
}
}
pub const fn to_web_as_pointer(self) -> WebEventKind {
use {EventButtonState as E, WebEventKind as J};
match self {
E::Pressed => J::PointerDown,
E::Released => J::PointerUp,
E::Moved => J::PointerMove,
}
}
}