@@ -14,6 +14,50 @@ fn sum_axis_gaps<L: LengthNum>(gap: L, num_items: usize) -> L {
1414 }
1515}
1616
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+
1761pub ( crate ) fn align_self < T : LayoutTreeNode > ( child : & T :: Style , parent : & T :: Style ) -> AlignSelf {
1862 let s = child. align_self ( ) ;
1963 if s == AlignSelf :: Auto {
@@ -347,10 +391,7 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
347391 } ) ;
348392 } else {
349393 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) ;
354395 while !flex_items. is_empty ( ) {
355396 let mut line_length = T :: Length :: zero ( ) ;
356397 let index = flex_items
@@ -392,10 +433,7 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
392433 let multi_flex_line = flex_lines. len ( ) > 1 ;
393434 for line in & mut flex_lines {
394435 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) ,
399437 line. items . len ( ) ,
400438 ) ;
401439 // 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> {
883921 let min_inner_cross =
884922 self_min_max_limit. cross_size ( requested_cross_size, dir) - padding_border_cross;
885923 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) ,
890925 flex_lines. len ( ) ,
891926 ) ;
892927 let line_total_cross: T :: Length =
@@ -1018,10 +1053,7 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
10181053
10191054 for line in & mut flex_lines {
10201055 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) ,
10251057 line. items . len ( ) ,
10261058 ) ;
10271059 let used_space: T :: Length = total_main_axis_gap
@@ -1069,10 +1101,7 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
10691101 let is_reversed = main_dir_rev == AxisReverse :: Reversed ;
10701102 for ( index, flex_child) in line. items . iter_mut ( ) . enumerate ( ) {
10711103 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) ;
10761105 flex_child. extra_offset_main = if is_first {
10771106 match style. justify_content ( ) {
10781107 JustifyContent :: Start
@@ -1214,10 +1243,7 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
12141243 // 16. Align all flex lines per align-content.
12151244
12161245 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) ;
12211247 let total_cross_axis_gap = sum_axis_gaps ( gap, flex_lines. len ( ) ) ;
12221248 let free_space = ( inner_container_size. cross_size ( dir) - total_cross_size)
12231249 . max ( T :: Length :: zero ( ) )
0 commit comments