@@ -14,6 +14,50 @@ fn sum_axis_gaps<L: LengthNum>(gap: L, num_items: usize) -> L {
14
14
}
15
15
}
16
16
17
+ #[ inline( always) ]
18
+ fn resolve_row_gap < T : LayoutTreeNode > (
19
+ style : & T :: Style ,
20
+ node : & T ,
21
+ inner_size : & Normalized < OptionSize < T :: Length > > ,
22
+ ) -> T :: Length {
23
+ style. row_gap ( ) . resolve ( inner_size. height , node) . or_zero ( )
24
+ }
25
+
26
+ #[ inline( always) ]
27
+ fn resolve_column_gap < T : LayoutTreeNode > (
28
+ style : & T :: Style ,
29
+ node : & T ,
30
+ inner_size : & Normalized < OptionSize < T :: Length > > ,
31
+ ) -> T :: Length {
32
+ style. column_gap ( ) . resolve ( inner_size. width , node) . or_zero ( )
33
+ }
34
+
35
+ #[ inline( always) ]
36
+ fn main_axis_gap < T : LayoutTreeNode > (
37
+ dir : AxisDirection ,
38
+ style : & T :: Style ,
39
+ node : & T ,
40
+ inner_size : & Normalized < OptionSize < T :: Length > > ,
41
+ ) -> T :: Length {
42
+ match dir {
43
+ AxisDirection :: Horizontal => resolve_column_gap ( style, node, inner_size) ,
44
+ AxisDirection :: Vertical => resolve_row_gap ( style, node, inner_size) ,
45
+ }
46
+ }
47
+
48
+ #[ inline( always) ]
49
+ fn cross_axis_gap < T : LayoutTreeNode > (
50
+ dir : AxisDirection ,
51
+ style : & T :: Style ,
52
+ node : & T ,
53
+ inner_size : & Normalized < OptionSize < T :: Length > > ,
54
+ ) -> T :: Length {
55
+ match dir {
56
+ AxisDirection :: Horizontal => resolve_row_gap ( style, node, inner_size) ,
57
+ AxisDirection :: Vertical => resolve_column_gap ( style, node, inner_size) ,
58
+ }
59
+ }
60
+
17
61
pub ( crate ) fn align_self < T : LayoutTreeNode > ( child : & T :: Style , parent : & T :: Style ) -> AlignSelf {
18
62
let s = child. align_self ( ) ;
19
63
if s == AlignSelf :: Auto {
@@ -347,10 +391,7 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
347
391
} ) ;
348
392
} else {
349
393
let mut flex_items = & mut flex_items[ ..] ;
350
- let main_axis_gap = style
351
- . row_gap ( )
352
- . resolve ( requested_inner_size. main_size ( dir) , node)
353
- . or_zero ( ) ;
394
+ let main_axis_gap = main_axis_gap :: < T > ( dir, style, node, & requested_inner_size) ;
354
395
while !flex_items. is_empty ( ) {
355
396
let mut line_length = T :: Length :: zero ( ) ;
356
397
let index = flex_items
@@ -392,10 +433,7 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
392
433
let multi_flex_line = flex_lines. len ( ) > 1 ;
393
434
for line in & mut flex_lines {
394
435
let total_main_axis_gap = sum_axis_gaps (
395
- style
396
- . row_gap ( )
397
- . resolve ( requested_inner_size. main_size ( dir) , node)
398
- . or_zero ( ) ,
436
+ main_axis_gap :: < T > ( dir, style, node, & requested_inner_size) ,
399
437
line. items . len ( ) ,
400
438
) ;
401
439
// 1. Determine the used flex factor. Sum the outer hypothetical main sizes of all
@@ -883,10 +921,7 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
883
921
let min_inner_cross =
884
922
self_min_max_limit. cross_size ( requested_cross_size, dir) - padding_border_cross;
885
923
let total_cross_axis_gap = sum_axis_gaps (
886
- style
887
- . column_gap ( )
888
- . resolve ( requested_inner_size. main_size ( dir) , node)
889
- . or_zero ( ) ,
924
+ cross_axis_gap :: < T > ( dir, style, node, & requested_inner_size) ,
890
925
flex_lines. len ( ) ,
891
926
) ;
892
927
let line_total_cross: T :: Length =
@@ -1018,10 +1053,7 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
1018
1053
1019
1054
for line in & mut flex_lines {
1020
1055
let total_main_axis_gap = sum_axis_gaps (
1021
- style
1022
- . row_gap ( )
1023
- . resolve ( requested_inner_size. main_size ( dir) , node)
1024
- . or_zero ( ) ,
1056
+ main_axis_gap :: < T > ( dir, style, node, & requested_inner_size) ,
1025
1057
line. items . len ( ) ,
1026
1058
) ;
1027
1059
let used_space: T :: Length = total_main_axis_gap
@@ -1069,10 +1101,7 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
1069
1101
let is_reversed = main_dir_rev == AxisReverse :: Reversed ;
1070
1102
for ( index, flex_child) in line. items . iter_mut ( ) . enumerate ( ) {
1071
1103
let is_first = index == 0 ;
1072
- let gap = style
1073
- . row_gap ( )
1074
- . resolve ( requested_inner_size. main_size ( dir) , node)
1075
- . or_zero ( ) ;
1104
+ let gap = main_axis_gap :: < T > ( dir, style, node, & requested_inner_size) ;
1076
1105
flex_child. extra_offset_main = if is_first {
1077
1106
match style. justify_content ( ) {
1078
1107
JustifyContent :: Start
@@ -1214,10 +1243,7 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
1214
1243
// 16. Align all flex lines per align-content.
1215
1244
1216
1245
let num_lines = flex_lines. len ( ) as i32 ;
1217
- let gap = style
1218
- . column_gap ( )
1219
- . resolve ( requested_inner_size. main_size ( dir) , node)
1220
- . or_zero ( ) ;
1246
+ let gap = cross_axis_gap :: < T > ( dir, style, node, & requested_inner_size) ;
1221
1247
let total_cross_axis_gap = sum_axis_gaps ( gap, flex_lines. len ( ) ) ;
1222
1248
let free_space = ( inner_container_size. cross_size ( dir) - total_cross_size)
1223
1249
. max ( T :: Length :: zero ( ) )
0 commit comments