From 7ec9cc08c77aba48b8963c2eca663afbcbbc27e0 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 25 Oct 2023 20:49:40 +0200 Subject: [PATCH] Fix z-index targeting for drag and drop --- crates/gpui2/src/interactive.rs | 4 ++-- crates/gpui2/src/platform/mac/window.rs | 6 +++--- crates/gpui2/src/window.rs | 4 ++-- crates/ui2/src/components/panes.rs | 20 +++++++++++++------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/crates/gpui2/src/interactive.rs b/crates/gpui2/src/interactive.rs index 60869d7eebcec5e478bb50d465d812770b307182..fd603eda460765f12800374433f41b2289ef5bb5 100644 --- a/crates/gpui2/src/interactive.rs +++ b/crates/gpui2/src/interactive.rs @@ -1033,13 +1033,13 @@ impl Deref for MouseExitEvent { } #[derive(Debug, Clone, Default)] -pub struct DroppedFiles(pub(crate) SmallVec<[PathBuf; 2]>); +pub struct ExternalPaths(pub(crate) SmallVec<[PathBuf; 2]>); #[derive(Debug, Clone)] pub enum FileDropEvent { Entered { position: Point, - files: DroppedFiles, + files: ExternalPaths, }, Pending { position: Point, diff --git a/crates/gpui2/src/platform/mac/window.rs b/crates/gpui2/src/platform/mac/window.rs index 46f96043f2ec976e81ed51726e04166dd7ef1162..babf8aece37dfe5ff6e08aaeb894d1b9b7804a49 100644 --- a/crates/gpui2/src/platform/mac/window.rs +++ b/crates/gpui2/src/platform/mac/window.rs @@ -1,6 +1,6 @@ use super::{display_bounds_from_native, ns_string, MacDisplay, MetalRenderer, NSRange}; use crate::{ - display_bounds_to_native, point, px, size, AnyWindowHandle, Bounds, DroppedFiles, Executor, + display_bounds_to_native, point, px, size, AnyWindowHandle, Bounds, ExternalPaths, Executor, FileDropEvent, GlobalPixels, InputEvent, KeyDownEvent, Keystroke, Modifiers, ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point, Scene, Size, @@ -1679,7 +1679,7 @@ extern "C" fn perform_drag_operation(this: &Object, _: Sel, dragging_info: id) - } } -fn external_paths_from_event(dragging_info: *mut Object) -> DroppedFiles { +fn external_paths_from_event(dragging_info: *mut Object) -> ExternalPaths { let mut paths = SmallVec::new(); let pasteboard: id = unsafe { msg_send![dragging_info, draggingPasteboard] }; let filenames = unsafe { NSPasteboard::propertyListForType(pasteboard, NSFilenamesPboardType) }; @@ -1690,7 +1690,7 @@ fn external_paths_from_event(dragging_info: *mut Object) -> DroppedFiles { }; paths.push(PathBuf::from(path)) } - DroppedFiles(paths) + ExternalPaths(paths) } extern "C" fn conclude_drag_operation(this: &Object, _: Sel, _: id) { diff --git a/crates/gpui2/src/window.rs b/crates/gpui2/src/window.rs index 2822e44d3fc83ce0c330954db5ee3e5450890371..8b3aa7a11768c9177e81fbd48f4cc2e744b5daa6 100644 --- a/crates/gpui2/src/window.rs +++ b/crates/gpui2/src/window.rs @@ -1,6 +1,6 @@ use crate::{ px, size, Action, AnyBox, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace, - Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, DroppedFiles, + Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, ExternalPaths, Edges, Effect, Element, EntityId, EventEmitter, FileDropEvent, FocusEvent, FontId, GlobalElementId, GlyphId, Handle, Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch, KeyMatcher, Keystroke, LayoutId, MainThread, MainThreadOnly, Modifiers, MonochromeSprite, @@ -903,7 +903,7 @@ impl<'a, 'w> WindowContext<'a, 'w> { drag_handle_view: None, cursor_offset: position, state: Box::new(files), - state_type: TypeId::of::(), + state_type: TypeId::of::(), }); InputEvent::MouseDown(MouseDownEvent { position, diff --git a/crates/ui2/src/components/panes.rs b/crates/ui2/src/components/panes.rs index 1c60520c033048929017679e98bc79a37f45ee27..77b6817d89f2da35d24976ea4b3f5228ae6c3f39 100644 --- a/crates/ui2/src/components/panes.rs +++ b/crates/ui2/src/components/panes.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use gpui2::{hsla, red, AnyElement, DroppedFiles, ElementId, Hsla, Length, Size}; +use gpui2::{hsla, red, AnyElement, ElementId, ExternalPaths, Hsla, Length, Size}; use smallvec::SmallVec; use crate::prelude::*; @@ -49,18 +49,24 @@ impl Pane { .w(self.size.width) .h(self.size.height) .relative() - .children(cx.stack(0, |_| self.children.drain(..))) - .child(cx.stack(1, |_| { + .child( + div() + .z_index(0) + .size_full() + .children(self.children.drain(..)), + ) + .child( // TODO kb! Figure out why we can't we see the red background when we drag a file over this div. div() + .z_index(1) .id("drag-target") - .drag_over::(|d| d.bg(red())) - .on_drop(|_, files: DroppedFiles, _| { + .drag_over::(|d| d.bg(red())) + .on_drop(|_, files: ExternalPaths, _| { dbg!("dropped files!", files); }) .absolute() - .inset_0() - })) + .inset_0(), + ) } }