layout: fix dimensions of empty list

When the Min constraints are set but the list
has no item to display, use those as the list
returned dimensions.

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2021-12-03 20:40:35 +01:00
committed by Elias Naur
parent 872b4ba41b
commit 2d75181b51
2 changed files with 17 additions and 0 deletions
+5
View File
@@ -293,6 +293,11 @@ func (l *List) layout(ops *op.Ops, macro op.MacroOp) Dimensions {
if pos > mainMax {
pos = mainMax
}
if crossMin, crossMax := l.Axis.crossConstraint(l.cs); maxCross < crossMin {
maxCross = crossMin
} else if maxCross > crossMax {
maxCross = crossMax
}
dims := l.Axis.Convert(image.Pt(pos, maxCross))
call := macro.Stop()
defer clip.Rect(image.Rectangle{Max: dims}).Push(ops).Pop()
+12
View File
@@ -13,6 +13,18 @@ import (
"gioui.org/op"
)
func TestEmptyList(t *testing.T) {
var l List
gtx := Context{
Ops: new(op.Ops),
Constraints: Exact(image.Pt(20, 10)),
}
dims := l.Layout(gtx, 0, nil)
if got, want := dims.Size, gtx.Constraints.Min; got != want {
t.Errorf("got %v; want %v", got, want)
}
}
func TestListPosition(t *testing.T) {
_s := func(e ...event.Event) []event.Event { return e }
r := new(router.Router)