1 Star 0 Fork 21

interesting-goods/Fyne

forked from Gitee 极速下载/Fyne 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
container.go 2.91 KB
一键复制 编辑 原始数据 按行查看 历史
Andy Williams 提交于 2019-11-24 19:33 . don't refresh unless we have to
package fyne
// Declare conformity to CanvasObject
var _ CanvasObject = (*Container)(nil)
// Container is a CanvasObject that contains a collection of child objects.
// The layout of the children is set by the specified Layout.
type Container struct {
size Size // The current size of the Container
position Position // The current position of the Container
Hidden bool // Is this Container hidden
Layout Layout // The Layout algorithm for arranging child CanvasObjects
Objects []CanvasObject // The set of CanvasObjects this container holds
}
func (c *Container) layout() {
if c.Layout != nil {
c.Layout.Layout(c.Objects, c.size)
return
}
}
// Size returns the current size of this container.
func (c *Container) Size() Size {
return c.size
}
// Resize sets a new size for the Container.
func (c *Container) Resize(size Size) {
if c.size == size {
return
}
c.size = size
c.layout()
}
// Position gets the current position of this Container, relative to its parent.
func (c *Container) Position() Position {
return c.position
}
// Move the container (and all its children) to a new position, relative to its parent.
func (c *Container) Move(pos Position) {
c.position = pos
c.layout()
}
// MinSize calculates the minimum size of a Container.
// This is delegated to the Layout, if specified, otherwise it will mimic MaxLayout.
func (c *Container) MinSize() Size {
if c.Layout != nil {
return c.Layout.MinSize(c.Objects)
}
minSize := NewSize(1, 1)
for _, child := range c.Objects {
minSize = minSize.Union(child.MinSize())
}
return minSize
}
// Visible returns true if the container is currently visible, false otherwise.
func (c *Container) Visible() bool {
return !c.Hidden
}
// Show sets this container, and all its children, to be visible.
func (c *Container) Show() {
if !c.Hidden {
return
}
c.Hidden = false
}
// Hide sets this container, and all its children, to be not visible.
func (c *Container) Hide() {
if c.Hidden {
return
}
c.Hidden = true
}
// AddObject adds another CanvasObject to the set this Container holds.
func (c *Container) AddObject(o CanvasObject) {
c.Objects = append(c.Objects, o)
c.layout()
}
// Refresh causes this object to be redrawn in it's current state
func (c *Container) Refresh() {
c.layout()
for _, child := range c.Objects {
child.Refresh()
}
}
// NewContainer returns a new Container instance holding the specified CanvasObjects.
func NewContainer(objects ...CanvasObject) *Container {
ret := &Container{
Objects: objects,
}
ret.size = ret.MinSize()
ret.layout()
return ret
}
// NewContainerWithLayout returns a new Container instance holding the specified
// CanvasObjects which will be laid out according to the specified Layout.
func NewContainerWithLayout(layout Layout, objects ...CanvasObject) *Container {
ret := &Container{
Objects: objects,
Layout: layout,
}
ret.size = layout.MinSize(objects)
ret.layout()
return ret
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/interesting-goods/Fyne.git
[email protected]:interesting-goods/Fyne.git
interesting-goods
Fyne
Fyne
master

搜索帮助