forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridlayout_test.go
114 lines (87 loc) · 3.67 KB
/
gridlayout_test.go
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package layout_test
import (
"image/color"
"testing"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"github.com/stretchr/testify/assert"
)
func TestGridLayout(t *testing.T) {
gridSize := fyne.NewSize(100+theme.Padding(), 100+theme.Padding())
cellSize := fyne.NewSize(50, 50)
obj1 := canvas.NewRectangle(color.NRGBA{0, 0, 0, 0})
obj2 := canvas.NewRectangle(color.NRGBA{0, 0, 0, 0})
obj3 := canvas.NewRectangle(color.NRGBA{0, 0, 0, 0})
container := &fyne.Container{
Objects: []fyne.CanvasObject{obj1, obj2, obj3},
}
container.Resize(gridSize)
layout.NewGridLayout(2).Layout(container.Objects, gridSize)
assert.Equal(t, obj1.Size(), cellSize)
cell2Pos := fyne.NewPos(50+theme.Padding(), 0)
assert.Equal(t, cell2Pos, obj2.Position())
cell3Pos := fyne.NewPos(0, 50+theme.Padding())
assert.Equal(t, cell3Pos, obj3.Position())
}
func TestGridLayoutRounding(t *testing.T) {
gridSize := fyne.NewSize(100+theme.Padding()*2, 50)
obj1 := canvas.NewRectangle(color.NRGBA{0, 0, 0, 0})
obj2 := canvas.NewRectangle(color.NRGBA{0, 0, 0, 0})
obj3 := canvas.NewRectangle(color.NRGBA{0, 0, 0, 0})
container := &fyne.Container{
Objects: []fyne.CanvasObject{obj1, obj2, obj3},
}
container.Resize(gridSize)
layout.NewGridLayout(3).Layout(container.Objects, gridSize)
assert.Equal(t, fyne.NewPos(0, 0), obj1.Position())
assert.Equal(t, fyne.NewSize(33, 50), obj1.Size())
assert.Equal(t, fyne.NewPos(33+theme.Padding(), 0), obj2.Position())
assert.Equal(t, fyne.NewSize(34, 50), obj2.Size())
assert.Equal(t, fyne.NewPos(67+theme.Padding()*2, 0), obj3.Position())
assert.Equal(t, fyne.NewSize(33, 50), obj3.Size())
}
func TestGridLayout_Vertical(t *testing.T) {
gridSize := fyne.NewSize(100+theme.Padding(), 100+theme.Padding())
cellSize := fyne.NewSize(50, 50)
obj1 := canvas.NewRectangle(color.NRGBA{0, 0, 0, 0})
obj2 := canvas.NewRectangle(color.NRGBA{0, 0, 0, 0})
obj3 := canvas.NewRectangle(color.NRGBA{0, 0, 0, 0})
container := &fyne.Container{
Objects: []fyne.CanvasObject{obj1, obj2, obj3},
}
container.Resize(gridSize)
layout.NewGridLayoutWithRows(2).Layout(container.Objects, gridSize)
assert.Equal(t, obj1.Size(), cellSize)
cell2Pos := fyne.NewPos(0, 50+theme.Padding())
assert.Equal(t, cell2Pos, obj2.Position())
cell3Pos := fyne.NewPos(50+theme.Padding(), 0)
assert.Equal(t, cell3Pos, obj3.Position())
}
func TestGridLayout_MinSize(t *testing.T) {
text1 := canvas.NewText("Large Text", color.NRGBA{0xff, 0, 0, 0})
text2 := canvas.NewText("small", color.NRGBA{0xff, 0, 0, 0})
minSize := text1.MinSize().Add(fyne.NewSize(0, text2.MinSize().Height+theme.Padding()))
container := fyne.NewContainer(text1, text2)
layoutMin := layout.NewGridLayout(1).MinSize(container.Objects)
assert.Equal(t, minSize, layoutMin)
}
func TestGridLayout_MinSize_Vertical(t *testing.T) {
text1 := canvas.NewText("Text", color.NRGBA{0xff, 0, 0, 0})
text2 := canvas.NewText("Text", color.NRGBA{0xff, 0, 0, 0})
minSize := text1.MinSize().Add(fyne.NewSize(text2.MinSize().Width+theme.Padding(), 0))
container := fyne.NewContainer(text1, text2)
layoutMin := layout.NewGridLayoutWithRows(1).MinSize(container.Objects)
assert.Equal(t, minSize, layoutMin)
}
func TestGridLayout_MinSize_HiddenItem(t *testing.T) {
text1 := canvas.NewText("Large Text", color.NRGBA{0xff, 0, 0, 0})
text2 := canvas.NewText("hidden", color.NRGBA{0xff, 0, 0, 0})
text2.Hide()
text3 := canvas.NewText("small", color.NRGBA{0xff, 0, 0, 0})
minSize := text1.MinSize().Add(fyne.NewSize(0, text3.MinSize().Height+theme.Padding()))
container := fyne.NewContainer(text1, text2, text3)
layoutMin := layout.NewGridLayout(1).MinSize(container.Objects)
assert.Equal(t, minSize, layoutMin)
}