Преглед изворни кода

Use keyboard_types instead of bespoke ModifierSet

Reinis Mazeiks пре 3 година
родитељ
комит
3fec31fe50

+ 1 - 0
packages/html/Cargo.toml

@@ -17,6 +17,7 @@ serde_repr = { version = "0.1", optional = true }
 wasm-bindgen = { version = "0.2.79", optional = true }
 euclid = "0.22.7"
 enumset = "1.0.11"
+keyboard-types = "0.6.2"
 
 [dependencies.web-sys]
 optional = true

+ 11 - 8
packages/html/src/events.rs

@@ -3,9 +3,12 @@ use dioxus_core::exports::bumpalo;
 use dioxus_core::*;
 
 pub mod on {
+    //! Input events and associated data
+
     use crate::geometry::{ClientPoint, ElementPoint, PagePoint, ScreenPoint};
-    use crate::input::{Modifier, ModifierSet, MouseButton, MouseButtonSet};
+    use crate::input::{MouseButton, MouseButtonSet};
     use enumset::EnumSet;
+    use keyboard_types::Modifiers;
     use std::collections::HashMap;
 
     use super::*;
@@ -593,26 +596,26 @@ pub mod on {
         }
 
         /// The set of modifier keys which were pressed when the event occurred
-        pub fn modifiers(&self) -> ModifierSet {
-            let mut set = EnumSet::empty();
+        pub fn modifiers(&self) -> Modifiers {
+            let mut modifiers = Modifiers::empty();
 
             #[allow(deprecated)]
             {
                 if self.alt_key {
-                    set |= Modifier::Alt;
+                    modifiers.insert(Modifiers::ALT);
                 }
                 if self.ctrl_key {
-                    set |= Modifier::Ctrl;
+                    modifiers.insert(Modifiers::CONTROL);
                 }
                 if self.meta_key {
-                    set |= Modifier::Meta;
+                    modifiers.insert(Modifiers::META);
                 }
                 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.

+ 8 - 0
packages/html/src/geometry.rs

@@ -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;
+
 use euclid::*;
 
 /// Coordinate space relative to the screen
 pub struct ScreenSpace;
+/// A point in ScreenSpace
 pub type ScreenPoint = Point2D<f64, ScreenSpace>;
 
 /// Coordinate space relative to the viewport
 pub struct ClientSpace;
+/// A point in ClientSpace
 pub type ClientPoint = Point2D<f64, ClientSpace>;
 
 /// Coordinate space relative to an element
 pub struct ElementSpace;
+/// A point in ElementSpace
 pub type ElementPoint = Point2D<f64, ElementSpace>;
 
 /// Coordinate space relative to the page
 pub struct PageSpace;
+/// A point in PageSpace
 pub type PagePoint = Point2D<f64, PageSpace>;
 
 /// Coordinates of a point in the app's interface

+ 3 - 13
packages/html/src/input.rs

@@ -1,18 +1,8 @@
+//! Data structures representing user input, such as modifier keys and mouse buttons
 use enumset::{EnumSet, EnumSetType};
 
-// note: EnumSetType also derives Copy and Clone for some reason
-/// A modifier key, such as Alt or Ctrl
-#[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 re-export of keyboard_types
+pub use keyboard_types;
 
 /// A mouse button type (such as Primary/Secondary)
 // note: EnumSetType also derives Copy and Clone for some reason

+ 1 - 2
packages/html/src/lib.rs

@@ -17,11 +17,10 @@ mod elements;
 mod events;
 pub mod geometry;
 mod global_attributes;
-mod input;
+pub mod input;
 #[cfg(feature = "wasm-bind")]
 mod web_sys_bind;
 
 pub use elements::*;
 pub use events::*;
 pub use global_attributes::*;
-pub use input::*;