Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(widgets): 🐛 Flex not give a right gap for the second child #622

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.,}
);
}
Loading