-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer.go
77 lines (64 loc) · 1.24 KB
/
container.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
package wasabi
type container struct {
base
children []Element
}
func newContainer(children ...Element) container {
return container{
base: newBase(),
children: children,
}
}
func (c *container) Attach(a App) {
c.base.Attach(a)
for _, c := range c.children {
c.Attach(a)
}
}
func (c *container) Detach() {
c.base.Detach()
for _, child := range c.children {
child.Detach()
}
}
func (c *container) Children() []Element {
return c.children
}
func (c *container) Add(w Element) {
c.children = append(c.children, w)
c.Update()
}
func (c *container) Remove(el Element) {
new := make([]Element, len(c.children))
var i uint
for _, child := range c.children {
if child != el {
new[i] = child
i++
}
}
c.children = new[:i]
c.Update()
}
func (c *container) View() string {
var ret string
for _, w := range c.children {
ret += w.View()
}
return ret
}
type genericContainerElement struct {
container
tag string
}
func containerElement(tag string, children ...Element) *genericContainerElement {
el := &genericContainerElement{
container: newContainer(children...),
tag: tag,
}
el.base.SetElement(el)
return el
}
func (g *genericContainerElement) View() string {
return g.genHTML(g.tag, g.container.View())
}