diff options
| author | pml68 <contact@pml68.dev> | 2025-04-13 03:40:38 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.dev> | 2025-04-15 23:52:42 +0200 |
| commit | 495985f449e46b24e6b734d3aa9e135a779a8b77 (patch) | |
| tree | f2908b3a1776458e81de63c6d2461b9fc4cec13f /crates/iced_drop/src/lib.rs | |
| parent | feat(material_theme): implement `pick_list::Catalog` (diff) | |
| download | iced-builder-495985f449e46b24e6b734d3aa9e135a779a8b77.tar.gz | |
refactor: move `material_theme` and `iced_drop` into separate crates dir
Diffstat (limited to 'crates/iced_drop/src/lib.rs')
| -rw-r--r-- | crates/iced_drop/src/lib.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/crates/iced_drop/src/lib.rs b/crates/iced_drop/src/lib.rs new file mode 100644 index 0000000..c1e1b03 --- /dev/null +++ b/crates/iced_drop/src/lib.rs @@ -0,0 +1,55 @@ +pub mod widget; + +use iced::advanced::graphics::futures::MaybeSend; +use iced::advanced::renderer; +use iced::advanced::widget::{operate, Id}; +use iced::task::Task; +use iced::{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)) +} |
