iced_drop

Crates.ioiced_drop
lib.rsiced_drop
version0.1.38
created_at2025-07-10 19:51:33.175744+00
updated_at2025-09-24 01:00:07.833693+00
descriptionSmall library providing a custom widget and operation to implement drag and drop in iced
homepage
repositoryhttps://github.com/pepa65/iced_drop
max_upload_size
id1746982
size124,672
pepa65 (pepa65)

documentation

README

version build dependencies docs license downloads

iced_drop 0.1.38

Small library providing a custom widget and operation to implement drag and drop in iced

Usage

To add drag and drog functionality, first define two messages with the following format:

enum Message {
	Drop(iced::Point, iced::Rectangle)
	HandleZones(Vec<(iced::advanced::widget::Id, iced::Rectangle)>)
}

The Drop message will be sent when the droppable is being dragged, and the left mouse button is released. This message provides the mouse position and layout boundaries of the droppable at the release point.

The HandleZones message will be sent after an operation that finds the drop zones under the mouse position. It provides the Id and bounds for each drop zone.

Next, create create a droppable in the view method and assign the on_drop message. The dropopable function takes an impl Into<Element> object, so it's easy to make a droppable from any iced widget.

iced_drop::droppable("Drop me!").on_drop(Message::Drop);

Next, create a "drop zone." A drop zone is any widget that operates like a container andhas some assigned Id. It's important that the widget is assigned some Id or it won't be recognized as a drop zone.

iced::widget::container("Drop zone")
	.id(iced::widget::container::Id::new("drop_zone"));

Finally, handle the updates of the drop messages

match message {
	Message::Drop(cursor_pos, _) => {
		return iced_drop::zones_on_point(
			Message::HandleZonesFound,
			point,
			None,
			None,
		);
	}
	Message::HandleZones(zones) => {
		println!("{:?}", zones)
	}
}

On Drop, we return a widget operation that looks for drop zones under the cursor_pos. When this operation finishes, it returns the zones found and sends the HandleZones message. In this example, we only defined one zone, so the zones vector will either be empty if the droppable was not dropped on the zone, or it will contain the drop_zone

Future Development

Right now it's a little annoying having to work with iced's Id type. At some point, I will work on a drop_zone widget that can take some generic clonable type as an id, and I will create a seperate find_zones operation that will return a list of this custom Id. This should make it easier to determine which drop zones were found.

Commit count: 70

cargo fmt