1
1
#[ cfg( test) ]
2
2
mod measure {
3
+ use stretch:: node:: MeasureFunc ;
3
4
use stretch:: number:: OrElse ;
4
5
5
6
#[ test]
6
7
fn measure_root ( ) {
7
8
let mut stretch = stretch:: node:: Stretch :: new ( ) ;
8
9
let node = stretch
9
- . new_leaf ( stretch:: style:: Style { ..Default :: default ( ) } , |constraint| stretch:: geometry:: Size {
10
- width : constraint. width . or_else ( 100.0 ) ,
11
- height : constraint. height . or_else ( 100.0 ) ,
12
- } )
10
+ . new_leaf (
11
+ stretch:: style:: Style { ..Default :: default ( ) } ,
12
+ MeasureFunc :: Raw ( |constraint| stretch:: geometry:: Size {
13
+ width : constraint. width . or_else ( 100.0 ) ,
14
+ height : constraint. height . or_else ( 100.0 ) ,
15
+ } ) ,
16
+ )
13
17
. unwrap ( ) ;
14
18
15
19
stretch. compute_layout ( node, stretch:: geometry:: Size :: undefined ( ) ) . unwrap ( ) ;
@@ -23,10 +27,13 @@ mod measure {
23
27
let mut stretch = stretch:: node:: Stretch :: new ( ) ;
24
28
25
29
let child = stretch
26
- . new_leaf ( stretch:: style:: Style { ..Default :: default ( ) } , |constraint| stretch:: geometry:: Size {
27
- width : constraint. width . or_else ( 100.0 ) ,
28
- height : constraint. height . or_else ( 100.0 ) ,
29
- } )
30
+ . new_leaf (
31
+ stretch:: style:: Style { ..Default :: default ( ) } ,
32
+ MeasureFunc :: Raw ( |constraint| stretch:: geometry:: Size {
33
+ width : constraint. width . or_else ( 100.0 ) ,
34
+ height : constraint. height . or_else ( 100.0 ) ,
35
+ } ) ,
36
+ )
30
37
. unwrap ( ) ;
31
38
32
39
let node = stretch. new_node ( stretch:: style:: Style { ..Default :: default ( ) } , & [ child] ) . unwrap ( ) ;
@@ -43,10 +50,13 @@ mod measure {
43
50
fn measure_child_constraint ( ) {
44
51
let mut stretch = stretch:: node:: Stretch :: new ( ) ;
45
52
let child = stretch
46
- . new_leaf ( stretch:: style:: Style { ..Default :: default ( ) } , |constraint| stretch:: geometry:: Size {
47
- width : constraint. width . or_else ( 100.0 ) ,
48
- height : constraint. height . or_else ( 100.0 ) ,
49
- } )
53
+ . new_leaf (
54
+ stretch:: style:: Style { ..Default :: default ( ) } ,
55
+ MeasureFunc :: Raw ( |constraint| stretch:: geometry:: Size {
56
+ width : constraint. width . or_else ( 100.0 ) ,
57
+ height : constraint. height . or_else ( 100.0 ) ,
58
+ } ) ,
59
+ )
50
60
. unwrap ( ) ;
51
61
52
62
let node = stretch
@@ -75,10 +85,13 @@ mod measure {
75
85
fn measure_child_constraint_padding_parent ( ) {
76
86
let mut stretch = stretch:: node:: Stretch :: new ( ) ;
77
87
let child = stretch
78
- . new_leaf ( stretch:: style:: Style { ..Default :: default ( ) } , |constraint| stretch:: geometry:: Size {
79
- width : constraint. width . or_else ( 100.0 ) ,
80
- height : constraint. height . or_else ( 100.0 ) ,
81
- } )
88
+ . new_leaf (
89
+ stretch:: style:: Style { ..Default :: default ( ) } ,
90
+ MeasureFunc :: Raw ( |constraint| stretch:: geometry:: Size {
91
+ width : constraint. width . or_else ( 100.0 ) ,
92
+ height : constraint. height . or_else ( 100.0 ) ,
93
+ } ) ,
94
+ )
82
95
. unwrap ( ) ;
83
96
84
97
let node = stretch
@@ -125,12 +138,13 @@ mod measure {
125
138
. unwrap ( ) ;
126
139
127
140
let child1 = stretch
128
- . new_leaf ( stretch:: style:: Style { flex_grow : 1.0 , ..Default :: default ( ) } , |constraint| {
129
- stretch:: geometry:: Size {
141
+ . new_leaf (
142
+ stretch:: style:: Style { flex_grow : 1.0 , ..Default :: default ( ) } ,
143
+ MeasureFunc :: Raw ( |constraint| stretch:: geometry:: Size {
130
144
width : constraint. width . or_else ( 10.0 ) ,
131
145
height : constraint. height . or_else ( 50.0 ) ,
132
- }
133
- } )
146
+ } ) ,
147
+ )
134
148
. unwrap ( ) ;
135
149
136
150
let node = stretch
@@ -170,10 +184,13 @@ mod measure {
170
184
. unwrap ( ) ;
171
185
172
186
let child1 = stretch
173
- . new_leaf ( stretch:: style:: Style { ..Default :: default ( ) } , |constraint| stretch:: geometry:: Size {
174
- width : constraint. width . or_else ( 100.0 ) ,
175
- height : constraint. height . or_else ( 50.0 ) ,
176
- } )
187
+ . new_leaf (
188
+ stretch:: style:: Style { ..Default :: default ( ) } ,
189
+ MeasureFunc :: Raw ( |constraint| stretch:: geometry:: Size {
190
+ width : constraint. width . or_else ( 100.0 ) ,
191
+ height : constraint. height . or_else ( 50.0 ) ,
192
+ } ) ,
193
+ )
177
194
. unwrap ( ) ;
178
195
179
196
let node = stretch
@@ -212,11 +229,14 @@ mod measure {
212
229
. unwrap ( ) ;
213
230
214
231
let child1 = stretch
215
- . new_leaf ( stretch:: style:: Style { flex_grow : 1.0 , ..Default :: default ( ) } , |constraint| {
216
- let width = constraint. width . or_else ( 10.0 ) ;
217
- let height = constraint. height . or_else ( width * 2.0 ) ;
218
- stretch:: geometry:: Size { width, height }
219
- } )
232
+ . new_leaf (
233
+ stretch:: style:: Style { flex_grow : 1.0 , ..Default :: default ( ) } ,
234
+ MeasureFunc :: Raw ( |constraint| {
235
+ let width = constraint. width . or_else ( 10.0 ) ;
236
+ let height = constraint. height . or_else ( width * 2.0 ) ;
237
+ stretch:: geometry:: Size { width, height }
238
+ } ) ,
239
+ )
220
240
. unwrap ( ) ;
221
241
222
242
let node = stretch
@@ -258,11 +278,14 @@ mod measure {
258
278
. unwrap ( ) ;
259
279
260
280
let child1 = stretch
261
- . new_leaf ( stretch:: style:: Style { ..Default :: default ( ) } , |constraint| {
262
- let width = constraint. width . or_else ( 100.0 ) ;
263
- let height = constraint. height . or_else ( width * 2.0 ) ;
264
- stretch:: geometry:: Size { width, height }
265
- } )
281
+ . new_leaf (
282
+ stretch:: style:: Style { ..Default :: default ( ) } ,
283
+ MeasureFunc :: Raw ( |constraint| {
284
+ let width = constraint. width . or_else ( 100.0 ) ;
285
+ let height = constraint. height . or_else ( width * 2.0 ) ;
286
+ stretch:: geometry:: Size { width, height }
287
+ } ) ,
288
+ )
266
289
. unwrap ( ) ;
267
290
268
291
let node = stretch
@@ -290,11 +313,14 @@ mod measure {
290
313
let mut stretch = stretch:: node:: Stretch :: new ( ) ;
291
314
292
315
let child = stretch
293
- . new_leaf ( stretch:: style:: Style { ..Default :: default ( ) } , |constraint| {
294
- let height = constraint. height . or_else ( 50.0 ) ;
295
- let width = constraint. width . or_else ( height) ;
296
- stretch:: geometry:: Size { width, height }
297
- } )
316
+ . new_leaf (
317
+ stretch:: style:: Style { ..Default :: default ( ) } ,
318
+ MeasureFunc :: Raw ( |constraint| {
319
+ let height = constraint. height . or_else ( 50.0 ) ;
320
+ let width = constraint. width . or_else ( height) ;
321
+ stretch:: geometry:: Size { width, height }
322
+ } ) ,
323
+ )
298
324
. unwrap ( ) ;
299
325
300
326
let node = stretch
@@ -328,10 +354,10 @@ mod measure {
328
354
} ,
329
355
..Default :: default ( )
330
356
} ,
331
- |constraint| stretch:: geometry:: Size {
357
+ MeasureFunc :: Raw ( |constraint| stretch:: geometry:: Size {
332
358
width : constraint. width . or_else ( 100.0 ) ,
333
359
height : constraint. height . or_else ( 100.0 ) ,
334
- } ,
360
+ } ) ,
335
361
)
336
362
. unwrap ( ) ;
337
363
@@ -354,10 +380,10 @@ mod measure {
354
380
} ,
355
381
..Default :: default ( )
356
382
} ,
357
- |constraint| stretch:: geometry:: Size {
383
+ MeasureFunc :: Raw ( |constraint| stretch:: geometry:: Size {
358
384
width : constraint. width . or_else ( 100.0 ) ,
359
385
height : constraint. height . or_else ( 100.0 ) ,
360
- } ,
386
+ } ) ,
361
387
)
362
388
. unwrap ( ) ;
363
389
@@ -389,10 +415,10 @@ mod measure {
389
415
flex_grow : 1.0 ,
390
416
..Default :: default ( )
391
417
} ,
392
- |constraint| stretch:: geometry:: Size {
418
+ MeasureFunc :: Raw ( |constraint| stretch:: geometry:: Size {
393
419
width : constraint. width . or_else ( 100.0 ) ,
394
420
height : constraint. height . or_else ( 100.0 ) ,
395
- } ,
421
+ } ) ,
396
422
)
397
423
. unwrap ( ) ;
398
424
@@ -421,10 +447,13 @@ mod measure {
421
447
fn stretch_overrides_measure ( ) {
422
448
let mut stretch = stretch:: node:: Stretch :: new ( ) ;
423
449
let child = stretch
424
- . new_leaf ( stretch:: style:: Style { ..Default :: default ( ) } , |constraint| stretch:: geometry:: Size {
425
- width : constraint. width . or_else ( 50.0 ) ,
426
- height : constraint. height . or_else ( 50.0 ) ,
427
- } )
450
+ . new_leaf (
451
+ stretch:: style:: Style { ..Default :: default ( ) } ,
452
+ MeasureFunc :: Raw ( |constraint| stretch:: geometry:: Size {
453
+ width : constraint. width . or_else ( 50.0 ) ,
454
+ height : constraint. height . or_else ( 50.0 ) ,
455
+ } ) ,
456
+ )
428
457
. unwrap ( ) ;
429
458
430
459
let node = stretch
@@ -452,10 +481,10 @@ mod measure {
452
481
let child = stretch
453
482
. new_leaf (
454
483
stretch:: style:: Style { position_type : stretch:: style:: PositionType :: Absolute , ..Default :: default ( ) } ,
455
- |constraint| stretch:: geometry:: Size {
484
+ MeasureFunc :: Raw ( |constraint| stretch:: geometry:: Size {
456
485
width : constraint. width . or_else ( 50.0 ) ,
457
486
height : constraint. height . or_else ( 50.0 ) ,
458
- } ,
487
+ } ) ,
459
488
)
460
489
. unwrap ( ) ;
461
490
@@ -482,10 +511,10 @@ mod measure {
482
511
fn ignore_invalid_measure ( ) {
483
512
let mut stretch = stretch:: node:: Stretch :: new ( ) ;
484
513
let child = stretch
485
- . new_leaf ( stretch :: style :: Style { flex_grow : 1.0 , .. Default :: default ( ) } , |_| stretch :: geometry :: Size {
486
- width : 200.0 ,
487
- height : 200.0 ,
488
- } )
514
+ . new_leaf (
515
+ stretch :: style :: Style { flex_grow : 1.0 , .. Default :: default ( ) } ,
516
+ MeasureFunc :: Raw ( |_| stretch :: geometry :: Size { width : 200.0 , height : 200.0 } ) ,
517
+ )
489
518
. unwrap ( ) ;
490
519
491
520
let node = stretch
@@ -515,13 +544,16 @@ mod measure {
515
544
static NUM_MEASURES : atomic:: AtomicU32 = atomic:: AtomicU32 :: new ( 0 ) ;
516
545
517
546
let grandchild = stretch
518
- . new_leaf ( stretch:: style:: Style { ..Default :: default ( ) } , |constraint| {
519
- NUM_MEASURES . fetch_add ( 1 , atomic:: Ordering :: Relaxed ) ;
520
- stretch:: geometry:: Size {
521
- width : constraint. width . or_else ( 50.0 ) ,
522
- height : constraint. height . or_else ( 50.0 ) ,
523
- }
524
- } )
547
+ . new_leaf (
548
+ stretch:: style:: Style { ..Default :: default ( ) } ,
549
+ MeasureFunc :: Raw ( |constraint| {
550
+ NUM_MEASURES . fetch_add ( 1 , atomic:: Ordering :: Relaxed ) ;
551
+ stretch:: geometry:: Size {
552
+ width : constraint. width . or_else ( 50.0 ) ,
553
+ height : constraint. height . or_else ( 50.0 ) ,
554
+ }
555
+ } ) ,
556
+ )
525
557
. unwrap ( ) ;
526
558
527
559
let child = stretch. new_node ( stretch:: style:: Style { ..Default :: default ( ) } , & [ grandchild] ) . unwrap ( ) ;
0 commit comments