From 43c921680bfb73876148cb6f513a56a89a514bca Mon Sep 17 00:00:00 2001 From: gered Date: Thu, 13 Apr 2023 14:43:13 -0400 Subject: [PATCH] add num_derive's FromPrimitive derive to keyboard and mouse button enums this has very limited use, outside of some tests i am writing right now, but maybe it will be useful down the road. (i suppose mostly, i just wanted to try this out for myself ...) --- ggdt/Cargo.toml | 4 +++- ggdt/src/system/input_devices/keyboard/codes.rs | 4 +++- ggdt/src/system/input_devices/keyboard/scancodes.rs | 4 +++- ggdt/src/system/input_devices/mouse/buttons.rs | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ggdt/Cargo.toml b/ggdt/Cargo.toml index 386a58a..65455e2 100644 --- a/ggdt/Cargo.toml +++ b/ggdt/Cargo.toml @@ -10,7 +10,9 @@ byte-slice-cast = "1.2.1" byteorder = "1.4.3" thiserror = "=1.0.30" rand = "0.8.5" -num-traits = "0.2.14" +num = "0.4.0" +num-derive = "0.3.3" +num-traits = "0.2.15" bitflags = "2.0.2" flate2 = "1.0.25" crc32fast = "1.3.2" diff --git a/ggdt/src/system/input_devices/keyboard/codes.rs b/ggdt/src/system/input_devices/keyboard/codes.rs index 807ee43..b7b2b39 100644 --- a/ggdt/src/system/input_devices/keyboard/codes.rs +++ b/ggdt/src/system/input_devices/keyboard/codes.rs @@ -1,6 +1,8 @@ +use num_derive::FromPrimitive; + // ugh -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, FromPrimitive)] #[repr(i32)] pub enum Keycode { Backspace = sdl2::keyboard::Keycode::Backspace as i32, diff --git a/ggdt/src/system/input_devices/keyboard/scancodes.rs b/ggdt/src/system/input_devices/keyboard/scancodes.rs index b1a3cbb..be066c7 100644 --- a/ggdt/src/system/input_devices/keyboard/scancodes.rs +++ b/ggdt/src/system/input_devices/keyboard/scancodes.rs @@ -1,6 +1,8 @@ +use num_derive::FromPrimitive; + // ugh -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, FromPrimitive)] #[repr(i32)] pub enum Scancode { A = sdl2::keyboard::Scancode::A as i32, diff --git a/ggdt/src/system/input_devices/mouse/buttons.rs b/ggdt/src/system/input_devices/mouse/buttons.rs index 7d28f73..b32babb 100644 --- a/ggdt/src/system/input_devices/mouse/buttons.rs +++ b/ggdt/src/system/input_devices/mouse/buttons.rs @@ -1,4 +1,5 @@ use bitflags::bitflags; +use num_derive::FromPrimitive; // equivalent to SDL's "SDL_BUTTON" macro #[inline] @@ -18,7 +19,7 @@ bitflags! { } } -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, FromPrimitive)] #[repr(u8)] pub enum MouseButton { Unknown = 0,