Simplify KeyEvent

Fold CharacterInput into KeyPressed/KeyReleased and store the "key" as a string.

Also, instead of exposing the KeyCode we're encoding special characters
into the string.
This commit is contained in:
Simon Hausmann 2021-01-21 15:37:17 +01:00
parent db740831ee
commit 9ca87ab312
10 changed files with 223 additions and 463 deletions

View file

@ -175,30 +175,3 @@ fn callback_arg(ty: &syn::Type) -> Option<&syn::Type> {
}
None
}
#[proc_macro_derive(MappedKeyCode)]
pub fn keycode_mapping(input: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(input as syn::DeriveInput);
let variants = match &input.data {
syn::Data::Enum(syn::DataEnum { variants, .. }) => variants,
_ => {
return syn::Error::new(input.ident.span(), "Only `enum` types are supported")
.to_compile_error()
.into()
}
}
.iter()
.collect::<Vec<_>>();
quote!(
impl From<winit::event::VirtualKeyCode> for KeyCode {
fn from(code: winit::event::VirtualKeyCode) -> Self {
match code {
#(winit::event::VirtualKeyCode::#variants => Self::#variants),*
}
}
}
)
.into()
}