mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget: constrain drag offset to [0, 1]
Once the user begins dragging, the cursor can move outside the clip area (or even the window on at least X11), leading to events with positions that are either negative, or larger than the clip area. Negative values outright break the delta tracking and cause the scrollbar to misbehave. Positive values "only" break the invariant of Scrollbar.ScrollDistance that the returned value is in the range [-1, 1]. Signed-off-by: Dominik Honnef <dominik@honnef.co>
This commit is contained in:
committed by
Elias Naur
parent
d8766f6d2d
commit
ea37124686
@@ -74,6 +74,12 @@ func (s *Scrollbar) Layout(gtx layout.Context, axis layout.Axis, viewportStart,
|
||||
continue
|
||||
}
|
||||
dragOffset := axis.FConvert(event.Position).X
|
||||
// The user can drag outside of the constraints, or even the window. Limit dragging to within the scrollbar.
|
||||
if dragOffset < 0 {
|
||||
dragOffset = 0
|
||||
} else if dragOffset > trackHeight {
|
||||
dragOffset = trackHeight
|
||||
}
|
||||
normalizedDragOffset := dragOffset / trackHeight
|
||||
|
||||
if !s.dragging {
|
||||
|
||||
Reference in New Issue
Block a user