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:
inkeliz
2025-05-16 11:27:19 +01:00
committed by Elias Naur
parent f73287be87
commit 0225334124
2 changed files with 20 additions and 4 deletions
+11 -2
View File
@@ -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
}