@@ -15,12 +15,10 @@ use num_traits::float::FloatCore;
1515/// Compute the number of rows and columns in the explicit grid
1616pub ( crate ) fn compute_explicit_grid_size_in_axis (
1717 style : & impl GridContainerStyle ,
18+ template : & [ TrackSizingFunction ] ,
1819 inner_container_size : Size < Option < f32 > > ,
1920 axis : AbsoluteAxis ,
2021) -> u16 {
21- // Load the grid-template-rows or grid-template-columns definition (depending on the axis)
22- let template = style. grid_template_tracks ( axis) ;
23-
2422 // If template contains no tracks, then there are trivially zero explicit tracks
2523 if template. is_empty ( ) {
2624 return 0 ;
@@ -294,8 +292,18 @@ mod test {
294292 fn explicit_grid_sizing_no_repeats ( ) {
295293 let grid_style = ( 600.0 , 600.0 , 2 , 4 ) . into_grid ( ) ;
296294 let preferred_size = grid_style. size . map ( |s| s. into_option ( ) ) ;
297- let width = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Horizontal ) ;
298- let height = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Vertical ) ;
295+ let width = compute_explicit_grid_size_in_axis (
296+ & grid_style,
297+ & grid_style. grid_template_columns ,
298+ preferred_size,
299+ AbsoluteAxis :: Horizontal ,
300+ ) ;
301+ let height = compute_explicit_grid_size_in_axis (
302+ & grid_style,
303+ & grid_style. grid_template_rows ,
304+ preferred_size,
305+ AbsoluteAxis :: Vertical ,
306+ ) ;
299307 assert_eq ! ( width, 2 ) ;
300308 assert_eq ! ( height, 4 ) ;
301309 }
@@ -311,8 +319,18 @@ mod test {
311319 ..Default :: default ( )
312320 } ;
313321 let preferred_size = grid_style. size . map ( |s| s. into_option ( ) ) ;
314- let width = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Horizontal ) ;
315- let height = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Vertical ) ;
322+ let width = compute_explicit_grid_size_in_axis (
323+ & grid_style,
324+ & grid_style. grid_template_columns ,
325+ preferred_size,
326+ AbsoluteAxis :: Horizontal ,
327+ ) ;
328+ let height = compute_explicit_grid_size_in_axis (
329+ & grid_style,
330+ & grid_style. grid_template_rows ,
331+ preferred_size,
332+ AbsoluteAxis :: Vertical ,
333+ ) ;
316334 assert_eq ! ( width, 3 ) ;
317335 assert_eq ! ( height, 4 ) ;
318336 }
@@ -328,8 +346,18 @@ mod test {
328346 ..Default :: default ( )
329347 } ;
330348 let preferred_size = grid_style. size . map ( |s| s. into_option ( ) ) ;
331- let width = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Horizontal ) ;
332- let height = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Vertical ) ;
349+ let width = compute_explicit_grid_size_in_axis (
350+ & grid_style,
351+ & grid_style. grid_template_columns ,
352+ preferred_size,
353+ AbsoluteAxis :: Horizontal ,
354+ ) ;
355+ let height = compute_explicit_grid_size_in_axis (
356+ & grid_style,
357+ & grid_style. grid_template_rows ,
358+ preferred_size,
359+ AbsoluteAxis :: Vertical ,
360+ ) ;
333361 assert_eq ! ( width, 3 ) ;
334362 assert_eq ! ( height, 4 ) ;
335363 }
@@ -345,8 +373,18 @@ mod test {
345373 ..Default :: default ( )
346374 } ;
347375 let inner_container_size = Size { width : Some ( 120.0 ) , height : Some ( 80.0 ) } ;
348- let width = compute_explicit_grid_size_in_axis ( & grid_style, inner_container_size, AbsoluteAxis :: Horizontal ) ;
349- let height = compute_explicit_grid_size_in_axis ( & grid_style, inner_container_size, AbsoluteAxis :: Vertical ) ;
376+ let width = compute_explicit_grid_size_in_axis (
377+ & grid_style,
378+ & grid_style. grid_template_columns ,
379+ inner_container_size,
380+ AbsoluteAxis :: Horizontal ,
381+ ) ;
382+ let height = compute_explicit_grid_size_in_axis (
383+ & grid_style,
384+ & grid_style. grid_template_rows ,
385+ inner_container_size,
386+ AbsoluteAxis :: Vertical ,
387+ ) ;
350388 assert_eq ! ( width, 3 ) ;
351389 assert_eq ! ( height, 4 ) ;
352390 }
@@ -362,8 +400,18 @@ mod test {
362400 ..Default :: default ( )
363401 } ;
364402 let inner_container_size = Size { width : Some ( 140.0 ) , height : Some ( 90.0 ) } ;
365- let width = compute_explicit_grid_size_in_axis ( & grid_style, inner_container_size, AbsoluteAxis :: Horizontal ) ;
366- let height = compute_explicit_grid_size_in_axis ( & grid_style, inner_container_size, AbsoluteAxis :: Vertical ) ;
403+ let width = compute_explicit_grid_size_in_axis (
404+ & grid_style,
405+ & grid_style. grid_template_columns ,
406+ inner_container_size,
407+ AbsoluteAxis :: Horizontal ,
408+ ) ;
409+ let height = compute_explicit_grid_size_in_axis (
410+ & grid_style,
411+ & grid_style. grid_template_rows ,
412+ inner_container_size,
413+ AbsoluteAxis :: Vertical ,
414+ ) ;
367415 assert_eq ! ( width, 4 ) ;
368416 assert_eq ! ( height, 5 ) ;
369417 }
@@ -379,8 +427,18 @@ mod test {
379427 ..Default :: default ( )
380428 } ;
381429 let preferred_size = grid_style. size . map ( |s| s. into_option ( ) ) ;
382- let width = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Horizontal ) ;
383- let height = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Vertical ) ;
430+ let width = compute_explicit_grid_size_in_axis (
431+ & grid_style,
432+ & grid_style. grid_template_columns ,
433+ preferred_size,
434+ AbsoluteAxis :: Horizontal ,
435+ ) ;
436+ let height = compute_explicit_grid_size_in_axis (
437+ & grid_style,
438+ & grid_style. grid_template_rows ,
439+ preferred_size,
440+ AbsoluteAxis :: Vertical ,
441+ ) ;
384442 assert_eq ! ( width, 4 ) ; // 2 repetitions * 2 repeated tracks = 4 tracks in total
385443 assert_eq ! ( height, 6 ) ; // 3 repetitions * 2 repeated tracks = 4 tracks in total
386444 }
@@ -397,8 +455,18 @@ mod test {
397455 ..Default :: default ( )
398456 } ;
399457 let preferred_size = grid_style. size . map ( |s| s. into_option ( ) ) ;
400- let width = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Horizontal ) ;
401- let height = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Vertical ) ;
458+ let width = compute_explicit_grid_size_in_axis (
459+ & grid_style,
460+ & grid_style. grid_template_columns ,
461+ preferred_size,
462+ AbsoluteAxis :: Horizontal ,
463+ ) ;
464+ let height = compute_explicit_grid_size_in_axis (
465+ & grid_style,
466+ & grid_style. grid_template_rows ,
467+ preferred_size,
468+ AbsoluteAxis :: Vertical ,
469+ ) ;
402470 assert_eq ! ( width, 2 ) ; // 2 tracks + 1 gap
403471 assert_eq ! ( height, 3 ) ; // 3 tracks + 2 gaps
404472 }
@@ -414,8 +482,18 @@ mod test {
414482 ..Default :: default ( )
415483 } ;
416484 let preferred_size = grid_style. size . map ( |s| s. into_option ( ) ) ;
417- let width = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Horizontal ) ;
418- let height = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Vertical ) ;
485+ let width = compute_explicit_grid_size_in_axis (
486+ & grid_style,
487+ & grid_style. grid_template_columns ,
488+ preferred_size,
489+ AbsoluteAxis :: Horizontal ,
490+ ) ;
491+ let height = compute_explicit_grid_size_in_axis (
492+ & grid_style,
493+ & grid_style. grid_template_rows ,
494+ preferred_size,
495+ AbsoluteAxis :: Vertical ,
496+ ) ;
419497 assert_eq ! ( width, 3 ) ;
420498 assert_eq ! ( height, 1 ) ;
421499 }
@@ -432,8 +510,18 @@ mod test {
432510 ..Default :: default ( )
433511 } ;
434512 let preferred_size = grid_style. size . map ( |s| s. into_option ( ) ) ;
435- let width = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Horizontal ) ;
436- let height = compute_explicit_grid_size_in_axis ( & grid_style, preferred_size, AbsoluteAxis :: Vertical ) ;
513+ let width = compute_explicit_grid_size_in_axis (
514+ & grid_style,
515+ & grid_style. grid_template_columns ,
516+ preferred_size,
517+ AbsoluteAxis :: Horizontal ,
518+ ) ;
519+ let height = compute_explicit_grid_size_in_axis (
520+ & grid_style,
521+ & grid_style. grid_template_rows ,
522+ preferred_size,
523+ AbsoluteAxis :: Vertical ,
524+ ) ;
437525 assert_eq ! ( width, 3 ) ; // 3 tracks + 2 gaps
438526 assert_eq ! ( height, 2 ) ; // 2 tracks + 1 gap
439527 }
@@ -450,8 +538,18 @@ mod test {
450538 ..Default :: default ( )
451539 } ;
452540 let inner_container_size = Size { width : Some ( 100.0 ) , height : Some ( 80.0 ) } ;
453- let width = compute_explicit_grid_size_in_axis ( & grid_style, inner_container_size, AbsoluteAxis :: Horizontal ) ;
454- let height = compute_explicit_grid_size_in_axis ( & grid_style, inner_container_size, AbsoluteAxis :: Vertical ) ;
541+ let width = compute_explicit_grid_size_in_axis (
542+ & grid_style,
543+ & grid_style. grid_template_columns ,
544+ inner_container_size,
545+ AbsoluteAxis :: Horizontal ,
546+ ) ;
547+ let height = compute_explicit_grid_size_in_axis (
548+ & grid_style,
549+ & grid_style. grid_template_rows ,
550+ inner_container_size,
551+ AbsoluteAxis :: Vertical ,
552+ ) ;
455553 assert_eq ! ( width, 5 ) ; // 40px horizontal padding
456554 assert_eq ! ( height, 4 ) ; // 20px vertical padding
457555 }
0 commit comments