mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
layout,gesture: add option to handle vertical scroll on horizontal list
Previously, it was impossible to scroll a Axis == Horizontal using ordinary mouse-wheel. Now, it's possible to set ScrollAnyAxis == True, which combine scrolling from any direction. That makes possible to scroll Horizontal lists with vertical mouse-wheel. By default this option is false, keeping the old behaviour. Signed-off-by: inkeliz <inkeliz@inkeliz.com>
This commit is contained in:
+11
-2
@@ -29,6 +29,8 @@ type List struct {
|
||||
ScrollToEnd bool
|
||||
// Alignment is the cross axis alignment of list elements.
|
||||
Alignment Alignment
|
||||
// ScrollAnyAxis allows any scroll axis to scroll the list, not just the main axis.
|
||||
ScrollAnyAxis bool
|
||||
|
||||
cs Constraints
|
||||
scroll gesture.Scroll
|
||||
@@ -159,12 +161,19 @@ func (l *List) update(gtx Context) {
|
||||
max = 0
|
||||
}
|
||||
}
|
||||
|
||||
xrange := pointer.ScrollRange{Min: min, Max: max}
|
||||
yrange := pointer.ScrollRange{}
|
||||
if l.Axis == Vertical {
|
||||
|
||||
axis := gesture.Axis(l.Axis)
|
||||
if l.ScrollAnyAxis {
|
||||
axis = gesture.Both
|
||||
yrange = xrange
|
||||
} else if l.Axis == Vertical {
|
||||
xrange, yrange = yrange, xrange
|
||||
}
|
||||
d := l.scroll.Update(gtx.Metric, gtx.Source, gtx.Now, gesture.Axis(l.Axis), xrange, yrange)
|
||||
d := l.scroll.Update(gtx.Metric, gtx.Source, gtx.Now, axis, xrange, yrange)
|
||||
|
||||
l.scrollDelta = d
|
||||
l.Position.Offset += d
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user