-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometry-hypervisor.go
267 lines (243 loc) · 6.57 KB
/
geometry-hypervisor.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// Copyright © 2018 Anton Bekker. All rights reserved.
// This file is part of the AGui.
// License information can be found in the LICENSE file.
package gui
func (w *Window) geometryHypervisorPause() {
if !w.geometryHypervisorIsActive() {
w.geometryHypervisorState++
}
}
func (w *Window) geometryHypervisorResume() {
if w.geometryHypervisorIsPaused() {
w.geometryHypervisorState--
w.geometryHypervisorRunIfReady()
}
}
func (w *Window) geometryHypervisorIsActive() bool { return w.geometryHypervisorState < 0 }
func (w *Window) geometryHypervisorIsReady() bool { return w.geometryHypervisorState == 0 }
func (w *Window) geometryHypervisorIsPaused() bool { return w.geometryHypervisorState > 0 }
func (w *Window) geometryHypervisorRunIfReady() {
if w.geometryHypervisorIsReady() {
w.geometryHypervisorDo()
}
}
func (w *Window) geometryHypervisorDo() {
w.geometryHypervisorState = -1
w.geometryHypervisorDoUPHG(w)
w.geometryHypervisorAdjustWidth()
w.geometryHypervisorDoUCHG(w)
w.geometryHypervisorDoUPVG(w)
w.geometryHypervisorAdjustHeight()
w.geometryHypervisorDoUCVG(w)
w.geometryHypervisorPropogateSize()
w.geometryHypervisorDoIR(w)
w.geometryHypervisorDoIG(w)
w.invalidate()
w.geometryHypervisorState = 0
}
func (w *Window) geometryHypervisorAdjustWidth() {
if !w.geometryHypervisorWidthRequest.enabled {
return
}
width := w.geometryHypervisorWidthRequest.size
if width < w.minSize.X {
width = w.minSize.X
} else if width > w.maxSize.X {
width = w.maxSize.X
}
if w.setHorGeometry(0, width) {
w.setUCHG()
w.setIR()
}
}
func (w *Window) geometryHypervisorAdjustHeight() {
if !w.geometryHypervisorHeightRequest.enabled {
return
}
height := w.geometryHypervisorHeightRequest.size
if height < w.minSize.Y {
height = w.minSize.Y
} else if height > w.maxSize.Y {
height = w.maxSize.Y
}
if w.setVerGeometry(0, height) {
w.setUCVG()
w.setIR()
}
}
func (w *Window) geometryHypervisorPropogateSize() {
w.driver.SetSize(
w.Geometry().GetSize(),
w.geometryHypervisorWidthRequest.enabled && w.geometryHypervisorWidthRequest.invertFixedSide,
w.geometryHypervisorHeightRequest.enabled && w.geometryHypervisorHeightRequest.invertFixedSide,
)
w.geometryHypervisorWidthRequest.enabled = false
w.geometryHypervisorHeightRequest.enabled = false
}
//
// Update Possible Horizontal Geometry (from down to up).
//
func (w *Window) geometryHypervisorDoUPHG(control Control) {
if control.getCUPHG() && (!control.getUPHG() || !control.getUPHGRecursive()) {
for _, child := range control.Children() {
w.geometryHypervisorDoUPHG(child)
}
}
if control.getUPHG() {
var changed bool
if control.getUPHGRecursive() {
changed = w.geometryHypervisorDoUPHGRecursive(control)
} else {
changed = control.setPossibleHorGeometry(control.ComputePossibleHorGeometry())
}
if changed && control.Parent() != nil {
control.Parent().setUPHG(false)
control.Parent().setUCHG()
}
}
control.unsetCUPHG()
control.unsetUPHG()
}
func (w *Window) geometryHypervisorDoUPHGRecursive(control Control) (changed bool) {
for _, child := range control.Children() {
w.geometryHypervisorDoUPHGRecursive(child)
}
changed = control.setPossibleHorGeometry(control.ComputePossibleHorGeometry())
if changed && control.Parent() != nil {
control.Parent().setUCHG()
}
control.unsetCUPHG()
control.unsetUPHG()
return
}
//
// Update Child Horizontal Geometry (from up to down).
//
func (w *Window) geometryHypervisorDoUCHG(control Control) {
if control.getUCHG() {
children := control.Children()
lefts, rights := control.ComputeChildHorGeometry()
for i, child := range children {
changed := child.setHorGeometry(lefts[i], rights[i])
if changed {
child.setUCHG()
child.setUPVG(false)
child.setIR()
child.setIG()
}
}
control.unsetUCHG()
}
if control.getCUCHG() {
children := control.Children()
for _, child := range children {
w.geometryHypervisorDoUCHG(child)
}
control.unsetCUCHG()
}
}
//
// Update Possible Vertical Geometry (from down to up).
//
func (w *Window) geometryHypervisorDoUPVG(control Control) {
if control.getCUPVG() && (!control.getUPVG() || !control.getUPVGRecursive()) {
for _, child := range control.Children() {
w.geometryHypervisorDoUPVG(child)
}
}
if control.getUPVG() {
var changed bool
if control.getUPVGRecursive() {
changed = w.geometryHypervisorDoUPVGRecursive(control)
} else {
changed = control.setPossibleVerGeometry(control.ComputePossibleVerGeometry())
}
if changed && control.Parent() != nil {
control.Parent().setUPVG(false)
control.Parent().setUCVG()
}
}
control.unsetCUPVG()
control.unsetUPVG()
}
func (w *Window) geometryHypervisorDoUPVGRecursive(control Control) (changed bool) {
for _, child := range control.Children() {
w.geometryHypervisorDoUPVGRecursive(child)
}
changed = control.setPossibleVerGeometry(control.ComputePossibleVerGeometry())
if changed && control.Parent() != nil {
control.Parent().setUCVG()
}
control.unsetCUPVG()
control.unsetUPVG()
return
}
//
// Update Child Vertical Geometry (from up to down).
//
func (w *Window) geometryHypervisorDoUCVG(control Control) {
if control.getUCVG() {
children := control.Children()
tops, bottoms := control.ComputeChildVerGeometry()
for i, child := range children {
changed := child.setVerGeometry(tops[i], bottoms[i])
if changed {
child.setUCVG()
child.setIR()
child.setIG()
}
}
control.unsetUCVG()
}
if control.getCUCVG() {
children := control.Children()
for _, child := range children {
w.geometryHypervisorDoUCVG(child)
}
control.unsetCUCVG()
}
}
//
// Invalidate Region (from up to down).
//
func (w *Window) geometryHypervisorDoIR(control Control) {
if control.getIR() {
w.invalidateRegion(control.Geometry())
control.unsetIR()
if control.getCIR() {
w.geometryHypervisorDoIRUnsetRecursive(control)
}
} else if control.getCIR() {
children := control.Children()
for _, child := range children {
w.geometryHypervisorDoIR(child)
}
control.unsetCIR()
}
}
func (w *Window) geometryHypervisorDoIRUnsetRecursive(control Control) {
if control.getCIR() {
children := control.Children()
for _, child := range children {
w.geometryHypervisorDoIRUnsetRecursive(child)
}
control.unsetCIR()
}
control.unsetIR()
}
//
// Invalidate Geometry (from up to down).
//
func (w *Window) geometryHypervisorDoIG(control Control) { // TODO may be merge with DoIR?
if control.getIG() {
control.OnGeometryChangeEvent()
control.unsetIG()
}
if control.getCIG() {
children := control.Children()
for _, child := range children {
w.geometryHypervisorDoIG(child)
}
control.unsetCIG()
}
}