-
Notifications
You must be signed in to change notification settings - Fork 1
/
hooks.go
136 lines (113 loc) · 2.99 KB
/
hooks.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package ui
import "github.com/axe/axe-go/pkg/util"
type Hooks struct {
OnInit HookBase
OnPlace HookPlace
OnUpdate HookUpdate
OnRender HookRender
OnRemove HookBase
OnPostProcess PostProcess
OnPostProcessLayers PostProcess
OnPostProcessChildren PostProcess
}
func (h *Hooks) Add(add Hooks, before bool) {
h.OnInit.Add(add.OnInit, before)
h.OnPlace.Add(add.OnPlace, before)
h.OnUpdate.Add(add.OnUpdate, before)
h.OnRender.Add(add.OnRender, before)
h.OnRemove.Add(add.OnRemove, before)
h.OnPostProcess.Add(add.OnPostProcess, before)
h.OnPostProcessLayers.Add(add.OnPostProcessLayers, before)
h.OnPostProcessChildren.Add(add.OnPostProcessChildren, before)
}
func (h *Hooks) Clear() {
h.OnInit.Clear()
h.OnPlace.Clear()
h.OnUpdate.Clear()
h.OnRender.Clear()
h.OnRemove.Clear()
h.OnPostProcess.Clear()
h.OnPostProcessLayers.Clear()
h.OnPostProcessChildren.Clear()
}
type HookBase func(b *Base)
func hookBaseNil(h HookBase) bool {
return h == nil
}
func hookBaseJoin(first, second HookBase) HookBase {
return func(b *Base) {
first(b)
second(b)
}
}
func (h HookBase) Run(b *Base) {
if h != nil {
h(b)
}
}
func (h *HookBase) Add(add HookBase, before bool) {
*h = util.CoalesceJoin(*h, add, before, hookBaseNil, hookBaseJoin)
}
func (h *HookBase) Clear() {
*h = nil
}
type HookPlace func(b *Base, parent Bounds, ctx *RenderContext, force bool)
func hookPlaceNil(h HookPlace) bool {
return h == nil
}
func hookPlaceJoin(first, second HookPlace) HookPlace {
return func(b *Base, parent Bounds, ctx *RenderContext, force bool) {
first(b, parent, ctx, force)
second(b, parent, ctx, force)
}
}
func (h HookPlace) Run(b *Base, parent Bounds, ctx *RenderContext, force bool) {
if h != nil {
h(b, parent, ctx, force)
}
}
func (h *HookPlace) Add(add HookPlace, before bool) {
*h = util.CoalesceJoin(*h, add, before, hookPlaceNil, hookPlaceJoin)
}
func (h *HookPlace) Clear() {
*h = nil
}
type HookUpdate func(b *Base, update Update) Dirty
func hookUpdateNil(h HookUpdate) bool {
return h == nil
}
func hookUpdateJoin(first, second HookUpdate) HookUpdate {
return func(b *Base, update Update) Dirty {
dirty := DirtyNone
dirty.Add(first(b, update))
dirty.Add(second(b, update))
return dirty
}
}
func (h HookUpdate) Run(b *Base, update Update) {
if h != nil {
h(b, update)
}
}
func (h *HookUpdate) Add(add HookUpdate, before bool) {
*h = util.CoalesceJoin(*h, add, before, hookUpdateNil, hookUpdateJoin)
}
func (h *HookUpdate) Clear() {
*h = nil
}
type HookRender func(b *Base, ctx *RenderContext, out *VertexQueue)
func hookRenderNil(h HookRender) bool {
return h == nil
}
func hookRenderJoin(first, second HookRender) HookRender {
return func(b *Base, ctx *RenderContext, out *VertexQueue) {
first(b, ctx, out)
second(b, ctx, out)
}
}
func (h *HookRender) Add(add HookRender, before bool) {
*h = util.CoalesceJoin(*h, add, before, hookRenderNil, hookRenderJoin)
}
func (h *HookRender) Clear() {
*h = nil
}