add file property to drag data
This commit is contained in:
1 parent
c904411190
commit
ada246c12e
11 files changed
+133
-77
No files matched your search
@@ -1,7 +1,9 @@
|
||||
use dioxus_core::Event;
|
||||
|
||||
use crate::FileEngine;
|
||||
use crate::MouseData;
|
||||
|
||||
use dioxus_core::Event;
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub type DragEvent = Event<DragData>;
|
||||
|
||||
/// The DragEvent interface is a DOM event that represents a drag and drop interaction. The user initiates a drag by
|
||||
@@ -9,12 +11,38 @@ pub type DragEvent = Event<DragData>;
|
||||
/// (such as another DOM element). Applications are free to interpret a drag and drop interaction in an
|
||||
/// application-specific way.
|
||||
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Clone)]
|
||||
pub struct DragData {
|
||||
/// Inherit mouse data
|
||||
pub mouse: MouseData,
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
serde(
|
||||
default,
|
||||
skip_serializing,
|
||||
deserialize_with = "crate::events::deserialize_file_engine"
|
||||
)
|
||||
)]
|
||||
pub files: Option<std::sync::Arc<dyn FileEngine>>,
|
||||
}
|
||||
|
||||
impl Debug for DragData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("DragData")
|
||||
.field("mouse", &self.mouse)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for DragData {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.mouse == other.mouse
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for DragData {}
|
||||
|
||||
impl_event! {
|
||||
DragData;
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ impl FileEngine for SerializedFileEngine {
|
||||
}
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
fn deserialize_file_engine<'de, D>(
|
||||
pub(crate) fn deserialize_file_engine<'de, D>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<std::sync::Arc<dyn FileEngine>>, D::Error>
|
||||
where
|
||||
|
||||
@@ -123,6 +123,7 @@ impl From<&MouseEvent> for DragData {
|
||||
fn from(value: &MouseEvent) -> Self {
|
||||
Self {
|
||||
mouse: MouseData::from(value),
|
||||
files: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user