forked from joejulian/gio
widget: move scrollbar indicator if dragging starts outside of it
Signed-off-by: Dominik Honnef <dominik@honnef.co>
This commit is contained in:
committed by
Elias Naur
parent
f229601e2d
commit
6981a88720
@@ -87,7 +87,22 @@ func (s *Scrollbar) Layout(gtx layout.Context, axis layout.Axis, viewportStart,
|
|||||||
if !s.dragging {
|
if !s.dragging {
|
||||||
s.dragging = true
|
s.dragging = true
|
||||||
s.oldDragPos = normalizedDragOffset
|
s.oldDragPos = normalizedDragOffset
|
||||||
|
|
||||||
|
if normalizedDragOffset < viewportStart || normalizedDragOffset > viewportEnd {
|
||||||
|
// The user started dragging somewhere on the track that isn't covered by the indicator. Consider this a
|
||||||
|
// click in addition to a drag and jump to the clicked point.
|
||||||
|
//
|
||||||
|
// TODO(dh): this isn't perfect. We only get the pointer.Drag event once the user has actually dragged,
|
||||||
|
// which means that if the user presses the mouse button and neither releases it nor drags it, nothing
|
||||||
|
// will happen.
|
||||||
|
pos := axis.Convert(image.Point{
|
||||||
|
X: int(event.Position.X),
|
||||||
|
Y: int(event.Position.Y),
|
||||||
|
})
|
||||||
|
normalizedPos := float32(pos.X) / trackHeight
|
||||||
|
s.delta += normalizedPos - viewportStart
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
s.delta += normalizedDragOffset - s.oldDragPos
|
s.delta += normalizedDragOffset - s.oldDragPos
|
||||||
|
|
||||||
if viewportStart+s.delta < 0 {
|
if viewportStart+s.delta < 0 {
|
||||||
@@ -103,6 +118,7 @@ func (s *Scrollbar) Layout(gtx layout.Context, axis layout.Axis, viewportStart,
|
|||||||
}
|
}
|
||||||
s.oldDragPos = normalizedDragOffset
|
s.oldDragPos = normalizedDragOffset
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Process events from the indicator so that hover is
|
// Process events from the indicator so that hover is
|
||||||
// detected properly.
|
// detected properly.
|
||||||
|
|||||||
Reference in New Issue
Block a user