datatransfer object, drag_and_drop example, fix drag-and-drop (#4789)

* wip: implement datatransfer

* Editable kanban contents

* desktop sorta works without crashing

* lint
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2025-10-15 01:06:13 -07:00
1 parent 7856679641
commit 0aa7351473
13 files changed
+562 -122

No files matched your search

+12 -2
View File
@@ -11,8 +11,9 @@ use dioxus_html::{
point_interaction::{
InteractionElementOffset, InteractionLocation, ModifiersInteraction, PointerInteraction,
},
FileData, FormValue, HasDragData, HasFileData, HasFormData, HasMouseData, NativeFileData,
SerializedFormData, SerializedFormObject, SerializedMouseData, SerializedPointInteraction,
FileData, FormValue, HasDataTransferData, HasDragData, HasFileData, HasFormData, HasMouseData,
NativeFileData, SerializedDataTransfer, SerializedFormData, SerializedFormObject,
SerializedMouseData, SerializedPointInteraction,
};
use serde::{Deserialize, Serialize};
@@ -234,6 +235,7 @@ impl NativeFileHover {
#[derive(Clone)]
pub(crate) struct DesktopFileDragEvent {
pub mouse: SerializedPointInteraction,
pub data_transfer: SerializedDataTransfer,
pub files: Vec<PathBuf>,
}
@@ -247,6 +249,12 @@ impl HasFileData for DesktopFileDragEvent {
}
}
impl HasDataTransferData for DesktopFileDragEvent {
fn data_transfer(&self) -> dioxus_html::DataTransfer {
dioxus_html::DataTransfer::new(self.data_transfer.clone())
}
}
impl HasDragData for DesktopFileDragEvent {
fn as_any(&self) -> &dyn std::any::Any {
self
@@ -389,3 +397,5 @@ impl NativeFileData for DesktopFileData {
)
}
}
pub struct DesktopDataTransfer {}
+6 -5
View File
@@ -155,16 +155,17 @@ impl WebviewEdits {
}
dioxus_html::EventData::Drag(ref drag) => {
// we want to override this with a native file engine, provided by the most recent drag event
let file_event = hovered_file.current().unwrap();
let paths = match file_event {
wry::DragDropEvent::Enter { paths, .. } => paths,
wry::DragDropEvent::Drop { paths, .. } => paths,
let file_event = hovered_file.current();
let file_paths = match file_event {
Some(wry::DragDropEvent::Enter { paths, .. }) => paths,
Some(wry::DragDropEvent::Drop { paths, .. }) => paths,
_ => vec![],
};
Rc::new(PlatformEventData::new(Box::new(DesktopFileDragEvent {
mouse: drag.mouse.clone(),
files: paths,
data_transfer: drag.data_transfer.clone(),
files: file_paths,
})))
}
_ => data.into_any(),