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

ui.dnd_drop_zone() now returns InnerResponse. #4079

Merged
merged 1 commit into from
Feb 21, 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
10 changes: 5 additions & 5 deletions crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2223,11 +2223,11 @@ impl Ui {
///
/// The given frame is used for its margins, but it color is ignored.
#[doc(alias = "drag and drop")]
pub fn dnd_drop_zone<Payload>(
pub fn dnd_drop_zone<Payload, R>(
&mut self,
frame: Frame,
add_contents: impl FnOnce(&mut Ui),
) -> (Response, Option<Arc<Payload>>)
add_contents: impl FnOnce(&mut Ui) -> R,
) -> (InnerResponse<R>, Option<Arc<Payload>>)
where
Payload: Any + Send + Sync,
{
Expand All @@ -2236,7 +2236,7 @@ impl Ui {
DragAndDrop::has_payload_of_type::<Payload>(self.ctx());

let mut frame = frame.begin(self);
add_contents(&mut frame.content_ui);
let inner = add_contents(&mut frame.content_ui);
let response = frame.allocate_space(self);

// NOTE: we use `response.contains_pointer` here instead of `hovered`, because
Expand Down Expand Up @@ -2266,7 +2266,7 @@ impl Ui {

let payload = response.dnd_release_payload::<Payload>();

(response, payload)
(InnerResponse { inner, response }, payload)
}

/// Close the menu we are in (including submenus), if any.
Expand Down
2 changes: 1 addition & 1 deletion crates/egui_demo_lib/src/demo/drag_and_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl super::View for DragAndDropDemo {

let frame = Frame::default().inner_margin(4.0);

let (_, dropped_payload) = ui.dnd_drop_zone::<Location>(frame, |ui| {
let (_, dropped_payload) = ui.dnd_drop_zone::<Location, ()>(frame, |ui| {
ui.set_min_size(vec2(64.0, 100.0));
for (row_idx, item) in column.iter().enumerate() {
let item_id = Id::new(("my_drag_and_drop_demo", col_idx, row_idx));
Expand Down
Loading