Skip to content

Commit 89a6f85

Browse files
committed
refactor: better impl for axis info
1 parent bd74717 commit 89a6f85

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,14 +1302,8 @@ impl<T: LayoutTreeNode> FlexBox<T> for LayoutUnit<T> {
13021302
.or_zero()
13031303
}
13041304
};
1305-
let baseline_diff = child.gen_origin(
1306-
dir,
1307-
main_dir_rev,
1308-
cross_dir_rev,
1309-
*container_size,
1310-
offset_main,
1311-
offset_cross,
1312-
);
1305+
let baseline_diff =
1306+
child.gen_origin(axis_info, *container_size, offset_main, offset_cross);
13131307
if self_first_baseline_ascent.is_none() {
13141308
self_first_baseline_ascent =
13151309
Some(flex_child.first_baseline_ascent + baseline_diff);

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,10 @@ impl<T: LayoutTreeNode> Flow<T> for LayoutUnit<T> {
492492
.or_zero()
493493
};
494494
let baseline_diff = child.gen_origin(
495-
axis_info.dir,
496-
axis_info.main_dir_rev,
497-
AxisReverse::NotReversed,
495+
AxisInfo {
496+
cross_dir_rev: AxisReverse::NotReversed,
497+
..axis_info
498+
},
498499
node_inner_size.or_zero(),
499500
main_offset,
500501
cross_offset,
@@ -617,9 +618,10 @@ impl<T: LayoutTreeNode> Flow<T> for LayoutUnit<T> {
617618
child.result = Rect::new(Point::zero(), child_res.size);
618619
child.cache.touch(child_node);
619620
child.gen_origin(
620-
axis_info.dir,
621-
axis_info.main_dir_rev,
622-
AxisReverse::NotReversed,
621+
AxisInfo {
622+
cross_dir_rev: AxisReverse::NotReversed,
623+
..axis_info
624+
},
623625
node_inner_size.or_zero(),
624626
main_offset + child_origin.main_axis(axis_info.dir),
625627
cross_offset + child_origin.cross_axis(axis_info.dir),

float-pigment-layout/src/special_positioned.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,7 @@ pub(crate) fn compute_special_position<T: LayoutTreeNode>(
454454
offset_cross
455455
};
456456

457-
layout_unit.gen_origin(
458-
axis_info.dir,
459-
axis_info.main_dir_rev,
460-
axis_info.cross_dir_rev,
461-
**parent.inner_size,
462-
offset_main,
463-
offset_cross,
464-
);
457+
layout_unit.gen_origin(axis_info, **parent.inner_size, offset_main, offset_cross);
465458
}
466459

467460
pub(crate) fn compute_position_relative<T: LayoutTreeNode>(

float-pigment-layout/src/unit.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,16 +646,14 @@ impl<T: LayoutTreeNode> LayoutUnit<T> {
646646
#[inline]
647647
pub(crate) fn gen_origin(
648648
&mut self,
649-
dir: AxisDirection,
650-
main_dir_rev: AxisReverse,
651-
cross_dir_rev: AxisReverse,
649+
axis_info: AxisInfo,
652650
parent_size: Size<T::Length>,
653651
offset_main: T::Length,
654652
offset_cross: T::Length,
655653
) -> Vector<T::Length> {
656-
let (width, height, width_rev, height_rev) = match dir {
657-
AxisDirection::Horizontal => (offset_main, offset_cross, main_dir_rev, cross_dir_rev),
658-
AxisDirection::Vertical => (offset_cross, offset_main, cross_dir_rev, main_dir_rev),
654+
let (width, height, width_rev, height_rev) = match axis_info.dir {
655+
AxisDirection::Horizontal => (offset_main, offset_cross, axis_info.main_dir_rev, axis_info.cross_dir_rev),
656+
AxisDirection::Vertical => (offset_cross, offset_main, axis_info.cross_dir_rev, axis_info.main_dir_rev),
659657
};
660658
let width = match width_rev {
661659
AxisReverse::NotReversed => width,

0 commit comments

Comments
 (0)