This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
widget_zone.go
84 lines (72 loc) · 1.58 KB
/
widget_zone.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
78
79
80
81
82
83
84
package scene
// WidgetZone is the structure of each layer (inner and outer) of the align system.
type WidgetZone struct {
left *WidgetSection
center *WidgetSection
right *WidgetSection
}
type WidgetSectionType string
const (
WidgetSectionLeft WidgetSectionType = "left"
WidgetSectionCenter WidgetSectionType = "center"
WidgetSectionRight WidgetSectionType = "right"
)
func NewWidgetZone() *WidgetZone {
return &WidgetZone{}
}
func (wz *WidgetZone) Section(s WidgetSectionType) *WidgetSection {
switch s {
case WidgetSectionLeft:
if wz.left == nil {
wz.left = NewWidgetSection()
}
return wz.left
case WidgetSectionCenter:
if wz.center == nil {
wz.center = NewWidgetSection()
}
return wz.center
case WidgetSectionRight:
if wz.right == nil {
wz.right = NewWidgetSection()
}
return wz.right
}
return nil
}
func (z *WidgetZone) Remove(wid WidgetID) {
if z == nil {
return
}
z.left.Remove(wid)
z.center.Remove(wid)
z.right.Remove(wid)
}
func (z *WidgetZone) Find(wid WidgetID) (int, WidgetSectionType, WidgetAreaType) {
if z == nil {
return -1, "", ""
}
if i, wa := z.left.Find(wid); i >= 0 {
return i, WidgetSectionLeft, wa
}
if i, wa := z.center.Find(wid); i >= 0 {
return i, WidgetSectionCenter, wa
}
if i, wa := z.right.Find(wid); i >= 0 {
return i, WidgetSectionRight, wa
}
return -1, "", ""
}
func (z *WidgetZone) SetSection(t WidgetSectionType, s *WidgetSection) {
if z == nil {
return
}
switch t {
case WidgetSectionLeft:
z.left = s
case WidgetSectionCenter:
z.center = s
case WidgetSectionRight:
z.right = s
}
}