ui::DataPackage¶
Header: winui/ui/DragDrop.hpp.
What a drag carries: text, files and an application-defined payload, such as a ListView's dragged item indices or a TreeView's node path.
The source fills it in and hands it to DragDrop::start(). A drop target reads it through DragEventArgs::data. Nothing is serialized, so data can hold any copyable C++ value. Files and text dragged in from the file manager or another app arrive through the same drop events while they move over the window. Their package has only files and text set, and no source. The caption a target answers with shows under the file manager's drag image.
Example:
void start_row_drag(ui::Element& row, ui::Point pointer)
{
ui::DataPackage package;
package.text = "Ada Lovelace";
package.data = std::size_t{3}; // the dragged row, read back with std::any_cast
package.requested_operation = ui::DataPackageOperation::Copy;
ui::RenderRecording visual; // what follows the pointer
row.render(visual);
ui::DragDrop::start(row, std::move(package), std::move(visual), row.bounds(), pointer);
}
| Field | Type | Default | |
|---|---|---|---|
text |
std::string |
Plain text for targets that only understand text. | |
files |
std::vector<std::filesystem::path> |
Paths of the files being dragged: what a drop from the file manager carries. | |
data |
std::any |
The application's own payload; the target recovers it with std::any_cast. |
|
requested_operation |
DataPackageOperation |
DataPackageOperation::Move |
What the source would like done with it; a target may accept something else. |
source |
const Element* |
nullptr |
The element the drag started from. DragDrop::start() fills it in; a target compares it to tell a reorder within itself from a drop from elsewhere. |