layout: layout one invisible child at each end of a List

A recent change added automatic scrolling to move focused widgets
into view. This change modifies List to layout an extra child at
each of its ends, to enable focus to move to them and trigger
automatic scrolling of the list.

For https://github.com/tailscale/tailscale/issues/4278.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-03-30 19:21:29 +02:00
parent a699fb89ac
commit 508330e818
2 changed files with 56 additions and 5 deletions
+18
View File
@@ -140,3 +140,21 @@ func TestListPosition(t *testing.T) {
})
}
}
func TestExtraChildren(t *testing.T) {
var l List
l.Position.First = 1
gtx := Context{
Ops: new(op.Ops),
Constraints: Exact(image.Pt(10, 10)),
}
count := 0
const all = 3
l.Layout(gtx, all, func(gtx Context, idx int) Dimensions {
count++
return Dimensions{Size: image.Pt(10, 10)}
})
if count != all {
t.Errorf("laid out %d of %d children", count, all)
}
}