Refactor: move input types to separate module
This commit is contained in:
1 parent
6ba067a617
commit
2ef332085c
3 files changed
+61
-54
No files matched your search
@@ -1,10 +1,10 @@
|
|||||||
use bumpalo::boxed::Box as BumpBox;
|
use bumpalo::boxed::Box as BumpBox;
|
||||||
use dioxus_core::exports::bumpalo;
|
use dioxus_core::exports::bumpalo;
|
||||||
use dioxus_core::*;
|
use dioxus_core::*;
|
||||||
use enumset::EnumSetType;
|
|
||||||
|
|
||||||
pub mod on {
|
pub mod on {
|
||||||
use crate::geometry::{ClientPoint, Coordinates, ElementPoint, PagePoint, ScreenPoint};
|
use crate::geometry::{ClientPoint, ElementPoint, PagePoint, ScreenPoint};
|
||||||
|
use crate::input::{Modifier, ModifierSet, MouseButton, MouseButtonSet};
|
||||||
use enumset::EnumSet;
|
use enumset::EnumSet;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@@ -654,58 +654,6 @@ pub mod on {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// note: EnumSetType also derives Copy and Clone for some reason
|
|
||||||
#[derive(EnumSetType, Debug)]
|
|
||||||
pub enum Modifier {
|
|
||||||
Alt,
|
|
||||||
Ctrl,
|
|
||||||
Meta,
|
|
||||||
Shift,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type ModifierSet = EnumSet<Modifier>;
|
|
||||||
|
|
||||||
/// A mouse button type (such as Primary/Secondary)
|
|
||||||
// note: EnumSetType also derives Copy and Clone for some reason
|
|
||||||
#[derive(EnumSetType, Debug)]
|
|
||||||
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
|
||||||
pub enum MouseButton {
|
|
||||||
/// Primary button (typically the left button)
|
|
||||||
Primary,
|
|
||||||
/// Secondary button (typically the right button)
|
|
||||||
Secondary,
|
|
||||||
/// Auxiliary button (typically the middle button)
|
|
||||||
Auxiliary,
|
|
||||||
/// Fourth button (typically the "Browser Back" button)
|
|
||||||
Fourth,
|
|
||||||
/// Fifth button (typically the "Browser Forward" button)
|
|
||||||
Fifth,
|
|
||||||
/// A button with an unknown code
|
|
||||||
Unknown,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MouseButton {
|
|
||||||
/// Constructs a MouseButton for the specified button code
|
|
||||||
///
|
|
||||||
/// E.g. 0 => Primary; 1 => Auxiliary
|
|
||||||
///
|
|
||||||
/// Unknown codes get mapped to MouseButton::Unknown.
|
|
||||||
pub fn from_web_code(code: i16) -> Self {
|
|
||||||
match code {
|
|
||||||
0 => MouseButton::Primary,
|
|
||||||
// not a typo; auxiliary and secondary are swapped unlike in the `buttons` field.
|
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
||||||
1 => MouseButton::Auxiliary,
|
|
||||||
2 => MouseButton::Secondary,
|
|
||||||
3 => MouseButton::Fourth,
|
|
||||||
4 => MouseButton::Fifth,
|
|
||||||
_ => MouseButton::Unknown,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type MouseButtonSet = EnumSet<MouseButton>;
|
|
||||||
|
|
||||||
pub type PointerEvent = UiEvent<PointerData>;
|
pub type PointerEvent = UiEvent<PointerData>;
|
||||||
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
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 mouse button type (such as Primary/Secondary)
|
||||||
|
// note: EnumSetType also derives Copy and Clone for some reason
|
||||||
|
#[derive(EnumSetType, Debug)]
|
||||||
|
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
||||||
|
pub enum MouseButton {
|
||||||
|
/// Primary button (typically the left button)
|
||||||
|
Primary,
|
||||||
|
/// Secondary button (typically the right button)
|
||||||
|
Secondary,
|
||||||
|
/// Auxiliary button (typically the middle button)
|
||||||
|
Auxiliary,
|
||||||
|
/// Fourth button (typically the "Browser Back" button)
|
||||||
|
Fourth,
|
||||||
|
/// Fifth button (typically the "Browser Forward" button)
|
||||||
|
Fifth,
|
||||||
|
/// A button with an unknown code
|
||||||
|
Unknown,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MouseButton {
|
||||||
|
/// Constructs a MouseButton for the specified button code
|
||||||
|
///
|
||||||
|
/// E.g. 0 => Primary; 1 => Auxiliary
|
||||||
|
///
|
||||||
|
/// Unknown codes get mapped to MouseButton::Unknown.
|
||||||
|
pub fn from_web_code(code: i16) -> Self {
|
||||||
|
match code {
|
||||||
|
0 => MouseButton::Primary,
|
||||||
|
// not a typo; auxiliary and secondary are swapped unlike in the `buttons` field.
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
||||||
|
1 => MouseButton::Auxiliary,
|
||||||
|
2 => MouseButton::Secondary,
|
||||||
|
3 => MouseButton::Fourth,
|
||||||
|
4 => MouseButton::Fifth,
|
||||||
|
_ => MouseButton::Unknown,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A set of mouse buttons
|
||||||
|
pub type MouseButtonSet = EnumSet<MouseButton>;
|
||||||
@@ -17,9 +17,11 @@ mod elements;
|
|||||||
mod events;
|
mod events;
|
||||||
pub mod geometry;
|
pub mod geometry;
|
||||||
mod global_attributes;
|
mod global_attributes;
|
||||||
|
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::*;
|
||||||
Reference in new issue
Block a user