Add drag-and-drop#4540
Open
riverar wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class drag-and-drop support to the windows-reactor core/WinUI backend by introducing drag/drop APIs in the DSL and wiring them to WinUI UIElement drag events, enabling apps to accept dropped data (e.g., Explorer file drops).
Changes:
- Introduces
core::dragtypes (DragContext,DragOperation, handlers) and exposes them through the element API. - Adds DSL modifiers for drop targets and drag event handlers, and wires them through the reconciler into the WinUI backend.
- Updates WinUI bindings and adds a minimal sample demonstrating file drop.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/tools/bindings/src/reactor.txt | Adds WinUI drag/drop-related types/events to the bindings input list. |
| crates/tests/libs/reactor_selftest/src/bindings.rs | Updates generated selftest bindings to include drag/drop-related WinRT/WinUI APIs. |
| crates/samples/reactor/minimal/examples/drag_drop.rs | New sample demonstrating .allow_drop and drag/drop handlers. |
| crates/libs/reactor/src/winui/backend/mod.rs | Implements AllowDrop prop mapping + attaches WinUI drag event handlers and builds drag context. |
| crates/libs/reactor/src/dsl/modifiers.rs | Adds .allow_drop, .drag_* DSL methods and drag handler storage. |
| crates/libs/reactor/src/core/reconciler.rs | Applies/diffs AllowDrop and drag handlers into the backend. |
| crates/libs/reactor/src/core/modifiers.rs | Extends Modifiers with allow_drop + drag_handlers and updates is_empty(). |
| crates/libs/reactor/src/core/mod.rs | Registers the new internal drag module. |
| crates/libs/reactor/src/core/element.rs | Re-exports drag types from core::drag for consumer use. |
| crates/libs/reactor/src/core/drag.rs | New core drag/drop API surface (context, operations, callbacks, handler set). |
| crates/libs/reactor/src/core/backend.rs | Adds Prop::AllowDrop and Backend::set_drag_handlers hook. |
| crates/libs/reactor/src/bindings.rs | Updates generated reactor bindings to include drag/drop-related WinRT/WinUI APIs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+4282
to
+4286
| let dv_text = dv.clone(); | ||
| ctx.get_text_fn = Some(Box::new(move || { | ||
| let h = dv_text.GetTextAsync().ok()?.join().ok()?; | ||
| String::try_from(&h).ok() | ||
| })); |
Comment on lines
+4288
to
+4292
| ctx.get_storage_items_fn = Some(Box::new(move || { | ||
| let items = dv.GetStorageItemsAsync().ok().and_then(|op| op.join().ok()); | ||
| let Some(items) = items else { | ||
| return Vec::new(); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for drag-and-drop operations in the reactor core, including new APIs for configuring drag handlers and enabling drop targets on UI elements.
Sample:
border // ... .allow_drop(true) .drag_enter({ let set_hovering = set_hovering.clone(); move |ctx| { if ctx.has_storage_items { set_hovering.call(true); DragOperation::Link } else { DragOperation::None } } }) .drag_leave({ let set_hovering = set_hovering.clone(); move |_ctx| set_hovering.call(false) }) .drag_open(|ctx| { if ctx.has_storage_items { DragOperation::Link } else { DragOperation::None } }) .drag_drop({ move |ctx| { set_hovering.call(false); if let Some(item) = ctx.get_storage_items().into_iter().next() { set_dropped_path.call(Some(item.path)); DragOperation::Link } else { DragOperation::None } } }) .into() }Fixes #4537.