Update bitflags to 2.0

Co-authored-by: dAxpeDDa <daxpedda@gmail.com>
This commit is contained in:
George Burton 2023-06-02 15:44:36 +01:00 committed by GitHub
parent d273518ce9
commit 31ebc5caf4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 27 additions and 14 deletions

View file

@ -7,6 +7,7 @@ use std::convert::TryInto;
use web_sys::{HtmlCanvasElement, KeyboardEvent, MouseEvent, PointerEvent, WheelEvent};
bitflags! {
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct ButtonsState: u16 {
const LEFT = 0b001;
const RIGHT = 0b010;
@ -31,13 +32,13 @@ impl From<MouseButton> for ButtonsState {
MouseButton::Left => ButtonsState::LEFT,
MouseButton::Right => ButtonsState::RIGHT,
MouseButton::Middle => ButtonsState::MIDDLE,
MouseButton::Other(value) => unsafe { ButtonsState::from_bits_unchecked(value) },
MouseButton::Other(value) => ButtonsState::from_bits_retain(value),
}
}
}
pub fn mouse_buttons(event: &MouseEvent) -> ButtonsState {
unsafe { ButtonsState::from_bits_unchecked(event.buttons()) }
ButtonsState::from_bits_retain(event.buttons())
}
pub fn mouse_button(event: &MouseEvent) -> Option<MouseButton> {