Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some drag-and-drop-related APIs in Response and Memory #3876

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/egui/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Id> {
self.interaction().drag_id
}

/// Set which widget is being dragged.
#[inline(always)]
pub fn set_dragged_id(&mut self, id: Id) {
Expand Down
8 changes: 8 additions & 0 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ impl Response {
self.dragged
}

/// The Widget is being decidedly dragged.
///
/// 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())
}

#[inline]
pub fn dragged_by(&self, button: PointerButton) -> bool {
self.dragged() && self.ctx.input(|i| i.pointer.button_down(button))
Expand Down
Loading