Skip to content

Commit

Permalink
Merge branch 'emilk:master' into patch7
Browse files Browse the repository at this point in the history
  • Loading branch information
rustbasic authored Dec 9, 2024
2 parents 81e8284 + 13352d6 commit 275fb30
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
6 changes: 5 additions & 1 deletion crates/egui-wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,14 @@ impl RenderState {
);
}

let trace_path = std::env::var("WGPU_TRACE");
let (device, queue) = {
crate::profile_scope!("request_device");
adapter
.request_device(&(*device_descriptor)(&adapter), None)
.request_device(
&(*device_descriptor)(&adapter),
trace_path.ok().as_ref().map(std::path::Path::new),
)
.await?
};

Expand Down
31 changes: 19 additions & 12 deletions crates/egui/src/drag_and_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,38 @@ impl DragAndDrop {
ctx.on_end_pass("drag_and_drop_end_pass", Arc::new(Self::end_pass));
}

/// Interrupt drag-and-drop if the user presses the escape key.
///
/// This needs to happen at frame start so we can properly capture the escape key.
fn begin_pass(ctx: &Context) {
let has_any_payload = Self::has_any_payload(ctx);

if has_any_payload {
let abort_dnd = ctx.input_mut(|i| {
i.pointer.any_released()
|| i.consume_key(crate::Modifiers::NONE, crate::Key::Escape)
});
let abort_dnd_due_to_escape_key =
ctx.input_mut(|i| i.consume_key(crate::Modifiers::NONE, crate::Key::Escape));

if abort_dnd {
if abort_dnd_due_to_escape_key {
Self::clear_payload(ctx);
}
}
}

/// Interrupt drag-and-drop if the user releases the mouse button.
///
/// This is a catch-all safety net in case user code doesn't capture the drag payload itself.
/// This must happen at end-of-frame such that we don't shadow the mouse release event from user
/// code.
fn end_pass(ctx: &Context) {
let mut is_dragging = false;
let has_any_payload = Self::has_any_payload(ctx);

ctx.data_mut(|data| {
let state = data.get_temp_mut_or_default::<Self>(Id::NULL);
is_dragging = state.payload.is_some();
});
if has_any_payload {
let abort_dnd_due_to_mouse_release = ctx.input_mut(|i| i.pointer.any_released());

if is_dragging {
ctx.set_cursor_icon(CursorIcon::Grabbing);
if abort_dnd_due_to_mouse_release {
Self::clear_payload(ctx);
} else {
ctx.set_cursor_icon(CursorIcon::Grabbing);
}
}
}

Expand Down

0 comments on commit 275fb30

Please sign in to comment.