mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget/material: prevent invalid list item constraints
Previously, a bug in the ListStyle could result in items being passed a negative value in the minimum constraints. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -257,7 +257,13 @@ func (l ListStyle) Layout(gtx layout.Context, length int, w layout.ListElement)
|
||||
max := l.state.Axis.Convert(gtx.Constraints.Max)
|
||||
min := l.state.Axis.Convert(gtx.Constraints.Min)
|
||||
max.Y -= barWidth
|
||||
if max.Y < 0 {
|
||||
max.Y = 0
|
||||
}
|
||||
min.Y -= barWidth
|
||||
if min.Y < 0 {
|
||||
min.Y = 0
|
||||
}
|
||||
gtx.Constraints.Max = l.state.Axis.Convert(max)
|
||||
gtx.Constraints.Min = l.state.Axis.Convert(min)
|
||||
}
|
||||
|
||||
@@ -27,10 +27,15 @@ func TestListAnchorStrategies(t *testing.T) {
|
||||
Y: 500,
|
||||
},
|
||||
})
|
||||
gtx.Constraints.Min = image.Point{}
|
||||
|
||||
var spaceConstraints layout.Constraints
|
||||
space := func(gtx layout.Context, index int) layout.Dimensions {
|
||||
spaceConstraints = gtx.Constraints
|
||||
if spaceConstraints.Min.X < 0 || spaceConstraints.Min.Y < 0 ||
|
||||
spaceConstraints.Max.X < 0 || spaceConstraints.Max.Y < 0 {
|
||||
t.Errorf("invalid constraints at index %d: %#+v", index, spaceConstraints)
|
||||
}
|
||||
return layout.Dimensions{Size: image.Point{
|
||||
X: gtx.Constraints.Max.X,
|
||||
Y: gtx.Px(unit.Dp(20)),
|
||||
|
||||
Reference in New Issue
Block a user