forked from quantum/gonsole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basecontainer.go
54 lines (45 loc) · 999 Bytes
/
basecontainer.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
package gonsole
type BaseContainer struct {
title string
children []Control
}
func (c *BaseContainer) Title() string {
return c.title
}
func (c *BaseContainer) SetTitle(title string) {
c.title = title
}
func (c *BaseContainer) AddControl(ctrl Control) {
c.children = append(c.children, ctrl)
}
func (c *BaseContainer) Children() []Control {
return c.children
}
func (c *BaseContainer) ChildrenDeep() []Control {
controls := make([]Control, 0)
for _, control := range c.children {
container, ok := control.(Container)
if ok {
children := container.ChildrenDeep()
for _, child := range children {
controls = append(controls, child)
}
} else {
controls = append(controls, control)
}
}
return controls
}
func (c *BaseContainer) DirtyChildren() bool {
for _, child := range c.ChildrenDeep() {
if child.Dirty() {
return true
}
}
return false
}
func (c *BaseContainer) RepaintChildren() {
for _, child := range c.Children() {
child.Repaint()
}
}