-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayout_test.go
More file actions
78 lines (72 loc) · 1.66 KB
/
layout_test.go
File metadata and controls
78 lines (72 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SPDX-License-Identifier: Unlicense OR MIT
package layout
import (
"image"
"testing"
"gioui.org/op"
)
func TestStack(t *testing.T) {
gtx := Context{
Ops: new(op.Ops),
Constraints: Constraints{
Max: image.Pt(100, 100),
},
}
exp := image.Point{X: 60, Y: 70}
dims := Stack{Alignment: Center}.Layout(gtx,
Expanded(func(gtx Context) Dimensions {
return Dimensions{Size: exp}
}),
Stacked(func(gtx Context) Dimensions {
return Dimensions{Size: image.Point{X: 50, Y: 50}}
}),
)
if got := dims.Size; got != exp {
t.Errorf("Stack ignored Expanded size, got %v expected %v", got, exp)
}
}
func TestFlex(t *testing.T) {
gtx := Context{
Ops: new(op.Ops),
Constraints: Constraints{
Min: image.Pt(100, 100),
Max: image.Pt(100, 100),
},
}
dims := Flex{}.Layout(gtx)
if got := dims.Size; got != gtx.Constraints.Min {
t.Errorf("Flex ignored minimum constraints, got %v expected %v", got, gtx.Constraints.Min)
}
}
func TestDirection(t *testing.T) {
max := image.Pt(100, 100)
for _, tc := range []struct {
dir Direction
exp image.Point
}{
{N, image.Pt(max.X, 0)},
{S, image.Pt(max.X, 0)},
{E, image.Pt(0, max.Y)},
{W, image.Pt(0, max.Y)},
{NW, image.Pt(0, 0)},
{NE, image.Pt(0, 0)},
{SE, image.Pt(0, 0)},
{SW, image.Pt(0, 0)},
{Center, image.Pt(0, 0)},
} {
t.Run(tc.dir.String(), func(t *testing.T) {
gtx := Context{
Ops: new(op.Ops),
Constraints: Exact(max),
}
var min image.Point
tc.dir.Layout(gtx, func(gtx Context) Dimensions {
min = gtx.Constraints.Min
return Dimensions{}
})
if got, exp := min, tc.exp; got != exp {
t.Errorf("got %v; expected %v", got, exp)
}
})
}
}