forked from AllenDang/giu
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Layout.go
50 lines (42 loc) · 1.03 KB
/
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
package giu
const (
// Auto is used to widget.Size to indicate height or width to occupy available spaces
Auto float32 = -0.0000001
)
// Widget is a base unit of giu rendering system.
// each widget just needs to implement Build method which is called,
// when widget needs to be rendered.
type Widget interface {
Build()
}
var (
_ Widget = Layout{}
_ Splitable = Layout{}
)
// Layout is a set of widgets. It implements Widget interface so
// Layout can be used as a widget.
type Layout []Widget
// Build implements Widget interface
func (l Layout) Build() {
for _, w := range l {
if w != nil {
w.Build()
}
}
}
// Splitable is implemented by widgets, which can be split (ranged)
// Layout implements Splitable.
type Splitable interface {
Range(func(w Widget))
}
// Range ranges ofer the Layout, calling rangeFunc
// on each loop iteration.
func (l Layout) Range(rangeFunc func(Widget)) {
for _, w := range l {
if splitable, canRange := w.(Splitable); canRange {
splitable.Range(rangeFunc)
continue
}
rangeFunc(w)
}
}