Skip to content

windows-reactor drag-and-drop#4540

Open
riverar wants to merge 10 commits into
masterfrom
rafael/drag_drop
Open

windows-reactor drag-and-drop#4540
riverar wants to merge 10 commits into
masterfrom
rafael/drag_drop

Conversation

@riverar

@riverar riverar commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

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.

Animation

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::drag types (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 thread crates/libs/reactor/src/core/reconciler.rs Outdated
Comment thread crates/libs/reactor/src/winui/backend/mod.rs
Comment thread crates/libs/reactor/src/winui/backend/mod.rs
Comment thread crates/libs/reactor/src/core/drag.rs
Comment thread crates/libs/reactor/src/dsl/modifiers.rs
@kennykerr kennykerr changed the title Add drag-and-drop windows-reactor drag-and-drop Jun 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.


let callback = callback.clone();
let marshaller = marshaller.clone();
std::thread::spawn(move || {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't worry about this - the app/process is responsible for COM initialization for pool threads CoIncrementMTAUsage but you should generally prefer windows-threading as it is more efficient and what windows-future uses internally.

let callback = callback.clone();
let marshaller = marshaller.clone();

std::thread::spawn(move || {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Comment on lines +3281 to +3303
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()
}));

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();
};
let size = items.Size().unwrap_or(0);
(0..size)
.filter_map(|i| items.GetAt(i).ok())
.map(|item| DroppedItem {
path: item.get_Path().unwrap_or_default(),
name: item.get_Name().unwrap_or_default(),
is_folder: item
.get_Attributes()
.is_ok_and(|a| a.contains(Xaml::FileAttributes::Directory)),
})
.collect()
}));
};
pub use super::keyboard::{KeyModifiers, KeyboardAccelerator, KeyboardKey};
pub use super::modifiers::{AttachedProps, GridPlacement, Modifiers};
pub use super::drag::{DragAsyncCallback, DragCallback, DragContext, DragNotifyCallback, DragOperation, DroppedItem};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

windows-reactor: file drag and drop

3 participants