Skip to content

Add drag-and-drop#4540

Open
riverar wants to merge 1 commit into
masterfrom
rafael/drag_drop
Open

Add drag-and-drop#4540
riverar wants to merge 1 commit into
masterfrom
rafael/drag_drop

Conversation

@riverar
Copy link
Copy Markdown
Collaborator

@riverar riverar commented Jun 6, 2026

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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
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();
};
Comment thread crates/libs/reactor/src/core/drag.rs
Comment thread crates/libs/reactor/src/dsl/modifiers.rs
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

2 participants