...
1 package etk
2
3 import "image"
4
5
6
7 type Frame struct {
8 *Box
9 padding int
10 positionChildren bool
11 }
12
13
14 func NewFrame(w ...Widget) *Frame {
15 f := &Frame{
16 Box: NewBox(),
17 }
18 f.AddChild(w...)
19 return f
20 }
21
22
23 func (f *Frame) SetPadding(padding int) {
24 f.Lock()
25 defer f.Unlock()
26
27 f.padding = padding
28 f.reposition()
29 }
30
31
32 func (f *Frame) SetRect(r image.Rectangle) {
33 f.Lock()
34 defer f.Unlock()
35
36 f.rect = r
37 f.reposition()
38 }
39
40
41
42 func (f *Frame) SetPositionChildren(position bool) {
43 f.Lock()
44 defer f.Unlock()
45
46 f.positionChildren = position
47 f.reposition()
48 }
49
50
51 func (f *Frame) AddChild(w ...Widget) {
52 f.Lock()
53 defer f.Unlock()
54
55 f.children = append(f.children, w...)
56
57 if f.positionChildren {
58 r := f.rect.Inset(f.padding)
59 for _, wgt := range w {
60 wgt.SetRect(r)
61 }
62 }
63 }
64
65 func (f *Frame) reposition() {
66 if !f.positionChildren {
67 return
68 }
69 r := f.rect.Inset(f.padding)
70 for _, w := range f.children {
71 w.SetRect(r)
72 }
73 }
74
View as plain text