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`.
|
||||
- Add `icon` module that exposes winit's icon API.
|
||||
- `VideoMode::new` to create a `VideoMode`.
|
||||
- `keyboard::ModifiersKey` to track which modifier is exactly pressed.
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
|||
|
|
@ -305,8 +305,7 @@ mod cursor;
|
|||
pub mod event;
|
||||
pub mod event_loop;
|
||||
pub mod icon;
|
||||
pub mod keyboard;
|
||||
pub use winit_core::monitor;
|
||||
pub use winit_core::{keyboard, monitor};
|
||||
mod platform_impl;
|
||||
use winit_core::as_any as utils;
|
||||
pub mod window;
|
||||
|
|
|
|||
|
|
@ -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")),
|
||||
|
|
|
|||
|
|
@ -1750,7 +1750,7 @@ pub enum ModifiersKeyState {
|
|||
bitflags! {
|
||||
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub(crate) struct ModifiersKeys: u8 {
|
||||
pub struct ModifiersKeys: u8 {
|
||||
const LSHIFT = 0b0000_0001;
|
||||
const RSHIFT = 0b0000_0010;
|
||||
const LCONTROL = 0b0000_0100;
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
#[macro_use]
|
||||
pub mod as_any;
|
||||
pub mod keyboard;
|
||||
pub mod monitor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue