gpui: Keep drag cursor style when dragging (#24797)

Release Notes:

- Improve to keep drag cursor style on dragging resize handles.

---

### Before


https://github.com/user-attachments/assets/d4100d01-ac02-42b8-b923-9f2b4633c458

### After


https://github.com/user-attachments/assets/b5a450cd-c6de-4b39-a79c-2d73fcbad209

With example:

```
cargo run -p gpui --example drag_drop
```


https://github.com/user-attachments/assets/4cba1966-1578-40ce-a435-64ec11bcace5
This commit is contained in:
Jason Lee
2025-04-10 23:54:12 +00:00
committed by GitHub
parent a2a3d1a4bd
commit fd256d159d
4 changed files with 153 additions and 5 deletions
+7 -4
View File
@@ -31,10 +31,10 @@ use util::ResultExt;
use crate::{
Action, ActionBuildError, ActionRegistry, Any, AnyView, AnyWindowHandle, AppContext, Asset,
AssetSource, BackgroundExecutor, Bounds, ClipboardItem, DispatchPhase, DisplayId, EventEmitter,
FocusHandle, FocusMap, ForegroundExecutor, Global, KeyBinding, Keymap, Keystroke, LayoutId,
Menu, MenuItem, OwnedMenu, PathPromptOptions, Pixels, Platform, PlatformDisplay, Point,
PromptBuilder, PromptHandle, PromptLevel, Render, RenderablePromptHandle, Reservation,
AssetSource, BackgroundExecutor, Bounds, ClipboardItem, CursorStyle, DispatchPhase, DisplayId,
EventEmitter, FocusHandle, FocusMap, ForegroundExecutor, Global, KeyBinding, Keymap, Keystroke,
LayoutId, Menu, MenuItem, OwnedMenu, PathPromptOptions, Pixels, Platform, PlatformDisplay,
Point, PromptBuilder, PromptHandle, PromptLevel, Render, RenderablePromptHandle, Reservation,
ScreenCaptureSource, SharedString, SubscriberSet, Subscription, SvgRenderer, Task, TextSystem,
Window, WindowAppearance, WindowHandle, WindowId, WindowInvalidator, current_platform, hash,
init_app_menus,
@@ -1803,6 +1803,9 @@ pub struct AnyDrag {
/// This is used to render the dragged item in the same place
/// on the original element that the drag was initiated
pub cursor_offset: Point<Pixels>,
/// The cursor style to use while dragging
pub cursor_style: Option<CursorStyle>,
}
/// Contains state associated with a tooltip. You'll only need this struct if you're implementing
+8 -1
View File
@@ -1615,7 +1615,11 @@ impl Interactivity {
global_id, hitbox, &style, window, cx,
);
if !cx.has_active_drag() {
if let Some(drag) = cx.active_drag.as_ref() {
if let Some(mouse_cursor) = drag.cursor_style {
window.set_cursor_style(mouse_cursor, None);
}
} else {
if let Some(mouse_cursor) = style.mouse_cursor {
window.set_cursor_style(mouse_cursor, Some(hitbox));
}
@@ -1838,6 +1842,7 @@ impl Interactivity {
}
});
}
let drag_cursor_style = self.base_style.as_ref().mouse_cursor;
let mut drag_listener = mem::take(&mut self.drag_listener);
let drop_listeners = mem::take(&mut self.drop_listeners);
@@ -1929,6 +1934,7 @@ impl Interactivity {
view: drag,
value: drag_value,
cursor_offset,
cursor_style: drag_cursor_style,
});
pending_mouse_down.take();
window.refresh();
@@ -2269,6 +2275,7 @@ impl Interactivity {
}
}
style.mouse_cursor = drag.cursor_style;
cx.active_drag = Some(drag);
}
}
+1
View File
@@ -3093,6 +3093,7 @@ impl Window {
value: Arc::new(paths.clone()),
view: cx.new(|_| paths).into(),
cursor_offset: position,
cursor_style: None,
});
}
PlatformInput::MouseMove(MouseMoveEvent {