uicore-ts 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/uicore.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/compiledScripts/UIActionIndicator.d.ts +12 -0
- package/compiledScripts/UIActionIndicator.js +54 -0
- package/compiledScripts/UIActionIndicator.js.map +1 -0
- package/compiledScripts/UIBaseButton.d.ts +52 -0
- package/compiledScripts/UIBaseButton.js +268 -0
- package/compiledScripts/UIBaseButton.js.map +1 -0
- package/compiledScripts/UIButton.d.ts +54 -0
- package/compiledScripts/UIButton.js +247 -0
- package/compiledScripts/UIButton.js.map +1 -0
- package/compiledScripts/UIColor.d.ts +41 -0
- package/compiledScripts/UIColor.js +286 -0
- package/compiledScripts/UIColor.js.map +1 -0
- package/compiledScripts/UICore.d.ts +27 -0
- package/compiledScripts/UICore.js +105 -0
- package/compiledScripts/UICore.js.map +1 -0
- package/compiledScripts/UICoreExtensions.d.ts +60 -0
- package/compiledScripts/UICoreExtensions.js +527 -0
- package/compiledScripts/UICoreExtensions.js.map +1 -0
- package/compiledScripts/UIDateTimeInput.d.ts +40 -0
- package/compiledScripts/UIDateTimeInput.js +38 -0
- package/compiledScripts/UIDateTimeInput.js.map +1 -0
- package/compiledScripts/UIDialogView.d.ts +23 -0
- package/compiledScripts/UIDialogView.js +118 -0
- package/compiledScripts/UIDialogView.js.map +1 -0
- package/compiledScripts/UIImageView.d.ts +36 -0
- package/compiledScripts/UIImageView.js +170 -0
- package/compiledScripts/UIImageView.js.map +1 -0
- package/compiledScripts/UIKeyValueStringFilter.d.ts +21 -0
- package/compiledScripts/UIKeyValueStringFilter.js +98 -0
- package/compiledScripts/UIKeyValueStringFilter.js.map +1 -0
- package/compiledScripts/UIKeyValueStringSorter.d.ts +38 -0
- package/compiledScripts/UIKeyValueStringSorter.js +117 -0
- package/compiledScripts/UIKeyValueStringSorter.js.map +1 -0
- package/compiledScripts/UILayoutGrid.d.ts +8 -0
- package/compiledScripts/UILayoutGrid.js +22 -0
- package/compiledScripts/UILayoutGrid.js.map +1 -0
- package/compiledScripts/UILink.d.ts +25 -0
- package/compiledScripts/UILink.js +81 -0
- package/compiledScripts/UILink.js.map +1 -0
- package/compiledScripts/UILinkButton.d.ts +18 -0
- package/compiledScripts/UILinkButton.js +60 -0
- package/compiledScripts/UILinkButton.js.map +1 -0
- package/compiledScripts/UINativeScrollView.d.ts +20 -0
- package/compiledScripts/UINativeScrollView.js +121 -0
- package/compiledScripts/UINativeScrollView.js.map +1 -0
- package/compiledScripts/UIObject.d.ts +69 -0
- package/compiledScripts/UIObject.js +442 -0
- package/compiledScripts/UIObject.js.map +1 -0
- package/compiledScripts/UIPoint.d.ts +18 -0
- package/compiledScripts/UIPoint.js +68 -0
- package/compiledScripts/UIPoint.js.map +1 -0
- package/compiledScripts/UIRectangle.d.ts +61 -0
- package/compiledScripts/UIRectangle.js +421 -0
- package/compiledScripts/UIRectangle.js.map +1 -0
- package/compiledScripts/UIRoute.d.ts +39 -0
- package/compiledScripts/UIRoute.js +202 -0
- package/compiledScripts/UIRoute.js.map +1 -0
- package/compiledScripts/UIScrollView.d.ts +19 -0
- package/compiledScripts/UIScrollView.js +121 -0
- package/compiledScripts/UIScrollView.js.map +1 -0
- package/compiledScripts/UISlideScrollerView.d.ts +40 -0
- package/compiledScripts/UISlideScrollerView.js +242 -0
- package/compiledScripts/UISlideScrollerView.js.map +1 -0
- package/compiledScripts/UIStringFilter.d.ts +26 -0
- package/compiledScripts/UIStringFilter.js +107 -0
- package/compiledScripts/UIStringFilter.js.map +1 -0
- package/compiledScripts/UITableView.d.ts +61 -0
- package/compiledScripts/UITableView.js +383 -0
- package/compiledScripts/UITableView.js.map +1 -0
- package/compiledScripts/UITextArea.d.ts +7 -0
- package/compiledScripts/UITextArea.js +27 -0
- package/compiledScripts/UITextArea.js.map +1 -0
- package/compiledScripts/UITextField.d.ts +44 -0
- package/compiledScripts/UITextField.js +83 -0
- package/compiledScripts/UITextField.js.map +1 -0
- package/compiledScripts/UITextView.d.ts +89 -0
- package/compiledScripts/UITextView.js +237 -0
- package/compiledScripts/UITextView.js.map +1 -0
- package/compiledScripts/UITimer.d.ts +13 -0
- package/compiledScripts/UITimer.js +45 -0
- package/compiledScripts/UITimer.js.map +1 -0
- package/compiledScripts/UIView.d.ts +330 -0
- package/compiledScripts/UIView.js +1533 -0
- package/compiledScripts/UIView.js.map +1 -0
- package/compiledScripts/UIViewController.d.ts +38 -0
- package/compiledScripts/UIViewController.js +153 -0
- package/compiledScripts/UIViewController.js.map +1 -0
- package/compiledScripts/index.d.ts +29 -0
- package/compiledScripts/index.js +46 -0
- package/compiledScripts/index.js.map +1 -0
- package/package.json +36 -0
- package/scripts/UIActionIndicator.ts +139 -0
- package/scripts/UIBaseButton.ts +563 -0
- package/scripts/UIButton.ts +552 -0
- package/scripts/UIColor.ts +427 -0
- package/scripts/UICore.ts +223 -0
- package/scripts/UICoreExtensions.ts +949 -0
- package/scripts/UIDateTimeInput.ts +109 -0
- package/scripts/UIDialogView.ts +297 -0
- package/scripts/UIImageView.ts +366 -0
- package/scripts/UIKeyValueStringFilter.ts +260 -0
- package/scripts/UIKeyValueStringSorter.ts +337 -0
- package/scripts/UILayoutGrid.ts +83 -0
- package/scripts/UILink.ts +292 -0
- package/scripts/UILinkButton.ts +238 -0
- package/scripts/UINativeScrollView.ts +254 -0
- package/scripts/UIObject.ts +827 -0
- package/scripts/UIPoint.ts +123 -0
- package/scripts/UIRectangle.ts +730 -0
- package/scripts/UIRoute.ts +391 -0
- package/scripts/UIScrollView.ts +290 -0
- package/scripts/UISlideScrollerView.ts +530 -0
- package/scripts/UIStringFilter.ts +293 -0
- package/scripts/UITableView.ts +790 -0
- package/scripts/UITextArea.ts +91 -0
- package/scripts/UITextField.ts +218 -0
- package/scripts/UITextView.ts +561 -0
- package/scripts/UITimer.ts +107 -0
- package/scripts/UIView.ts +2789 -0
- package/scripts/UIViewController.ts +304 -0
- package/scripts/index.ts +36 -0
- package/tsconfig.json +59 -0
|
@@ -0,0 +1,730 @@
|
|
|
1
|
+
import { FIRST_OR_NIL, IS, IS_NIL, IS_NOT_NIL, nil, NO, UIObject, YES } from "./UIObject"
|
|
2
|
+
import { UIPoint } from "./UIPoint"
|
|
3
|
+
import { UIView } from "./UIView"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class UIRectangle extends UIObject {
|
|
10
|
+
|
|
11
|
+
_isBeingUpdated: boolean
|
|
12
|
+
rectanglePointDidChange: (b: any) => void
|
|
13
|
+
max: UIPoint
|
|
14
|
+
min: UIPoint
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
constructor(x: number = 0, y: number = 0, height: number = 0, width: number = 0) {
|
|
18
|
+
|
|
19
|
+
super()
|
|
20
|
+
|
|
21
|
+
this._class = UIRectangle
|
|
22
|
+
this.superclass = UIObject
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
this.min = new UIPoint(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY)
|
|
26
|
+
this.max = new UIPoint(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY)
|
|
27
|
+
|
|
28
|
+
this.min.didChange = this.rectanglePointDidChange
|
|
29
|
+
this.max.didChange = this.rectanglePointDidChange
|
|
30
|
+
|
|
31
|
+
this._isBeingUpdated = NO
|
|
32
|
+
|
|
33
|
+
this.min = new UIPoint(x, y)
|
|
34
|
+
this.max = new UIPoint(x + width, y + height)
|
|
35
|
+
|
|
36
|
+
if (IS_NIL(height)) {
|
|
37
|
+
this.max.y = height
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (IS_NIL(width)) {
|
|
41
|
+
this.max.x = width
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
copy() {
|
|
52
|
+
const result = new UIRectangle(this.x, this.y, this.height, this.width)
|
|
53
|
+
return result
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
isEqualTo(rectangle: UIRectangle) {
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const result = (IS(rectangle) && this.min.isEqualTo(rectangle.min) && this.max.isEqualTo(rectangle.max))
|
|
60
|
+
|
|
61
|
+
return result
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static zero() {
|
|
66
|
+
|
|
67
|
+
const result = new UIRectangle(0, 0, 0, 0)
|
|
68
|
+
|
|
69
|
+
return result
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
containsPoint(point: UIPoint) {
|
|
74
|
+
return this.min.x <= point.x && this.min.y <= point.y &&
|
|
75
|
+
point.x <= this.max.x && point.y <= this.max.y
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
updateByAddingPoint(point: UIPoint) {
|
|
79
|
+
|
|
80
|
+
if (!point) {
|
|
81
|
+
point = new UIPoint(0, 0)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.beginUpdates()
|
|
85
|
+
|
|
86
|
+
const min = this.min.copy()
|
|
87
|
+
if (min.x === nil) {
|
|
88
|
+
min.x = this.max.x
|
|
89
|
+
}
|
|
90
|
+
if (min.y === nil) {
|
|
91
|
+
min.y = this.max.y
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const max = this.max.copy()
|
|
95
|
+
if (max.x === nil) {
|
|
96
|
+
max.x = this.min.x
|
|
97
|
+
}
|
|
98
|
+
if (max.y === nil) {
|
|
99
|
+
max.y = this.min.y
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.min.x = Math.min(min.x, point.x)
|
|
103
|
+
this.min.y = Math.min(min.y, point.y)
|
|
104
|
+
this.max.x = Math.max(max.x, point.x)
|
|
105
|
+
this.max.y = Math.max(max.y, point.y)
|
|
106
|
+
|
|
107
|
+
this.finishUpdates()
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
get height() {
|
|
112
|
+
if (this.max.y === nil) {
|
|
113
|
+
return nil
|
|
114
|
+
}
|
|
115
|
+
return this.max.y - this.min.y
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
set height(height: number) {
|
|
119
|
+
this.max.y = this.min.y + height
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
get width() {
|
|
125
|
+
if (this.max.x === nil) {
|
|
126
|
+
return nil
|
|
127
|
+
}
|
|
128
|
+
return this.max.x - this.min.x
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
set width(width: number) {
|
|
132
|
+
this.max.x = this.min.x + width
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
get x() {
|
|
138
|
+
return this.min.x
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
set x(x: number) {
|
|
142
|
+
|
|
143
|
+
this.beginUpdates()
|
|
144
|
+
|
|
145
|
+
const width = this.width
|
|
146
|
+
this.min.x = x
|
|
147
|
+
this.max.x = this.min.x + width
|
|
148
|
+
|
|
149
|
+
this.finishUpdates()
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
get y() {
|
|
155
|
+
return this.min.y
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
set y(y: number) {
|
|
160
|
+
|
|
161
|
+
this.beginUpdates()
|
|
162
|
+
|
|
163
|
+
const height = this.height
|
|
164
|
+
this.min.y = y
|
|
165
|
+
this.max.y = this.min.y + height
|
|
166
|
+
|
|
167
|
+
this.finishUpdates()
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
get topLeft() {
|
|
175
|
+
|
|
176
|
+
return this.min.copy()
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
get topRight() {
|
|
181
|
+
return new UIPoint(this.max.x, this.y)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
get bottomLeft() {
|
|
185
|
+
return new UIPoint(this.x, this.max.y)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
get bottomRight() {
|
|
189
|
+
|
|
190
|
+
return this.max.copy()
|
|
191
|
+
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
get center() {
|
|
196
|
+
|
|
197
|
+
const result = this.min.copy().add(this.min.to(this.max).scale(0.5))
|
|
198
|
+
|
|
199
|
+
return result
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
set center(center: UIPoint) {
|
|
204
|
+
|
|
205
|
+
const offset = this.center.to(center)
|
|
206
|
+
this.offsetByPoint(offset)
|
|
207
|
+
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
offsetByPoint(offset: UIPoint) {
|
|
211
|
+
|
|
212
|
+
this.min.add(offset)
|
|
213
|
+
this.max.add(offset)
|
|
214
|
+
|
|
215
|
+
return this
|
|
216
|
+
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
concatenateWithRectangle(rectangle: UIRectangle) {
|
|
222
|
+
|
|
223
|
+
this.updateByAddingPoint(rectangle.bottomRight)
|
|
224
|
+
this.updateByAddingPoint(rectangle.topLeft)
|
|
225
|
+
|
|
226
|
+
return this
|
|
227
|
+
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
intersectionRectangleWithRectangle(rectangle: UIRectangle): UIRectangle {
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
const result = this.copy()
|
|
238
|
+
|
|
239
|
+
result.beginUpdates()
|
|
240
|
+
|
|
241
|
+
const min = result.min
|
|
242
|
+
if (min.x === nil) {
|
|
243
|
+
min.x = rectangle.max.x - Math.min(result.width, rectangle.width)
|
|
244
|
+
}
|
|
245
|
+
if (min.y === nil) {
|
|
246
|
+
min.y = rectangle.max.y - Math.min(result.height, rectangle.height)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const max = result.max
|
|
250
|
+
if (max.x === nil) {
|
|
251
|
+
max.x = rectangle.min.x + Math.min(result.width, rectangle.width)
|
|
252
|
+
}
|
|
253
|
+
if (max.y === nil) {
|
|
254
|
+
max.y = rectangle.min.y + Math.min(result.height, rectangle.height)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
result.min.x = Math.max(result.min.x, rectangle.min.x)
|
|
258
|
+
result.min.y = Math.max(result.min.y, rectangle.min.y)
|
|
259
|
+
result.max.x = Math.min(result.max.x, rectangle.max.x)
|
|
260
|
+
result.max.y = Math.min(result.max.y, rectangle.max.y)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
if (result.height < 0) {
|
|
264
|
+
|
|
265
|
+
const averageY = (this.center.y + rectangle.center.y) * 0.5
|
|
266
|
+
result.min.y = averageY
|
|
267
|
+
result.max.y = averageY
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (result.width < 0) {
|
|
272
|
+
|
|
273
|
+
const averageX = (this.center.x + rectangle.center.x) * 0.5
|
|
274
|
+
result.min.x = averageX
|
|
275
|
+
result.max.x = averageX
|
|
276
|
+
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
result.finishUpdates()
|
|
280
|
+
|
|
281
|
+
return result
|
|
282
|
+
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
get area() {
|
|
288
|
+
const result = this.height * this.width
|
|
289
|
+
return result
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
intersectsWithRectangle(rectangle: UIRectangle) {
|
|
294
|
+
|
|
295
|
+
return (this.intersectionRectangleWithRectangle(rectangle).area != 0)
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
// add some space around the rectangle
|
|
304
|
+
rectangleWithInsets(left: number, right: number, bottom: number, top: number) {
|
|
305
|
+
const result = this.copy()
|
|
306
|
+
result.min.x = this.min.x + left
|
|
307
|
+
result.max.x = this.max.x - right
|
|
308
|
+
result.min.y = this.min.y + top
|
|
309
|
+
result.max.y = this.max.y - bottom
|
|
310
|
+
return result
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
rectangleWithInset(inset: number) {
|
|
314
|
+
const result = this.rectangleWithInsets(inset, inset, inset, inset)
|
|
315
|
+
return result
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
rectangleWithHeight(height: number, centeredOnPosition: number = nil) {
|
|
319
|
+
|
|
320
|
+
if (isNaN(centeredOnPosition)) {
|
|
321
|
+
centeredOnPosition = nil
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const result = this.copy()
|
|
325
|
+
result.height = height
|
|
326
|
+
|
|
327
|
+
if (centeredOnPosition != nil) {
|
|
328
|
+
const change = height - this.height
|
|
329
|
+
result.offsetByPoint(new UIPoint(0, change * centeredOnPosition).scale(-1))
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return result
|
|
333
|
+
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
rectangleWithWidth(width: number, centeredOnPosition: number = nil) {
|
|
337
|
+
|
|
338
|
+
if (isNaN(centeredOnPosition)) {
|
|
339
|
+
centeredOnPosition = nil
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const result = this.copy()
|
|
343
|
+
result.width = width
|
|
344
|
+
|
|
345
|
+
if (centeredOnPosition != nil) {
|
|
346
|
+
const change = width - this.width
|
|
347
|
+
result.offsetByPoint(new UIPoint(change * centeredOnPosition, 0).scale(-1))
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return result
|
|
351
|
+
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
rectangleWithHeightRelativeToWidth(heightRatio: number = 1, centeredOnPosition: number = nil) {
|
|
355
|
+
|
|
356
|
+
const result = this.rectangleWithHeight(this.width * heightRatio, centeredOnPosition)
|
|
357
|
+
|
|
358
|
+
return result
|
|
359
|
+
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
rectangleWithWidthRelativeToHeight(widthRatio: number = 1, centeredOnPosition: number = nil) {
|
|
363
|
+
|
|
364
|
+
const result = this.rectangleWithWidth(this.height * widthRatio, centeredOnPosition)
|
|
365
|
+
|
|
366
|
+
return result
|
|
367
|
+
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
rectangleWithX(x: number, centeredOnPosition: number = 0) {
|
|
371
|
+
|
|
372
|
+
const result = this.copy()
|
|
373
|
+
result.x = x - result.width * centeredOnPosition
|
|
374
|
+
|
|
375
|
+
return result
|
|
376
|
+
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
rectangleWithY(y: number, centeredOnPosition: number = 0) {
|
|
380
|
+
|
|
381
|
+
const result = this.copy()
|
|
382
|
+
result.y = y - result.height * centeredOnPosition
|
|
383
|
+
|
|
384
|
+
return result
|
|
385
|
+
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
rectangleByAddingX(x: number) {
|
|
391
|
+
|
|
392
|
+
const result = this.copy()
|
|
393
|
+
result.x = this.x + x
|
|
394
|
+
|
|
395
|
+
return result
|
|
396
|
+
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
rectangleByAddingY(y: number) {
|
|
400
|
+
|
|
401
|
+
const result = this.copy()
|
|
402
|
+
result.y = this.y + y
|
|
403
|
+
|
|
404
|
+
return result
|
|
405
|
+
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
rectanglesBySplittingWidth(
|
|
413
|
+
weights: number[],
|
|
414
|
+
paddings: number | number[] = 0,
|
|
415
|
+
absoluteWidths: number | number[] = nil
|
|
416
|
+
) {
|
|
417
|
+
|
|
418
|
+
if (IS_NIL(paddings)) {
|
|
419
|
+
|
|
420
|
+
paddings = 1
|
|
421
|
+
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (!(paddings instanceof Array)) {
|
|
425
|
+
|
|
426
|
+
paddings = [paddings].arrayByRepeating(weights.length - 1)
|
|
427
|
+
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
paddings = paddings.arrayByTrimmingToLengthIfLonger(weights.length - 1)
|
|
431
|
+
|
|
432
|
+
if (!(absoluteWidths instanceof Array) && IS_NOT_NIL(absoluteWidths)) {
|
|
433
|
+
absoluteWidths = [absoluteWidths].arrayByRepeating(weights.length)
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const result: UIRectangle[] = []
|
|
437
|
+
const sumOfWeights = weights.reduce(function (a, b, index) {
|
|
438
|
+
if (IS_NOT_NIL(absoluteWidths[index])) {
|
|
439
|
+
b = 0
|
|
440
|
+
}
|
|
441
|
+
return a + b
|
|
442
|
+
}, 0)
|
|
443
|
+
const sumOfPaddings = paddings.summedValue
|
|
444
|
+
const sumOfAbsoluteWidths = (absoluteWidths as number[]).summedValue
|
|
445
|
+
const totalRelativeWidth = this.width - sumOfPaddings - sumOfAbsoluteWidths
|
|
446
|
+
var previousCellMaxX = this.x
|
|
447
|
+
|
|
448
|
+
for (var i = 0; i < weights.length; i++) {
|
|
449
|
+
|
|
450
|
+
var resultWidth: number
|
|
451
|
+
if (IS_NOT_NIL(absoluteWidths[i])) {
|
|
452
|
+
|
|
453
|
+
resultWidth = absoluteWidths[i] || 0
|
|
454
|
+
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
|
|
458
|
+
resultWidth = totalRelativeWidth * (weights[i] / sumOfWeights)
|
|
459
|
+
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const rectangle = this.rectangleWithWidth(resultWidth)
|
|
463
|
+
|
|
464
|
+
var padding = 0
|
|
465
|
+
if (paddings.length > i && paddings[i]) {
|
|
466
|
+
padding = paddings[i]
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
rectangle.x = previousCellMaxX
|
|
470
|
+
previousCellMaxX = rectangle.max.x + padding
|
|
471
|
+
//rectangle = rectangle.rectangleWithInsets(0, padding, 0, 0);
|
|
472
|
+
result.push(rectangle)
|
|
473
|
+
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return result
|
|
477
|
+
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
rectanglesBySplittingHeight(
|
|
481
|
+
weights: number[],
|
|
482
|
+
paddings: number | number[] = 0,
|
|
483
|
+
absoluteHeights: number | number[] = nil
|
|
484
|
+
) {
|
|
485
|
+
|
|
486
|
+
if (IS_NIL(paddings)) {
|
|
487
|
+
|
|
488
|
+
paddings = 1
|
|
489
|
+
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (!(paddings instanceof Array)) {
|
|
493
|
+
|
|
494
|
+
paddings = [paddings].arrayByRepeating(weights.length - 1)
|
|
495
|
+
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
paddings = paddings.arrayByTrimmingToLengthIfLonger(weights.length - 1)
|
|
499
|
+
|
|
500
|
+
if (!(absoluteHeights instanceof Array) && IS_NOT_NIL(absoluteHeights)) {
|
|
501
|
+
absoluteHeights = [absoluteHeights].arrayByRepeating(weights.length)
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const result: UIRectangle[] = []
|
|
505
|
+
const sumOfWeights = weights.reduce(function (a, b, index) {
|
|
506
|
+
if (IS_NOT_NIL(absoluteHeights[index])) {
|
|
507
|
+
b = 0
|
|
508
|
+
}
|
|
509
|
+
return a + b
|
|
510
|
+
}, 0)
|
|
511
|
+
const sumOfPaddings = paddings.summedValue
|
|
512
|
+
const sumOfAbsoluteHeights = (absoluteHeights as number[]).summedValue
|
|
513
|
+
const totalRelativeHeight = this.height - sumOfPaddings - sumOfAbsoluteHeights
|
|
514
|
+
var previousCellMaxY = this.y
|
|
515
|
+
|
|
516
|
+
for (var i = 0; i < weights.length; i++) {
|
|
517
|
+
var resultHeight: number
|
|
518
|
+
if (IS_NOT_NIL(absoluteHeights[i])) {
|
|
519
|
+
|
|
520
|
+
resultHeight = absoluteHeights[i] || 0
|
|
521
|
+
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
|
|
525
|
+
resultHeight = totalRelativeHeight * (weights[i] / sumOfWeights)
|
|
526
|
+
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const rectangle = this.rectangleWithHeight(resultHeight)
|
|
530
|
+
|
|
531
|
+
var padding = 0
|
|
532
|
+
if (paddings.length > i && paddings[i]) {
|
|
533
|
+
padding = paddings[i]
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
rectangle.y = previousCellMaxY
|
|
537
|
+
previousCellMaxY = rectangle.max.y + padding
|
|
538
|
+
//rectangle = rectangle.rectangleWithInsets(0, 0, padding, 0);
|
|
539
|
+
result.push(rectangle)
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return result
|
|
543
|
+
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
rectanglesByEquallySplittingWidth(numberOfFrames: number, padding: number = 0) {
|
|
551
|
+
const result: UIRectangle[] = []
|
|
552
|
+
const totalPadding = padding * (numberOfFrames - 1)
|
|
553
|
+
const resultWidth = (this.width - totalPadding) / numberOfFrames
|
|
554
|
+
for (var i = 0; i < numberOfFrames; i++) {
|
|
555
|
+
const rectangle = this.rectangleWithWidth(resultWidth, i / (numberOfFrames - 1))
|
|
556
|
+
result.push(rectangle)
|
|
557
|
+
}
|
|
558
|
+
return result
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
rectanglesByEquallySplittingHeight(numberOfFrames: number, padding: number = 0) {
|
|
562
|
+
const result: UIRectangle[] = []
|
|
563
|
+
const totalPadding = padding * (numberOfFrames - 1)
|
|
564
|
+
const resultHeight = (this.height - totalPadding) / numberOfFrames
|
|
565
|
+
for (var i = 0; i < numberOfFrames; i++) {
|
|
566
|
+
const rectangle = this.rectangleWithHeight(resultHeight, i / (numberOfFrames - 1))
|
|
567
|
+
result.push(rectangle)
|
|
568
|
+
}
|
|
569
|
+
return result
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
distributeViewsAlongWidth(
|
|
575
|
+
views: UIView[],
|
|
576
|
+
weights: number | number[] = 1,
|
|
577
|
+
paddings?: number | number[],
|
|
578
|
+
absoluteWidths?: number | number[]
|
|
579
|
+
) {
|
|
580
|
+
|
|
581
|
+
if (!(weights instanceof Array)) {
|
|
582
|
+
weights = [weights].arrayByRepeating(views.length)
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
const frames = this.rectanglesBySplittingWidth(weights, paddings, absoluteWidths)
|
|
586
|
+
|
|
587
|
+
frames.forEach((frame, index, array) => FIRST_OR_NIL(views[index]).frame = frame)
|
|
588
|
+
|
|
589
|
+
return this
|
|
590
|
+
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
distributeViewsAlongHeight(
|
|
594
|
+
views: UIView[],
|
|
595
|
+
weights: number | number[] = 1,
|
|
596
|
+
paddings?: number | number[],
|
|
597
|
+
absoluteHeights?: number | number[]
|
|
598
|
+
) {
|
|
599
|
+
|
|
600
|
+
if (!(weights instanceof Array)) {
|
|
601
|
+
weights = [weights].arrayByRepeating(views.length)
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const frames = this.rectanglesBySplittingHeight(weights, paddings, absoluteHeights)
|
|
605
|
+
|
|
606
|
+
frames.forEach((frame, index, array) => FIRST_OR_NIL(views[index]).frame = frame)
|
|
607
|
+
|
|
608
|
+
return this
|
|
609
|
+
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
distributeViewsEquallyAlongWidth(views: UIView[], padding: number) {
|
|
614
|
+
|
|
615
|
+
const frames = this.rectanglesByEquallySplittingWidth(views.length, padding)
|
|
616
|
+
|
|
617
|
+
frames.forEach(function (frame, index, array) {
|
|
618
|
+
views[index].frame = frame
|
|
619
|
+
})
|
|
620
|
+
|
|
621
|
+
return this
|
|
622
|
+
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
distributeViewsEquallyAlongHeight(views: UIView[], padding: number) {
|
|
626
|
+
|
|
627
|
+
const frames = this.rectanglesByEquallySplittingHeight(views.length, padding)
|
|
628
|
+
|
|
629
|
+
frames.forEach(function (frame, index, array) {
|
|
630
|
+
views[index].frame = frame
|
|
631
|
+
})
|
|
632
|
+
|
|
633
|
+
return this
|
|
634
|
+
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
rectangleForNextRow(padding: number = 0, height = this.height) {
|
|
640
|
+
const result = this.rectangleWithY(this.max.y + padding)
|
|
641
|
+
if (height != this.height) {
|
|
642
|
+
result.height = height
|
|
643
|
+
}
|
|
644
|
+
return result
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
rectangleForNextColumn(padding: number = 0, width = this.width) {
|
|
648
|
+
const result = this.rectangleWithX(this.max.x + padding)
|
|
649
|
+
if (width != this.width) {
|
|
650
|
+
result.width = width
|
|
651
|
+
}
|
|
652
|
+
return result
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
rectangleForPreviousRow(padding: number = 0) {
|
|
656
|
+
const result = this.rectangleWithY(this.min.y - this.height - padding)
|
|
657
|
+
return result
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
rectangleForPreviousColumn(padding: number = 0) {
|
|
661
|
+
const result = this.rectangleWithX(this.min.x - this.width - padding)
|
|
662
|
+
return result
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
// Bounding box
|
|
668
|
+
static boundingBoxForPoints(points) {
|
|
669
|
+
const result = new UIRectangle()
|
|
670
|
+
for (var i = 0; i < points.length; i++) {
|
|
671
|
+
result.updateByAddingPoint(points[i])
|
|
672
|
+
}
|
|
673
|
+
return result
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
beginUpdates() {
|
|
678
|
+
this._isBeingUpdated = YES
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
finishUpdates() {
|
|
682
|
+
this._isBeingUpdated = NO
|
|
683
|
+
this.didChange()
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
didChange() {
|
|
688
|
+
|
|
689
|
+
// Callback to be set by delegate
|
|
690
|
+
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
_rectanglePointDidChange() {
|
|
694
|
+
|
|
695
|
+
if (!this._isBeingUpdated) {
|
|
696
|
+
|
|
697
|
+
this.didChange()
|
|
698
|
+
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|