mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 22:31:14 +00:00
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:
parent
db740831ee
commit
9ca87ab312
10 changed files with 223 additions and 463 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue