diff options
| author | pml68 <contact@pml68.me> | 2024-10-04 00:44:02 +0200 |
|---|---|---|
| committer | pml68 <contact@pml68.me> | 2024-10-04 00:44:02 +0200 |
| commit | 510d68b92972b99868e187dd5340f04780b4c354 (patch) | |
| tree | 6d0937824d8606423b5afef2a16e182a3a984f8f /iced_drop | |
| parent | feat: implement fmt::Display for RenderedElement, work on props (diff) | |
| download | iced-builder-510d68b92972b99868e187dd5340f04780b4c354.tar.gz | |
feat: update to iced 0.13.1, basic project state file, prepare for drag&drop
Diffstat (limited to '')
| -rw-r--r-- | iced_drop/Cargo.toml | 2 | ||||
| -rw-r--r-- | iced_drop/LICENSE | 21 | ||||
| -rw-r--r-- | iced_drop/README.md | 2 | ||||
| -rw-r--r-- | iced_drop/src/lib.rs | 24 | ||||
| -rw-r--r-- | iced_drop/src/widget/droppable.rs | 8 | ||||
| -rw-r--r-- | iced_drop/src/widget/operation/drop.rs | 5 |
6 files changed, 45 insertions, 17 deletions
diff --git a/iced_drop/Cargo.toml b/iced_drop/Cargo.toml index 8b9d88c..40beeb0 100644 --- a/iced_drop/Cargo.toml +++ b/iced_drop/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies.iced] -version = "0.12.1" +version = "0.13.1" features = ["advanced"] diff --git a/iced_drop/LICENSE b/iced_drop/LICENSE new file mode 100644 index 0000000..89d9fee --- /dev/null +++ b/iced_drop/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 jhannyj + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/iced_drop/README.md b/iced_drop/README.md index 41b637b..3768d54 100644 --- a/iced_drop/README.md +++ b/iced_drop/README.md @@ -1,5 +1,7 @@ # iced_drop +# Modified to use iced 0.13.1 for compatibility + A small library which provides a custom widget and operation to make drag and drop easier to implement in [iced](https://github.com/iced-rs/iced/tree/master) ## Usage diff --git a/iced_drop/src/lib.rs b/iced_drop/src/lib.rs index fc559dc..9906cbe 100644 --- a/iced_drop/src/lib.rs +++ b/iced_drop/src/lib.rs @@ -1,8 +1,10 @@ pub mod widget; use iced::{ - advanced::{graphics::futures::MaybeSend, renderer, widget::Id}, - Command, Element, Point, Rectangle, + advanced::widget::{operate, Id}, + advanced::{graphics::futures::MaybeSend, renderer}, + task::Task, + Element, Point, Rectangle, }; use widget::droppable::*; @@ -18,17 +20,17 @@ where Droppable::new(content) } -pub fn zones_on_point<Message, MF>( +pub fn zones_on_point<T, MF>( msg: MF, point: Point, options: Option<Vec<Id>>, depth: Option<usize>, -) -> Command<Message> +) -> Task<T> where - Message: 'static, - MF: Fn(Vec<(Id, Rectangle)>) -> Message + MaybeSend + Sync + Clone + 'static, + T: Send + 'static, + MF: Fn(Vec<(Id, Rectangle)>) -> T + MaybeSend + Sync + Clone + 'static, { - Command::widget(drop::find_zones( + operate(drop::find_zones( move |bounds| bounds.contains(point), options, depth, @@ -41,11 +43,11 @@ pub fn find_zones<Message, MF, F>( filter: F, options: Option<Vec<Id>>, depth: Option<usize>, -) -> Command<Message> +) -> Task<Message> where - Message: 'static, + Message: Send + 'static, MF: Fn(Vec<(Id, Rectangle)>) -> Message + MaybeSend + Sync + Clone + 'static, - F: Fn(&Rectangle) -> bool + 'static, + F: Fn(&Rectangle) -> bool + Send + 'static, { - Command::widget(drop::find_zones(filter, options, depth)).map(move |id| msg(id)) + operate(drop::find_zones(filter, options, depth)).map(move |id| msg(id)) } diff --git a/iced_drop/src/widget/droppable.rs b/iced_drop/src/widget/droppable.rs index ed7dcbd..80d8600 100644 --- a/iced_drop/src/widget/droppable.rs +++ b/iced_drop/src/widget/droppable.rs @@ -228,8 +228,10 @@ where state.action = Action::Drag(start, position); // update the position of the overlay since the cursor was moved if self.drag_center { - state.overlay_bounds.x = position.x - state.overlay_bounds.width / 2.0; - state.overlay_bounds.y = position.y - state.overlay_bounds.height / 2.0; + state.overlay_bounds.x = + position.x - state.overlay_bounds.width / 2.0; + state.overlay_bounds.y = + position.y - state.overlay_bounds.height / 2.0; } else { state.overlay_bounds.x = state.widget_pos.x + position.x - start.x; state.overlay_bounds.y = state.widget_pos.y + position.y - start.y; @@ -315,7 +317,7 @@ where tree: &mut Tree, layout: Layout<'_>, renderer: &Renderer, - operation: &mut dyn Operation<Message>, + operation: &mut dyn Operation, ) { let state = tree.state.downcast_mut::<State>(); operation.custom(state, self.id.as_ref()); diff --git a/iced_drop/src/widget/operation/drop.rs b/iced_drop/src/widget/operation/drop.rs index 12a2e30..a76181c 100644 --- a/iced_drop/src/widget/operation/drop.rs +++ b/iced_drop/src/widget/operation/drop.rs @@ -17,7 +17,7 @@ pub fn find_zones<F>( depth: Option<usize>, ) -> impl Operation<Vec<(Id, Rectangle)>> where - F: Fn(&Rectangle) -> bool + 'static, + F: Fn(&Rectangle) -> bool + Send + 'static, { struct FindDropZone<F> { filter: F, @@ -30,7 +30,7 @@ where impl<F> Operation<Vec<(Id, Rectangle)>> for FindDropZone<F> where - F: Fn(&Rectangle) -> bool + 'static, + F: Fn(&Rectangle) -> bool + Send + 'static, { fn container( &mut self, @@ -70,6 +70,7 @@ where _state: &mut dyn Scrollable, _id: Option<&Id>, bounds: Rectangle, + _content_bounds: Rectangle, translation: Vector, ) { if (self.filter)(&bounds) { |
