add touch data to touch events

This commit is contained in:
Evan Almloff committed 2023-09-12 17:28:55 -05:00
1 parent b47064165e
commit c10700c962
8 files changed
+339 -160

No files matched your search

+24 -21
View File
@@ -2,6 +2,8 @@ use dioxus_core::Event;
use keyboard_types::{Code, Key, Location, Modifiers};
use std::fmt::Debug;
use crate::prelude::ModifiersInteraction;
#[cfg(feature = "serialize")]
fn resilient_deserialize_code<'de, D>(deserializer: D) -> Result<Code, D::Error>
where
@@ -63,11 +65,6 @@ impl KeyboardData {
self.inner.code()
}
/// The set of modifier keys which were pressed when the event occurred
pub fn modifiers(&self) -> Modifiers {
self.inner.modifiers()
}
/// The location of the key on the keyboard or other input device.
pub fn location(&self) -> Location {
self.inner.location()
@@ -84,6 +81,12 @@ impl KeyboardData {
}
}
impl ModifiersInteraction for KeyboardData {
fn modifiers(&self) -> Modifiers {
self.inner.modifiers()
}
}
#[cfg(feature = "serialize")]
/// A serialized version of KeyboardData
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
@@ -155,6 +158,21 @@ impl HasKeyboardData for SerializedKeyboardData {
self.code
}
fn location(&self) -> Location {
crate::input_data::decode_key_location(self.location)
}
fn is_auto_repeating(&self) -> bool {
self.repeat
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
#[cfg(feature = "serialize")]
impl ModifiersInteraction for SerializedKeyboardData {
fn modifiers(&self) -> Modifiers {
let mut modifiers = Modifiers::empty();
@@ -173,18 +191,6 @@ impl HasKeyboardData for SerializedKeyboardData {
modifiers
}
fn location(&self) -> Location {
crate::input_data::decode_key_location(self.location)
}
fn is_auto_repeating(&self) -> bool {
self.repeat
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
#[cfg(feature = "serialize")]
@@ -217,16 +223,13 @@ impl_event! {
onkeyup
}
pub trait HasKeyboardData: std::any::Any {
pub trait HasKeyboardData: ModifiersInteraction + std::any::Any {
/// The value of the key pressed by the user, taking into consideration the state of modifier keys such as Shift as well as the keyboard locale and layout.
fn key(&self) -> Key;
/// A physical key on the keyboard (as opposed to the character generated by pressing the key). In other words, this property returns a value that isn't altered by keyboard layout or the state of the modifier keys.
fn code(&self) -> Code;
/// The set of modifier keys which were pressed when the event occurred
fn modifiers(&self) -> Modifiers;
/// The location of the key on the keyboard or other input device.
fn location(&self) -> Location;