Skip to content

Commit

Permalink
Better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 25, 2024
1 parent 375fc39 commit f2eeacf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions crates/egui/src/drag_and_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ impl DragAndDrop {
/// Set a drag-and-drop payload.
///
/// This can be read by [`Self::payload`] until the pointer is released.
pub fn set_payload<T>(ctx: &Context, payload: T)
pub fn set_payload<Payload>(ctx: &Context, payload: Payload)
where
T: Any + Send + Sync,
Payload: Any + Send + Sync,
{
ctx.data_mut(|data| {
let state = data.get_temp_mut_or_default::<Self>(Id::NULL);
Expand All @@ -56,9 +56,9 @@ impl DragAndDrop {
///
/// Returns `Some` both during a drag and on the frame the pointer is released
/// (if there is a payload).
pub fn payload<T>(ctx: &Context) -> Option<Arc<T>>
pub fn payload<Payload>(ctx: &Context) -> Option<Arc<Payload>>
where
T: Any + Send + Sync,
Payload: Any + Send + Sync,
{
ctx.data(|data| {
let state = data.get_temp::<Self>(Id::NULL)?;
Expand All @@ -71,11 +71,11 @@ impl DragAndDrop {
///
/// Returns `true` both during a drag and on the frame the pointer is released
/// (if there is a payload).
pub fn has_payload_of_type<T>(ctx: &Context) -> bool
pub fn has_payload_of_type<Payload>(ctx: &Context) -> bool
where
T: Any + Send + Sync,
Payload: Any + Send + Sync,
{
Self::payload::<T>(ctx).is_some()
Self::payload::<Payload>(ctx).is_some()
}

/// Are we carrying a payload?
Expand Down
10 changes: 5 additions & 5 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl Response {

/// If the user started dragging this widget this frame, store the payload for drag-and-drop.
#[doc(alias = "drag and drop")]
pub fn dnd_set_drag_payload<T: Any + Send + Sync>(&self, payload: T) {
pub fn dnd_set_drag_payload<Payload: Any + Send + Sync>(&self, payload: Payload) {
if self.drag_started() {
crate::DragAndDrop::set_payload(&self.ctx, payload);
}
Expand All @@ -346,11 +346,11 @@ impl Response {
/// Only returns something if [`Self::contains_pointer`] is true,
/// and the user is drag-dropping something of this type.
#[doc(alias = "drag and drop")]
pub fn dnd_hover_payload<T: Any + Send + Sync>(&self) -> Option<Arc<T>> {
pub fn dnd_hover_payload<Payload: Any + Send + Sync>(&self) -> Option<Arc<Payload>> {
// NOTE: we use `response.contains_pointer` here instead of `hovered`, because
// `hovered` is always false when another widget is being dragged.
if self.contains_pointer() {
crate::DragAndDrop::payload::<T>(&self.ctx)
crate::DragAndDrop::payload::<Payload>(&self.ctx)
} else {
None
}
Expand All @@ -362,11 +362,11 @@ impl Response {
/// the user is drag-dropping something of this type,
/// and they released it this frame
#[doc(alias = "drag and drop")]
pub fn dnd_release_payload<T: Any + Send + Sync>(&self) -> Option<Arc<T>> {
pub fn dnd_release_payload<Payload: Any + Send + Sync>(&self) -> Option<Arc<Payload>> {
// NOTE: we use `response.contains_pointer` here instead of `hovered`, because
// `hovered` is always false when another widget is being dragged.
if self.contains_pointer() && self.ctx.input(|i| i.pointer.any_released()) {
crate::DragAndDrop::payload::<T>(&self.ctx)
crate::DragAndDrop::payload::<Payload>(&self.ctx)
} else {
None
}
Expand Down

0 comments on commit f2eeacf

Please sign in to comment.