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

@ -39,6 +39,7 @@ extern_methods!(
);
bitflags! {
#[derive(Clone, Copy)]
pub struct UIInterfaceOrientationMask: NSUInteger {
const Portrait = 1 << 1;
const PortraitUpsideDown = 1 << 2;

View file

@ -109,6 +109,7 @@ unsafe impl Encode for NSApplicationActivationPolicy {
}
bitflags! {
#[derive(Debug, Clone, Copy)]
pub struct NSApplicationPresentationOptions: NSUInteger {
const NSApplicationPresentationDefault = 0;
const NSApplicationPresentationAutoHideDock = 1 << 0;

View file

@ -194,6 +194,7 @@ const NX_DEVICERALTKEYMASK: u32 = 0x00000040;
const NX_DEVICERCTLKEYMASK: u32 = 0x00002000;
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NSEventModifierFlags: NSUInteger {
const NSAlphaShiftKeyMask = 1 << 16;
const NSShiftKeyMask = 1 << 17;
@ -212,6 +213,7 @@ unsafe impl Encode for NSEventModifierFlags {
}
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NSEventPhase: NSUInteger {
const NSEventPhaseNone = 0;
const NSEventPhaseBegan = 0x1 << 0;

View file

@ -336,6 +336,7 @@ unsafe impl Encode for NSWindowLevel {
}
bitflags! {
#[derive(Clone, Copy)]
pub struct NSWindowOcclusionState: NSUInteger {
const NSWindowOcclusionStateVisible = 1 << 1;
}
@ -346,6 +347,7 @@ unsafe impl Encode for NSWindowOcclusionState {
}
bitflags! {
#[derive(Debug, Clone, Copy)]
pub struct NSWindowStyleMask: NSUInteger {
const NSBorderlessWindowMask = 0;
const NSTitledWindowMask = 1 << 0;

View file

@ -71,6 +71,7 @@ enum ImeState {
}
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq)]
struct ModLocationMask: u8 {
const LEFT = 1;
const RIGHT = 2;

View file

@ -120,7 +120,7 @@ fn element_state(pressed: bool) -> event::ElementState {
}
bitflags! {
#[derive(Default)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
struct KeyboardModifierState: u8 {
const LSHIFT = 1 << 0;
const RSHIFT = 1 << 1;
@ -134,7 +134,7 @@ bitflags! {
}
bitflags! {
#[derive(Default)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
struct MouseButtonState: u8 {
const LEFT = 1 << 0;
const MIDDLE = 1 << 1;

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> {

View file

@ -105,6 +105,7 @@ static NUMPAD_KEYCODES: Lazy<HashSet<KeyCode>> = Lazy::new(|| {
});
bitflags! {
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct WindowsModifiers : u8 {
const SHIFT = 1 << 0;
const CONTROL = 1 << 1;
@ -362,11 +363,11 @@ impl LayoutCache {
}
// Iterate through every combination of modifiers
let mods_end = WindowsModifiers::FLAGS_END.bits;
let mods_end = WindowsModifiers::FLAGS_END.bits();
for mod_state in 0..mods_end {
let mut keys_for_this_mod = HashMap::with_capacity(256);
let mod_state = unsafe { WindowsModifiers::from_bits_unchecked(mod_state) };
let mod_state = WindowsModifiers::from_bits_retain(mod_state);
mod_state.apply_to_kbd_state(&mut key_state);
// Virtual key values are in the domain [0, 255].
@ -442,7 +443,7 @@ impl LayoutCache {
// Second pass: replace right alt keys with AltGr if the layout has alt graph
if layout.has_alt_graph {
for mod_state in 0..mods_end {
let mod_state = unsafe { WindowsModifiers::from_bits_unchecked(mod_state) };
let mod_state = WindowsModifiers::from_bits_retain(mod_state);
if let Some(keys) = layout.keys.get_mut(&mod_state) {
if let Some(key) = keys.get_mut(&KeyCode::AltRight) {
*key = Key::AltGraph;

View file

@ -71,6 +71,7 @@ pub struct MouseProperties {
}
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CursorFlags: u8 {
const GRABBED = 1 << 0;
const HIDDEN = 1 << 1;
@ -78,6 +79,7 @@ bitflags! {
}
}
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct WindowFlags: u32 {
const RESIZABLE = 1 << 0;
const MINIMIZABLE = 1 << 1;
@ -118,7 +120,7 @@ bitflags! {
const MARKER_ACTIVATE = 1 << 21;
const EXCLUSIVE_FULLSCREEN_OR_MASK = WindowFlags::ALWAYS_ON_TOP.bits;
const EXCLUSIVE_FULLSCREEN_OR_MASK = WindowFlags::ALWAYS_ON_TOP.bits();
}
}