Skip to content

Commit

Permalink
fix(widgets): 🐛 Flex not give a right gap for the second child
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Adoo authored and rchangelog[bot] committed Sep 3, 2024
1 parent c020469 commit d8196fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he

## [@Unreleased] - @ReleaseDate

### Fixed

- **widgets**: Flex may not decrease the gap for the second child during layout. (#622 @M-Adoo)

## [0.4.0-alpha.6] - 2024-08-21

### Features
Expand Down
31 changes: 23 additions & 8 deletions widgets/src/layout/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl FlexLayouter {
} else {
FlexSize::zero()
};
let mut gap = 0.;

while let Some(mut l) = layouter {
let mut max = max;
if !wrap {
Expand All @@ -201,6 +201,13 @@ impl FlexLayouter {
.query::<Expanded>()
.map(|expanded| expanded.flex);

layouter = l.into_next_sibling();
let gap = if layouter.is_some() && !FlexLayouter::is_space_layout(self.justify_content) {
self.main_axis_gap
} else {
0.
};

// flex-item need use empty space to resize after all fixed widget performed
// layout.
let line = &mut self.current_line;
Expand All @@ -226,13 +233,6 @@ impl FlexLayouter {
.current_line
.items_info
.push(FlexLayoutInfo { size, flex, pos: <_>::default() });

layouter = l.into_next_sibling();
if layouter.is_some() && !FlexLayouter::is_space_layout(self.justify_content) {
gap = self.main_axis_gap;
} else {
gap = 0.;
}
}
self.place_line();
}
Expand Down Expand Up @@ -654,4 +654,19 @@ mod tests {
{ path = [0, 0, 0], rect == ribir_geom::rect(0., 0., 100., 25.),}
{ path = [0, 0, 2], rect == ribir_geom::rect(200., 0., 300., 25.),}
);

widget_layout_test!(
fix_flex_gap,
fn_widget! {
@Column {
item_gap: 50.,
@SizedBox { size: Size::new(100., 100.) }
@SizedBox { size: Size::new(100., 500.) }
}
},
wnd_size = Size::new(500., 500.),
{ path =[0], height == 500.,}
{ path =[0, 0], y == 0., height == 100.,}
{ path =[0, 1], y == 150., height == 350.,}
);
}

0 comments on commit d8196fa

Please sign in to comment.