Use keyboard_types instead of bespoke ModifierSet

This commit is contained in:
Reinis Mazeiks committed 2022-05-07 10:05:52 +03:00
1 parent 2ef332085c
commit 3fec31fe50
5 files changed
+24 -23

No files matched your search

+1
View File
@@ -17,6 +17,7 @@ serde_repr = { version = "0.1", optional = true }
wasm-bindgen = { version = "0.2.79", optional = true } wasm-bindgen = { version = "0.2.79", optional = true }
euclid = "0.22.7" euclid = "0.22.7"
enumset = "1.0.11" enumset = "1.0.11"
keyboard-types = "0.6.2"
[dependencies.web-sys] [dependencies.web-sys]
optional = true optional = true
+11 -8
View File
@@ -3,9 +3,12 @@ use dioxus_core::exports::bumpalo;
use dioxus_core::*; use dioxus_core::*;
pub mod on { pub mod on {
//! Input events and associated data
use crate::geometry::{ClientPoint, ElementPoint, PagePoint, ScreenPoint}; use crate::geometry::{ClientPoint, ElementPoint, PagePoint, ScreenPoint};
use crate::input::{Modifier, ModifierSet, MouseButton, MouseButtonSet}; use crate::input::{MouseButton, MouseButtonSet};
use enumset::EnumSet; use enumset::EnumSet;
use keyboard_types::Modifiers;
use std::collections::HashMap; use std::collections::HashMap;
use super::*; use super::*;
@@ -593,26 +596,26 @@ pub mod on {
} }
/// The set of modifier keys which were pressed when the event occurred /// The set of modifier keys which were pressed when the event occurred
pub fn modifiers(&self) -> ModifierSet { pub fn modifiers(&self) -> Modifiers {
let mut set = EnumSet::empty(); let mut modifiers = Modifiers::empty();
#[allow(deprecated)] #[allow(deprecated)]
{ {
if self.alt_key { if self.alt_key {
set |= Modifier::Alt; modifiers.insert(Modifiers::ALT);
} }
if self.ctrl_key { if self.ctrl_key {
set |= Modifier::Ctrl; modifiers.insert(Modifiers::CONTROL);
} }
if self.meta_key { if self.meta_key {
set |= Modifier::Meta; modifiers.insert(Modifiers::META);
} }
if self.shift_key { if self.shift_key {
set |= Modifier::Shift; modifiers.insert(Modifiers::SHIFT);
} }
} }
set modifiers
} }
/// The set of mouse buttons which were held when the event occurred. /// The set of mouse buttons which were held when the event occurred.
+8
View File
@@ -1,20 +1,28 @@
//! Geometry primitives for representing e.g. mouse events
/// A re-export of euclid, which we use for geometry primitives
pub use euclid; pub use euclid;
use euclid::*; use euclid::*;
/// Coordinate space relative to the screen /// Coordinate space relative to the screen
pub struct ScreenSpace; pub struct ScreenSpace;
/// A point in ScreenSpace
pub type ScreenPoint = Point2D<f64, ScreenSpace>; pub type ScreenPoint = Point2D<f64, ScreenSpace>;
/// Coordinate space relative to the viewport /// Coordinate space relative to the viewport
pub struct ClientSpace; pub struct ClientSpace;
/// A point in ClientSpace
pub type ClientPoint = Point2D<f64, ClientSpace>; pub type ClientPoint = Point2D<f64, ClientSpace>;
/// Coordinate space relative to an element /// Coordinate space relative to an element
pub struct ElementSpace; pub struct ElementSpace;
/// A point in ElementSpace
pub type ElementPoint = Point2D<f64, ElementSpace>; pub type ElementPoint = Point2D<f64, ElementSpace>;
/// Coordinate space relative to the page /// Coordinate space relative to the page
pub struct PageSpace; pub struct PageSpace;
/// A point in PageSpace
pub type PagePoint = Point2D<f64, PageSpace>; pub type PagePoint = Point2D<f64, PageSpace>;
/// Coordinates of a point in the app's interface /// Coordinates of a point in the app's interface
+3 -13
View File
@@ -1,18 +1,8 @@
//! Data structures representing user input, such as modifier keys and mouse buttons
use enumset::{EnumSet, EnumSetType}; use enumset::{EnumSet, EnumSetType};
// note: EnumSetType also derives Copy and Clone for some reason /// A re-export of keyboard_types
/// A modifier key, such as Alt or Ctrl pub use keyboard_types;
#[derive(EnumSetType, Debug)]
pub enum Modifier {
Alt,
Ctrl,
/// The meta key (windows key, or command key)
Meta,
Shift,
}
/// A set of modifier keys
pub type ModifierSet = EnumSet<Modifier>;
/// A mouse button type (such as Primary/Secondary) /// A mouse button type (such as Primary/Secondary)
// note: EnumSetType also derives Copy and Clone for some reason // note: EnumSetType also derives Copy and Clone for some reason
+1 -2
View File
@@ -17,11 +17,10 @@ mod elements;
mod events; mod events;
pub mod geometry; pub mod geometry;
mod global_attributes; mod global_attributes;
mod input; pub mod input;
#[cfg(feature = "wasm-bind")] #[cfg(feature = "wasm-bind")]
mod web_sys_bind; mod web_sys_bind;
pub use elements::*; pub use elements::*;
pub use events::*; pub use events::*;
pub use global_attributes::*; pub use global_attributes::*;
pub use input::*;