widget/material: clamp fromListPosition end coordinate

Previously, it was possible for fromListPosition to return
an end coordinate greater than 1, which would make scroll
indicators using those coordinates render beyond the
boundaries of their scroll tracks. One could argue that
this is a bug in the scroll indicator, but I don't think
this method should return data outside of its documented
range.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2021-09-09 15:07:56 -04:00
committed by Elias Naur
parent fc5637804f
commit da09aabbe8
+1 -1
View File
@@ -35,7 +35,7 @@ func fromListPosition(lp layout.Position, elements int, majorAxisSize int) (star
// Compute the location of the beginning of the viewport.
viewportStart := (float32(lp.First)*meanElementHeight + listOffsetF) / lengthPx
return viewportStart, viewportStart + visibleFraction
return viewportStart, clamp1(viewportStart + visibleFraction)
}
// rangeIsScrollable returns whether the viewport described by start and end