Update mouse position during file drag and drop

This commit is contained in:
Kirill Bulatov 2023-10-26 13:50:35 +02:00
parent a4b7e3c9f6
commit 0a04c5734b
2 changed files with 20 additions and 14 deletions

View file

@ -1,7 +1,7 @@
use crate::{
px, size, Action, AnyBox, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace,
Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, ExternalPaths,
Edges, Effect, Element, EntityId, EventEmitter, FileDropEvent, FocusEvent, FontId,
Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, Edges, Effect,
Element, EntityId, EventEmitter, ExternalPaths, FileDropEvent, FocusEvent, FontId,
GlobalElementId, GlyphId, Handle, Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch,
KeyMatcher, Keystroke, LayoutId, MainThread, MainThreadOnly, Modifiers, MonochromeSprite,
MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas,
@ -899,6 +899,7 @@ impl<'a, 'w> WindowContext<'a, 'w> {
}
InputEvent::FileDrop(file_drop) => match file_drop {
FileDropEvent::Entered { position, files } => {
self.window.mouse_position = position;
self.active_drag.get_or_insert_with(|| AnyDrag {
drag_handle_view: None,
cursor_offset: position,
@ -912,17 +913,23 @@ impl<'a, 'w> WindowContext<'a, 'w> {
modifiers: Modifiers::default(),
})
}
FileDropEvent::Pending { position } => InputEvent::MouseMove(MouseMoveEvent {
position,
pressed_button: Some(MouseButton::Left),
modifiers: Modifiers::default(),
}),
FileDropEvent::Submit { position } => InputEvent::MouseUp(MouseUpEvent {
button: MouseButton::Left,
position,
modifiers: Modifiers::default(),
click_count: 1,
}),
FileDropEvent::Pending { position } => {
self.window.mouse_position = position;
InputEvent::MouseMove(MouseMoveEvent {
position,
pressed_button: Some(MouseButton::Left),
modifiers: Modifiers::default(),
})
}
FileDropEvent::Submit { position } => {
self.window.mouse_position = position;
InputEvent::MouseUp(MouseUpEvent {
button: MouseButton::Left,
position,
modifiers: Modifiers::default(),
click_count: 1,
})
}
FileDropEvent::Exited => InputEvent::MouseUp(MouseUpEvent {
button: MouseButton::Left,
position: Point::default(),