From 251beb34720d2e7d60ceaddc811a65f52f15bdbd Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 6 Mar 2024 22:15:33 +0100 Subject: feat(glfw): add setting key callback --- glfw/src/util.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'glfw/src/util.rs') diff --git a/glfw/src/util.rs b/glfw/src/util.rs index f77aaf8..98dcb9b 100644 --- a/glfw/src/util.rs +++ b/glfw/src/util.rs @@ -8,3 +8,34 @@ pub fn is_main_thread() -> bool ttid == pid } + +macro_rules! enum_from_repr { + ( + #[repr($repr: ident)] + $(#[$attr: meta])* + $visibility: vis enum $name: ident + { + $($variant: ident = $raw: path,)* + } + ) => { + $(#[$attr])* + #[repr($repr)] + $visibility enum $name + { + $($variant = $raw,)* + } + + impl $name + { + fn from_repr(repr: $repr) -> Option + { + match repr { + $($raw => Some(Self::$variant),)* + _ => None + } + } + } + }; +} + +pub(crate) use enum_from_repr; -- cgit v1.2.3-18-g5258