Skip to content

Commit 2746dd4

Browse files
committed
fix(layout): flex gap direction
1 parent 70ad858 commit 2746dd4

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed

float-pigment-layout/src/algo/flex_box.rs

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,6 @@ fn sum_axis_gaps<L: LengthNum>(gap: L, num_items: usize) -> L {
1414
}
1515
}
1616

17-
#[inline(always)]
18-
fn main_gap<T: LayoutTreeNode>(
19-
style: &T::Style,
20-
dir: AxisDirection,
21-
) -> DefLength<T::Length, T::LengthCustom> {
22-
match dir {
23-
AxisDirection::Horizontal => style.row_gap(),
24-
AxisDirection::Vertical => style.column_gap(),
25-
}
26-
}
27-
28-
#[inline(always)]
29-
fn cross_gap<T: LayoutTreeNode>(
30-
style: &T::Style,
31-
dir: AxisDirection,
32-
) -> DefLength<T::Length, T::LengthCustom> {
33-
match dir {
34-
AxisDirection::Horizontal => style.column_gap(),
35-
AxisDirection::Vertical => style.row_gap(),
36-
}
37-
}
38-
3917
pub(crate) fn align_self<T: LayoutTreeNode>(child: &T::Style, parent: &T::Style) -> AlignSelf {
4018
let s = child.align_self();
4119
if s == AlignSelf::Auto {
@@ -369,7 +347,8 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
369347
});
370348
} else {
371349
let mut flex_items = &mut flex_items[..];
372-
let main_axis_gap = main_gap::<T>(style, dir)
350+
let main_axis_gap = style
351+
.row_gap()
373352
.resolve(requested_inner_size.main_size(dir), node)
374353
.or_zero();
375354
while !flex_items.is_empty() {
@@ -413,7 +392,8 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
413392
let multi_flex_line = flex_lines.len() > 1;
414393
for line in &mut flex_lines {
415394
let total_main_axis_gap = sum_axis_gaps(
416-
main_gap::<T>(style, dir)
395+
style
396+
.row_gap()
417397
.resolve(requested_inner_size.main_size(dir), node)
418398
.or_zero(),
419399
line.items.len(),
@@ -903,7 +883,8 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
903883
let min_inner_cross =
904884
self_min_max_limit.cross_size(requested_cross_size, dir) - padding_border_cross;
905885
let total_cross_axis_gap = sum_axis_gaps(
906-
cross_gap::<T>(style, dir)
886+
style
887+
.column_gap()
907888
.resolve(requested_inner_size.main_size(dir), node)
908889
.or_zero(),
909890
flex_lines.len(),
@@ -1037,7 +1018,8 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
10371018

10381019
for line in &mut flex_lines {
10391020
let total_main_axis_gap = sum_axis_gaps(
1040-
main_gap::<T>(style, dir)
1021+
style
1022+
.row_gap()
10411023
.resolve(requested_inner_size.main_size(dir), node)
10421024
.or_zero(),
10431025
line.items.len(),
@@ -1087,7 +1069,8 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
10871069
let is_reversed = main_dir_rev == AxisReverse::Reversed;
10881070
for (index, flex_child) in line.items.iter_mut().enumerate() {
10891071
let is_first = index == 0;
1090-
let gap = main_gap::<T>(style, dir)
1072+
let gap = style
1073+
.row_gap()
10911074
.resolve(requested_inner_size.main_size(dir), node)
10921075
.or_zero();
10931076
flex_child.extra_offset_main = if is_first {
@@ -1231,7 +1214,8 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
12311214
// 16. Align all flex lines per align-content.
12321215

12331216
let num_lines = flex_lines.len() as i32;
1234-
let gap = cross_gap::<T>(style, dir)
1217+
let gap = style
1218+
.column_gap()
12351219
.resolve(requested_inner_size.main_size(dir), node)
12361220
.or_zero();
12371221
let total_cross_axis_gap = sum_axis_gaps(gap, flex_lines.len());

0 commit comments

Comments
 (0)