Use keyboard_types instead of bespoke ModifierSet
This commit is contained in:
1 parent
2ef332085c
commit
3fec31fe50
5 files changed
+24
-23
No files matched your search
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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::*;
|
||||
Reference in new issue
Block a user