winit-core: move keyboard
This commit is contained in:
parent
3142355417
commit
a491c2abed
6 changed files with 18 additions and 10 deletions
|
|
@ -2,8 +2,14 @@ use smol_str::SmolStr;
|
|||
|
||||
use crate::keyboard::{Key, KeyCode, NamedKey, NativeKey, NativeKeyCode, PhysicalKey};
|
||||
|
||||
impl Key {
|
||||
pub(crate) fn from_key_attribute_value(kav: &str) -> Self {
|
||||
pub trait FromAttributeValue {
|
||||
fn from_attribute_value(kav: &str) -> Self
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
impl FromAttributeValue for Key {
|
||||
fn from_attribute_value(kav: &str) -> Self {
|
||||
Key::Named(match kav {
|
||||
"Unidentified" => return Key::Unidentified(NativeKey::Web(SmolStr::new(kav))),
|
||||
"Dead" => return Key::Dead(None),
|
||||
|
|
@ -319,8 +325,8 @@ impl Key {
|
|||
}
|
||||
}
|
||||
|
||||
impl PhysicalKey {
|
||||
pub fn from_key_code_attribute_value(kcav: &str) -> Self {
|
||||
impl FromAttributeValue for PhysicalKey {
|
||||
fn from_attribute_value(kcav: &str) -> Self {
|
||||
PhysicalKey::Code(match kcav {
|
||||
"Backquote" => KeyCode::Backquote,
|
||||
"Backslash" => KeyCode::Backslash,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use web_sys::{KeyboardEvent, MouseEvent, Navigator, PointerEvent, WheelEvent};
|
|||
use super::Engine;
|
||||
use crate::event::{FingerId, MouseButton, MouseScrollDelta, PointerKind};
|
||||
use crate::keyboard::{Key, KeyLocation, ModifiersState, NamedKey, PhysicalKey};
|
||||
use crate::platform_impl::web::keyboard::FromAttributeValue;
|
||||
|
||||
bitflags::bitflags! {
|
||||
// https://www.w3.org/TR/pointerevents3/#the-buttons-property
|
||||
|
|
@ -170,16 +171,16 @@ pub fn pointer_type(event: &PointerEvent, pointer_id: i32) -> PointerKind {
|
|||
|
||||
pub fn key_code(event: &KeyboardEvent) -> PhysicalKey {
|
||||
let code = event.code();
|
||||
PhysicalKey::from_key_code_attribute_value(&code)
|
||||
PhysicalKey::from_attribute_value(&code)
|
||||
}
|
||||
|
||||
pub fn key(event: &KeyboardEvent) -> Key {
|
||||
Key::from_key_attribute_value(&event.key())
|
||||
Key::from_attribute_value(&event.key())
|
||||
}
|
||||
|
||||
pub fn key_text(event: &KeyboardEvent) -> Option<SmolStr> {
|
||||
let key = event.key();
|
||||
let key = Key::from_key_attribute_value(&key);
|
||||
let key = Key::from_attribute_value(&key);
|
||||
match &key {
|
||||
Key::Character(text) => Some(text.clone()),
|
||||
Key::Named(NamedKey::Tab) => Some(SmolStr::new("\t")),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue