From fd45eea366817b6082de04e8b3e08ce9c02270d8 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler Date: Tue, 23 Jan 2024 21:17:24 +0100 Subject: [PATCH 1/2] Improve drag-and-drop-related APIs in `Response` and `Memory` --- crates/egui/src/memory.rs | 6 ++++++ crates/egui/src/response.rs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index 7cd8e82020f..213d9c8b6a0 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -703,6 +703,12 @@ impl Memory { self.interaction().drag_id == Some(id) } + /// Get the id of the widget being dragged, if any. + #[inline(always)] + pub fn dragged_id(&self) -> Option { + self.interaction().drag_id + } + /// Set which widget is being dragged. #[inline(always)] pub fn set_dragged_id(&mut self, id: Id) { diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index 02d908d9723..651a7025115 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -309,6 +309,14 @@ impl Response { self.dragged } + /// The Widget is being decidedly dragged. + /// + /// This helper function checks both the output of [`dragged`] and [`crate::PointerState::is_decidedly_dragging`]. + #[inline] + pub fn decidedly_dragged(&self) -> bool { + self.dragged() && self.ctx.input(|i| i.pointer.is_decidedly_dragging()) + } + #[inline] pub fn dragged_by(&self, button: PointerButton) -> bool { self.dragged() && self.ctx.input(|i| i.pointer.button_down(button)) From 91670ccb059c59a92ca0ab1887cae403dfb9da34 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler Date: Tue, 23 Jan 2024 21:21:44 +0100 Subject: [PATCH 2/2] Fixed doc link --- crates/egui/src/response.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index 651a7025115..108a24d9340 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -311,7 +311,7 @@ impl Response { /// The Widget is being decidedly dragged. /// - /// This helper function checks both the output of [`dragged`] and [`crate::PointerState::is_decidedly_dragging`]. + /// This helper function checks both the output of [`Self::dragged`] and [`crate::PointerState::is_decidedly_dragging`]. #[inline] pub fn decidedly_dragged(&self) -> bool { self.dragged() && self.ctx.input(|i| i.pointer.is_decidedly_dragging())