winit-core: move keyboard
This commit is contained in:
parent
3142355417
commit
a491c2abed
6 changed files with 18 additions and 10 deletions
|
|
@ -78,6 +78,7 @@ changelog entry.
|
||||||
- Implement `CustomIconProvider` for `RgbaIcon`.
|
- Implement `CustomIconProvider` for `RgbaIcon`.
|
||||||
- Add `icon` module that exposes winit's icon API.
|
- Add `icon` module that exposes winit's icon API.
|
||||||
- `VideoMode::new` to create a `VideoMode`.
|
- `VideoMode::new` to create a `VideoMode`.
|
||||||
|
- `keyboard::ModifiersKey` to track which modifier is exactly pressed.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -305,8 +305,7 @@ mod cursor;
|
||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod event_loop;
|
pub mod event_loop;
|
||||||
pub mod icon;
|
pub mod icon;
|
||||||
pub mod keyboard;
|
pub use winit_core::{keyboard, monitor};
|
||||||
pub use winit_core::monitor;
|
|
||||||
mod platform_impl;
|
mod platform_impl;
|
||||||
use winit_core::as_any as utils;
|
use winit_core::as_any as utils;
|
||||||
pub mod window;
|
pub mod window;
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,14 @@ use smol_str::SmolStr;
|
||||||
|
|
||||||
use crate::keyboard::{Key, KeyCode, NamedKey, NativeKey, NativeKeyCode, PhysicalKey};
|
use crate::keyboard::{Key, KeyCode, NamedKey, NativeKey, NativeKeyCode, PhysicalKey};
|
||||||
|
|
||||||
impl Key {
|
pub trait FromAttributeValue {
|
||||||
pub(crate) fn from_key_attribute_value(kav: &str) -> Self {
|
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 {
|
Key::Named(match kav {
|
||||||
"Unidentified" => return Key::Unidentified(NativeKey::Web(SmolStr::new(kav))),
|
"Unidentified" => return Key::Unidentified(NativeKey::Web(SmolStr::new(kav))),
|
||||||
"Dead" => return Key::Dead(None),
|
"Dead" => return Key::Dead(None),
|
||||||
|
|
@ -319,8 +325,8 @@ impl Key {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PhysicalKey {
|
impl FromAttributeValue for PhysicalKey {
|
||||||
pub fn from_key_code_attribute_value(kcav: &str) -> Self {
|
fn from_attribute_value(kcav: &str) -> Self {
|
||||||
PhysicalKey::Code(match kcav {
|
PhysicalKey::Code(match kcav {
|
||||||
"Backquote" => KeyCode::Backquote,
|
"Backquote" => KeyCode::Backquote,
|
||||||
"Backslash" => KeyCode::Backslash,
|
"Backslash" => KeyCode::Backslash,
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use web_sys::{KeyboardEvent, MouseEvent, Navigator, PointerEvent, WheelEvent};
|
||||||
use super::Engine;
|
use super::Engine;
|
||||||
use crate::event::{FingerId, MouseButton, MouseScrollDelta, PointerKind};
|
use crate::event::{FingerId, MouseButton, MouseScrollDelta, PointerKind};
|
||||||
use crate::keyboard::{Key, KeyLocation, ModifiersState, NamedKey, PhysicalKey};
|
use crate::keyboard::{Key, KeyLocation, ModifiersState, NamedKey, PhysicalKey};
|
||||||
|
use crate::platform_impl::web::keyboard::FromAttributeValue;
|
||||||
|
|
||||||
bitflags::bitflags! {
|
bitflags::bitflags! {
|
||||||
// https://www.w3.org/TR/pointerevents3/#the-buttons-property
|
// 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 {
|
pub fn key_code(event: &KeyboardEvent) -> PhysicalKey {
|
||||||
let code = event.code();
|
let code = event.code();
|
||||||
PhysicalKey::from_key_code_attribute_value(&code)
|
PhysicalKey::from_attribute_value(&code)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn key(event: &KeyboardEvent) -> Key {
|
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> {
|
pub fn key_text(event: &KeyboardEvent) -> Option<SmolStr> {
|
||||||
let key = event.key();
|
let key = event.key();
|
||||||
let key = Key::from_key_attribute_value(&key);
|
let key = Key::from_attribute_value(&key);
|
||||||
match &key {
|
match &key {
|
||||||
Key::Character(text) => Some(text.clone()),
|
Key::Character(text) => Some(text.clone()),
|
||||||
Key::Named(NamedKey::Tab) => Some(SmolStr::new("\t")),
|
Key::Named(NamedKey::Tab) => Some(SmolStr::new("\t")),
|
||||||
|
|
|
||||||
|
|
@ -1750,7 +1750,7 @@ pub enum ModifiersKeyState {
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
pub(crate) struct ModifiersKeys: u8 {
|
pub struct ModifiersKeys: u8 {
|
||||||
const LSHIFT = 0b0000_0001;
|
const LSHIFT = 0b0000_0001;
|
||||||
const RSHIFT = 0b0000_0010;
|
const RSHIFT = 0b0000_0010;
|
||||||
const LCONTROL = 0b0000_0100;
|
const LCONTROL = 0b0000_0100;
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod as_any;
|
pub mod as_any;
|
||||||
|
pub mod keyboard;
|
||||||
pub mod monitor;
|
pub mod monitor;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue