forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_test.go
133 lines (102 loc) · 2.47 KB
/
container_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package fyne
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMinSize(t *testing.T) {
box := new(dummyObject)
minSize := box.MinSize()
container := NewContainer(box)
assert.Equal(t, minSize, container.MinSize())
container.AddObject(box)
assert.Equal(t, minSize, container.MinSize())
}
func TestMove(t *testing.T) {
box := new(dummyObject)
container := NewContainer(box)
size := NewSize(100, 100)
pos := NewPos(0, 0)
container.Resize(size)
assert.Equal(t, pos, box.Position())
pos = NewPos(10, 10)
container.Move(pos)
assert.Equal(t, pos, container.Position())
assert.Equal(t, pos, box.Position())
}
func TestDefaultLayout(t *testing.T) {
box := new(dummyObject)
container := NewContainer(box)
size := NewSize(100, 100)
container.Resize(size)
assert.Equal(t, size, container.Size())
assert.Equal(t, size, box.Size())
container.AddObject(box)
assert.Equal(t, size, box.Size())
}
type customLayout struct {
}
func (c *customLayout) Layout(objs []CanvasObject, size Size) {
for _, child := range objs {
child.Resize(size)
}
}
func (c *customLayout) MinSize(objects []CanvasObject) Size {
return NewSize(10, 10)
}
func TestCustomLayout(t *testing.T) {
box := new(dummyObject)
layout := new(customLayout)
container := NewContainerWithLayout(layout, box)
size := layout.MinSize(container.Objects)
assert.Equal(t, size, container.MinSize())
assert.Equal(t, size, container.Size())
assert.Equal(t, size, box.Size())
container.AddObject(box)
assert.Equal(t, size, box.Size())
}
func TestContainer_Hide(t *testing.T) {
box := new(dummyObject)
container := NewContainer(box)
assert.True(t, box.Visible())
container.Hide()
assert.False(t, box.Visible())
}
func TestContainer_Show(t *testing.T) {
box := new(dummyObject)
container := NewContainer(box)
container.Hide()
assert.False(t, box.Visible())
assert.False(t, container.Visible())
container.Show()
assert.True(t, box.Visible())
assert.True(t, container.Visible())
}
type dummyObject struct {
size Size
pos Position
hidden bool
}
func (d *dummyObject) Size() Size {
return d.size
}
func (d *dummyObject) Resize(size Size) {
d.size = size
}
func (d *dummyObject) Position() Position {
return d.pos
}
func (d *dummyObject) Move(pos Position) {
d.pos = pos
}
func (d *dummyObject) MinSize() Size {
return NewSize(5, 5)
}
func (d *dummyObject) Visible() bool {
return !d.hidden
}
func (d *dummyObject) Show() {
d.hidden = false
}
func (d *dummyObject) Hide() {
d.hidden = true
}