-
Notifications
You must be signed in to change notification settings - Fork 38
/
widget.go
103 lines (87 loc) · 2.47 KB
/
widget.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package plugin
type WidgetZoneType string
type WidgetSectionType string
type WidgetAreaType string
const (
WidgetZoneInner WidgetZoneType = "inner"
WidgetZoneOuter WidgetZoneType = "outer"
WidgetSectionLeft WidgetSectionType = "left"
WidgetSectionCenter WidgetSectionType = "center"
WidgetSectionRight WidgetSectionType = "right"
WidgetAreaTop WidgetAreaType = "top"
WidgetAreaMiddle WidgetAreaType = "middle"
WidgetAreaBottom WidgetAreaType = "bottom"
)
type WidgetLayout struct {
horizontallyExtendable bool
verticallyExtendable bool
extended bool
floating bool
defaultLocation *WidgetLocation
}
func (l WidgetLayout) Extendable(loc WidgetLocation) bool {
return l.HorizontallyExtendable() && loc.Horizontal() || l.VerticallyExtendable() && loc.Vertical()
}
func NewWidgetLayout(horizontallyExtendable, verticallyExtendable, extended, floating bool, defaultLocation *WidgetLocation) WidgetLayout {
return WidgetLayout{
horizontallyExtendable: horizontallyExtendable,
verticallyExtendable: verticallyExtendable,
extended: extended,
floating: floating,
defaultLocation: defaultLocation.Clone(),
}
}
func (l WidgetLayout) Ref() *WidgetLayout {
return &l
}
func (l WidgetLayout) HorizontallyExtendable() bool {
return l.horizontallyExtendable
}
func (l WidgetLayout) VerticallyExtendable() bool {
return l.verticallyExtendable
}
func (l WidgetLayout) Extended() bool {
return l.extended
}
func (l WidgetLayout) Floating() bool {
return l.floating
}
func (l WidgetLayout) DefaultLocation() *WidgetLocation {
if l.defaultLocation == nil {
return nil
}
return l.defaultLocation.Clone()
}
func (l *WidgetLayout) Clone() *WidgetLayout {
if l == nil {
return nil
}
return &WidgetLayout{
horizontallyExtendable: l.horizontallyExtendable,
verticallyExtendable: l.verticallyExtendable,
extended: l.extended,
floating: l.floating,
defaultLocation: l.defaultLocation.Clone(),
}
}
type WidgetLocation struct {
Zone WidgetZoneType
Section WidgetSectionType
Area WidgetAreaType
}
func (l WidgetLocation) Horizontal() bool {
return l.Section == WidgetSectionCenter
}
func (l WidgetLocation) Vertical() bool {
return l.Area == WidgetAreaMiddle
}
func (l *WidgetLocation) Clone() *WidgetLocation {
if l == nil {
return nil
}
return &WidgetLocation{
Zone: l.Zone,
Section: l.Section,
Area: l.Area,
}
}