mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user