split the point interaction trait into smaller traits for touch compatibility
This commit is contained in:
1 parent
3a02520ffa
commit
a9bb04722f
9 files changed
+101
-50
No files matched your search
@@ -1,6 +1,6 @@
|
||||
use crate::geometry::{ClientPoint, Coordinates, ElementPoint, PagePoint, ScreenPoint};
|
||||
use crate::input_data::{MouseButton, MouseButtonSet};
|
||||
use crate::prelude::PointInteraction;
|
||||
use crate::prelude::*;
|
||||
|
||||
use dioxus_core::Event;
|
||||
use keyboard_types::Modifiers;
|
||||
@@ -17,7 +17,7 @@ pub struct DragData {
|
||||
inner: Box<dyn HasDragData>,
|
||||
}
|
||||
|
||||
impl<E: HasDragData> From<E> for DragData {
|
||||
impl<E: HasDragData + 'static> From<E> for DragData {
|
||||
fn from(e: E) -> Self {
|
||||
Self { inner: Box::new(e) }
|
||||
}
|
||||
@@ -57,7 +57,7 @@ impl DragData {
|
||||
}
|
||||
}
|
||||
|
||||
impl PointInteraction for DragData {
|
||||
impl InteractionLocation for DragData {
|
||||
fn client_coordinates(&self) -> ClientPoint {
|
||||
self.inner.client_coordinates()
|
||||
}
|
||||
@@ -77,11 +77,15 @@ impl PointInteraction for DragData {
|
||||
fn coordinates(&self) -> Coordinates {
|
||||
self.inner.coordinates()
|
||||
}
|
||||
}
|
||||
|
||||
impl ModifiersInteraction for DragData {
|
||||
fn modifiers(&self) -> Modifiers {
|
||||
self.inner.modifiers()
|
||||
}
|
||||
}
|
||||
|
||||
impl PointerInteraction for DragData {
|
||||
fn held_buttons(&self) -> MouseButtonSet {
|
||||
self.inner.held_buttons()
|
||||
}
|
||||
@@ -119,7 +123,7 @@ impl HasMouseData for SerializedDragData {
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl crate::prelude::PointInteraction for SerializedDragData {
|
||||
impl InteractionLocation for SerializedDragData {
|
||||
fn client_coordinates(&self) -> ClientPoint {
|
||||
self.mouse.client_coordinates()
|
||||
}
|
||||
@@ -139,11 +143,17 @@ impl crate::prelude::PointInteraction for SerializedDragData {
|
||||
fn coordinates(&self) -> Coordinates {
|
||||
self.mouse.coordinates()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl ModifiersInteraction for SerializedDragData {
|
||||
fn modifiers(&self) -> Modifiers {
|
||||
self.mouse.modifiers()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl PointerInteraction for SerializedDragData {
|
||||
fn held_buttons(&self) -> MouseButtonSet {
|
||||
self.mouse.held_buttons()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::geometry::{ClientPoint, Coordinates, ElementPoint, PagePoint, ScreenPoint};
|
||||
use crate::input_data::{MouseButton, MouseButtonSet};
|
||||
use crate::point_interaction::PointInteraction;
|
||||
use crate::prelude::*;
|
||||
use dioxus_core::Event;
|
||||
use keyboard_types::Modifiers;
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct MouseData {
|
||||
inner: Box<dyn HasMouseData>,
|
||||
}
|
||||
|
||||
impl<E: HasMouseData> From<E> for MouseData {
|
||||
impl<E: HasMouseData + 'static> From<E> for MouseData {
|
||||
fn from(e: E) -> Self {
|
||||
Self { inner: Box::new(e) }
|
||||
}
|
||||
@@ -39,7 +39,7 @@ impl<E: HasMouseData> PartialEq<E> for MouseData {
|
||||
}
|
||||
|
||||
/// A trait for any object that has the data for a mouse event
|
||||
pub trait HasMouseData: PointInteraction {
|
||||
pub trait HasMouseData: PointerInteraction {
|
||||
/// return self as Any
|
||||
fn as_any(&self) -> &dyn std::any::Any;
|
||||
}
|
||||
@@ -119,7 +119,7 @@ impl MouseData {
|
||||
}
|
||||
}
|
||||
|
||||
impl PointInteraction for MouseData {
|
||||
impl InteractionLocation for MouseData {
|
||||
/// The event's coordinates relative to the application's viewport (as opposed to the coordinate within the page).
|
||||
///
|
||||
/// For example, clicking in the top left corner of the viewport will always result in a mouse event with client coordinates (0., 0.), regardless of whether the page is scrolled horizontally.
|
||||
@@ -149,12 +149,16 @@ impl PointInteraction for MouseData {
|
||||
fn coordinates(&self) -> Coordinates {
|
||||
self.inner.coordinates()
|
||||
}
|
||||
}
|
||||
|
||||
impl ModifiersInteraction for MouseData {
|
||||
/// The set of modifier keys which were pressed when the event occurred
|
||||
fn modifiers(&self) -> Modifiers {
|
||||
self.inner.modifiers()
|
||||
}
|
||||
}
|
||||
|
||||
impl PointerInteraction for MouseData {
|
||||
/// The set of mouse buttons which were held when the event occurred.
|
||||
fn held_buttons(&self) -> MouseButtonSet {
|
||||
self.inner.held_buttons()
|
||||
@@ -224,7 +228,7 @@ impl HasMouseData for SerializedMouseData {
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl PointInteraction for SerializedMouseData {
|
||||
impl InteractionLocation for SerializedMouseData {
|
||||
fn client_coordinates(&self) -> ClientPoint {
|
||||
self.point_data.client_coordinates()
|
||||
}
|
||||
@@ -240,11 +244,17 @@ impl PointInteraction for SerializedMouseData {
|
||||
fn screen_coordinates(&self) -> ScreenPoint {
|
||||
self.point_data.screen_coordinates()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl ModifiersInteraction for SerializedMouseData {
|
||||
fn modifiers(&self) -> Modifiers {
|
||||
self.point_data.modifiers()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl PointerInteraction for SerializedMouseData {
|
||||
fn held_buttons(&self) -> MouseButtonSet {
|
||||
self.point_data.held_buttons()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use dioxus_core::Event;
|
||||
use keyboard_types::Modifiers;
|
||||
|
||||
use crate::{geometry::*, input_data::*, point_interaction::PointInteraction};
|
||||
use crate::{geometry::*, input_data::*, prelude::*};
|
||||
|
||||
/// A synthetic event that wraps a web-style [`PointerEvent`](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent)
|
||||
pub type PointerEvent = Event<PointerData>;
|
||||
@@ -22,7 +22,7 @@ impl PointerData {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: HasPointerData> From<E> for PointerData {
|
||||
impl<E: HasPointerData + 'static> From<E> for PointerData {
|
||||
fn from(e: E) -> Self {
|
||||
Self { inner: Box::new(e) }
|
||||
}
|
||||
@@ -69,7 +69,7 @@ impl PartialEq for PointerData {
|
||||
}
|
||||
|
||||
/// A trait for any object that has the data for a pointer event
|
||||
pub trait HasPointerData: PointInteraction {
|
||||
pub trait HasPointerData: PointerInteraction {
|
||||
/// Gets the unique identifier of the pointer causing the event.
|
||||
fn pointer_id(&self) -> i32;
|
||||
|
||||
@@ -189,7 +189,7 @@ impl PointerData {
|
||||
}
|
||||
}
|
||||
|
||||
impl PointInteraction for PointerData {
|
||||
impl InteractionLocation for PointerData {
|
||||
fn client_coordinates(&self) -> ClientPoint {
|
||||
self.inner.client_coordinates()
|
||||
}
|
||||
@@ -205,11 +205,15 @@ impl PointInteraction for PointerData {
|
||||
fn page_coordinates(&self) -> PagePoint {
|
||||
self.inner.page_coordinates()
|
||||
}
|
||||
}
|
||||
|
||||
impl ModifiersInteraction for PointerData {
|
||||
fn modifiers(&self) -> Modifiers {
|
||||
self.inner.modifiers()
|
||||
}
|
||||
}
|
||||
|
||||
impl PointerInteraction for PointerData {
|
||||
fn held_buttons(&self) -> MouseButtonSet {
|
||||
self.inner.held_buttons()
|
||||
}
|
||||
@@ -306,7 +310,7 @@ impl HasPointerData for SerializedPointerData {
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl PointInteraction for SerializedPointerData {
|
||||
impl InteractionLocation for SerializedPointerData {
|
||||
fn client_coordinates(&self) -> ClientPoint {
|
||||
self.point_data.client_coordinates()
|
||||
}
|
||||
@@ -322,11 +326,17 @@ impl PointInteraction for SerializedPointerData {
|
||||
fn page_coordinates(&self) -> PagePoint {
|
||||
self.point_data.page_coordinates()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl ModifiersInteraction for SerializedPointerData {
|
||||
fn modifiers(&self) -> Modifiers {
|
||||
self.point_data.modifiers()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
impl PointerInteraction for SerializedPointerData {
|
||||
fn held_buttons(&self) -> MouseButtonSet {
|
||||
self.point_data.held_buttons()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user