Drag-Drop

drag-drop feature is used to enable system drag-drop events. After enabling, views can receive drag enter, hover, leave and release through event builder.

[dependencies]
flor = { version = "0.1.0", features = ["direct2d", "drag-drop"] }

Basic Usage

Drag-drop is event capability, entry in Event Builder.

use flor::base::platform::DropEffect;
use flor::view::builder::EventBuilder;
use flor_lys::label::label;

let drop_area = label("Drag Here")
    .on_drag_enter(|_view_id, _key_state, _pos, formats, effect| {
        if formats.iter().any(|format| matches!(format, flor::base::platform::DragFormat::Files(_))) {
            *effect = DropEffect::Copy;
        }
    })
    .on_drop(|_view_id, _key_state, _pos, data, effect| {
        println!("{data:?}");
        *effect = DropEffect::Copy;
    });

Events:

MethodPurpose
on_drag_enter(...)Drag content enters view hit area.
on_drag_over(...)Drag content moves on view.
on_drag_leave(...)Drag content leaves view.
on_drop(...)User releases drag content.

Complete signature and current dispatch status see Handler API's Drag-Drop Events.

Drag-drop events will directly encounter these types:

TypePurpose
DropEffectView's drag-drop feedback to system, indicating whether the current state is reject, copy, move, link, etc.
DragFormatData formats available in the drag enter and hover phase, used to determine what type of content is being dragged in.
DragDataReal data obtained in the on_drop(...) phase.
KeyStateMouse button and modifier key state when drag-drop occurs.
MousePositionMouse coordinates when drag-drop occurs.

on_drag_enter(...) and on_drag_over(...) get &[DragFormat], suitable for first checking whether the data can be accepted; on_drop(...) gets &DragData, suitable for reading the real data.

DropEffect

DropEffect is used to tell the system how the current view intends to handle the drag content. Values include:

ValueMeaning
DropEffect::NoneNot accept.
DropEffect::CopyAccept, and indicates copy.
DropEffect::MoveAccept, and indicates move.
DropEffect::LinkAccept, and indicates create link.
DropEffect::ScrollIndicates scroll feedback occurred during drag-drop.

In on_drag_enter, on_drag_over and on_drop can modify feedback through &mut DropEffect.

DragFormat and DragData

DragFormat is used in the enter and hover phase, indicating what formats the current drag object declares it can provide:

ValueMeaning
DragFormat::Files(_)File drag-drop.
DragFormat::Text(_)Text drag-drop.
DragFormat::Image(_)Image drag-drop.
DragFormat::Custom(_)Platform or application custom format.

DragData is used in the final release phase, indicating the real data handed to the view:

ValueMeaning
DragData::NoneNo available data.
DragData::Files(paths)File path list.
DragData::Text(text)Text content.
DragData::Image(bytes)Image byte data.
DragData::Raw(value)Platform raw data, used for extension scenarios.