mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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:
+3
-4
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user