diff options
| author | Polesznyák Márk László <116908301+pml68@users.noreply.github.com> | 2024-10-24 23:18:46 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-24 23:18:46 +0200 |
| commit | b351dd45dcd4b4c9142f069c62b51159c00922bf (patch) | |
| tree | d2f24b449c3f82a9f844ce35198bad351c2ca8af /iced_drop/src/lib.rs | |
| parent | Merge pull request #1 from pml68/feat/codegen (diff) | |
| parent | feat: implement d&d for existing elements (diff) | |
| download | iced-builder-b351dd45dcd4b4c9142f069c62b51159c00922bf.tar.gz | |
Merge pull request #2 from pml68/feat/drag-and-drop
Drag & Drop done
Diffstat (limited to 'iced_drop/src/lib.rs')
| -rw-r--r-- | iced_drop/src/lib.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/iced_drop/src/lib.rs b/iced_drop/src/lib.rs new file mode 100644 index 0000000..9906cbe --- /dev/null +++ b/iced_drop/src/lib.rs @@ -0,0 +1,53 @@ +pub mod widget; + +use iced::{ + advanced::widget::{operate, Id}, + advanced::{graphics::futures::MaybeSend, renderer}, + task::Task, + Element, Point, Rectangle, +}; + +use widget::droppable::*; +use widget::operation::drop; + +pub fn droppable<'a, Message, Theme, Renderer>( + content: impl Into<Element<'a, Message, Theme, Renderer>>, +) -> Droppable<'a, Message, Theme, Renderer> +where + Message: Clone, + Renderer: renderer::Renderer, +{ + Droppable::new(content) +} + +pub fn zones_on_point<T, MF>( + msg: MF, + point: Point, + options: Option<Vec<Id>>, + depth: Option<usize>, +) -> Task<T> +where + T: Send + 'static, + MF: Fn(Vec<(Id, Rectangle)>) -> T + MaybeSend + Sync + Clone + 'static, +{ + operate(drop::find_zones( + move |bounds| bounds.contains(point), + options, + depth, + )) + .map(move |id| msg(id)) +} + +pub fn find_zones<Message, MF, F>( + msg: MF, + filter: F, + options: Option<Vec<Id>>, + depth: Option<usize>, +) -> Task<Message> +where + Message: Send + 'static, + MF: Fn(Vec<(Id, Rectangle)>) -> Message + MaybeSend + Sync + Clone + 'static, + F: Fn(&Rectangle) -> bool + Send + 'static, +{ + operate(drop::find_zones(filter, options, depth)).map(move |id| msg(id)) +} |
