project panel: Fix rendering of groups of dragged project panel entries (#20686)
This PR introduces a new parameter for `on_drag` in gpui, which is an offset from the element origin to the mouse event origin. Release Notes: - Fixed rendering of dragged project panel entries
This commit is contained in:
parent
43999c47e1
commit
56c93be4de
5 changed files with 30 additions and 17 deletions
|
@ -443,7 +443,7 @@ impl Interactivity {
|
|||
pub fn on_drag<T, W>(
|
||||
&mut self,
|
||||
value: T,
|
||||
constructor: impl Fn(&T, &mut WindowContext) -> View<W> + 'static,
|
||||
constructor: impl Fn(&T, Point<Pixels>, &mut WindowContext) -> View<W> + 'static,
|
||||
) where
|
||||
Self: Sized,
|
||||
T: 'static,
|
||||
|
@ -455,7 +455,9 @@ impl Interactivity {
|
|||
);
|
||||
self.drag_listener = Some((
|
||||
Box::new(value),
|
||||
Box::new(move |value, cx| constructor(value.downcast_ref().unwrap(), cx).into()),
|
||||
Box::new(move |value, offset, cx| {
|
||||
constructor(value.downcast_ref().unwrap(), offset, cx).into()
|
||||
}),
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -966,14 +968,15 @@ pub trait StatefulInteractiveElement: InteractiveElement {
|
|||
|
||||
/// On drag initiation, this callback will be used to create a new view to render the dragged value for a
|
||||
/// drag and drop operation. This API should also be used as the equivalent of 'on drag start' with
|
||||
/// the [`Self::on_drag_move`] API
|
||||
/// the [`Self::on_drag_move`] API.
|
||||
/// The callback also has access to the offset of triggering click from the origin of parent element.
|
||||
/// The fluent API equivalent to [`Interactivity::on_drag`]
|
||||
///
|
||||
/// See [`ViewContext::listener`](crate::ViewContext::listener) to get access to a view's state from this callback.
|
||||
fn on_drag<T, W>(
|
||||
mut self,
|
||||
value: T,
|
||||
constructor: impl Fn(&T, &mut WindowContext) -> View<W> + 'static,
|
||||
constructor: impl Fn(&T, Point<Pixels>, &mut WindowContext) -> View<W> + 'static,
|
||||
) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
|
@ -1056,7 +1059,8 @@ pub(crate) type ScrollWheelListener =
|
|||
|
||||
pub(crate) type ClickListener = Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>;
|
||||
|
||||
pub(crate) type DragListener = Box<dyn Fn(&dyn Any, &mut WindowContext) -> AnyView + 'static>;
|
||||
pub(crate) type DragListener =
|
||||
Box<dyn Fn(&dyn Any, Point<Pixels>, &mut WindowContext) -> AnyView + 'static>;
|
||||
|
||||
type DropListener = Box<dyn Fn(&dyn Any, &mut WindowContext) + 'static>;
|
||||
|
||||
|
@ -1818,7 +1822,8 @@ impl Interactivity {
|
|||
if let Some((drag_value, drag_listener)) = drag_listener.take() {
|
||||
*clicked_state.borrow_mut() = ElementClickedState::default();
|
||||
let cursor_offset = event.position - hitbox.origin;
|
||||
let drag = (drag_listener)(drag_value.as_ref(), cx);
|
||||
let drag =
|
||||
(drag_listener)(drag_value.as_ref(), cursor_offset, cx);
|
||||
cx.active_drag = Some(AnyDrag {
|
||||
view: drag,
|
||||
value: drag_value,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue