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 <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2022-02-18 17:46:57 +01:00
committed by Elias Naur
parent 27762fdd46
commit 42ea56ac44
+3 -4
View File
@@ -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
}