From 42ea56ac44ea8aad8cd5106b1a50c7e42329b689 Mon Sep 17 00:00:00 2001 From: Pierre Curto Date: Fri, 18 Feb 2022 17:46:57 +0100 Subject: [PATCH] widget: adjust Draggable.Pos to be relative When dragging objects around an area, it is easier to reason with the relative movement of the dragged item. References: https://todo.sr.ht/~eliasnaur/gio/363 Signed-off-by: Pierre Curto --- widget/dnd.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/widget/dnd.go b/widget/dnd.go index bed52bc2..ba929589 100644 --- a/widget/dnd.go +++ b/widget/dnd.go @@ -35,9 +35,8 @@ func (d *Draggable) Layout(gtx layout.Context, w, drag layout.Widget) layout.Dim case pointer.Press: d.click = ev.Position pos = f32.Point{} - case pointer.Drag: + case pointer.Drag, pointer.Release: pos = ev.Position.Sub(d.click) - case pointer.Release: } } d.pos = pos @@ -97,7 +96,7 @@ func (d *Draggable) Offer(ops *op.Ops, mime string, data io.ReadCloser) { }.Add(ops) } -// Pos returns the drag position relative to its area. +// Pos returns the drag position relative to its initial click position. func (d *Draggable) Pos() f32.Point { - return d.pos.Add(d.click) + return d.pos }