代码拉取完成,页面将自动刷新
同步操作将从 Gitee 极速下载/Fyne 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。