-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout.go
54 lines (43 loc) · 971 Bytes
/
layout.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 main
import "github.com/fogleman/gg"
type Layout struct {
View
Children []View
alloc *Allocation
}
func (c *Layout) Add(child View) {
c.Children = append(c.Children, child)
}
func (c *Layout) Remove(child View) {
list := c.Children[:0]
for _, item := range c.Children {
if item != child {
list = append(list, item)
}
}
c.Children = list
}
func (c *Layout) Render(context *gg.Context) {
context.Push()
defer context.Pop()
// FIXME: https://github.com/fogleman/gg/issues/27
// alloc := c.Allocation()
// context.DrawRectangle(alloc.X, alloc.Y, alloc.Width, alloc.Height)
// context.Clip()
// defer context.ResetClip()
for _, child := range c.Children {
func() {
context.Push()
defer context.Pop()
alloc := child.Allocation()
context.Translate(alloc.X, alloc.Y)
child.Render(context)
}()
}
}
func (c *Layout) Allocation() Allocation {
return *c.alloc
}
func (c *Layout) Len() int {
return len(c.Children)
}