widget/material: ensure scrollbars can be dragged from list end

The scrollbar implementation prior to this change only adjusted
list.Position.Offset. This works in all circumstances except when
list.Position.BeforeEnd=false. If the position indicates that the
scroll position is at the end of the list, the offset is ignored.

This change ensures that manually dragging the scrollbar always
causes BeforeEnd to be set to true. If the drag ends with the
scrollbar at the end of the list, BeforeEnd will be set
automatically by the next list.Layout call, so this doesn't
prevent the list from optimizing for that case in general.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2021-07-07 09:46:10 -04:00
committed by Elias Naur
parent 941aeaae91
commit 0e60935856
+5
View File
@@ -279,6 +279,11 @@ func (l ListStyle) Layout(gtx layout.Context, length int, w layout.ListElement)
// with the scrollbar.
deltaPx := int(math.Round(float64(float32(l.state.Position.Length) * delta)))
l.state.List.Position.Offset += deltaPx
// Ensure that the list pays attention to the Offset field when the scrollbar drag
// is started while the bar is at the end of the list. Without this, the scrollbar
// cannot be dragged away from the end.
l.state.List.Position.BeforeEnd = true
}
return listDims