Revise Key and KeyCode enums

Split `Key` into clear categories, like `Named`, `Dead`, Character`, `Unidentified`
removing the `#[non_exhaustive]` from the `Key` itself.

Similar action was done for the `KeyCode`.

Fixes: #2995
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
This commit is contained in:
Diggory Hardy 2023-10-19 15:27:49 +01:00 committed by GitHub
parent b9e1e96eaa
commit acfeff5327
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 1456 additions and 1277 deletions

View file

@ -1,6 +1,6 @@
use crate::dpi::LogicalPosition;
use crate::event::{MouseButton, MouseScrollDelta};
use crate::keyboard::{Key, KeyCode, KeyLocation, ModifiersState};
use crate::keyboard::{Key, KeyLocation, ModifiersState, NamedKey, PhysicalKey};
use once_cell::unsync::OnceCell;
use smol_str::SmolStr;
@ -149,9 +149,9 @@ pub fn mouse_scroll_delta(
}
}
pub fn key_code(event: &KeyboardEvent) -> KeyCode {
pub fn key_code(event: &KeyboardEvent) -> PhysicalKey {
let code = event.code();
KeyCode::from_key_code_attribute_value(&code)
PhysicalKey::from_key_code_attribute_value(&code)
}
pub fn key(event: &KeyboardEvent) -> Key {
@ -163,9 +163,9 @@ pub fn key_text(event: &KeyboardEvent) -> Option<SmolStr> {
let key = Key::from_key_attribute_value(&key);
match &key {
Key::Character(text) => Some(text.clone()),
Key::Tab => Some(SmolStr::new("\t")),
Key::Enter => Some(SmolStr::new("\r")),
Key::Space => Some(SmolStr::new(" ")),
Key::Named(NamedKey::Tab) => Some(SmolStr::new("\t")),
Key::Named(NamedKey::Enter) => Some(SmolStr::new("\r")),
Key::Named(NamedKey::Space) => Some(SmolStr::new(" ")),
_ => None,
}
.map(SmolStr::new)