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

flexbox 2020: Implement `align-items` and `align-self`, excluding `baseline` #27339

Merged
merged 7 commits into from Jul 21, 2020

flex 2020: Handle positioning flex item based on align-self

  • Loading branch information
Manishearth committed Jul 21, 2020
commit ba9448e68210feb7f64f3f6aa43ec62fe503a205
@@ -715,7 +715,10 @@ impl FlexLine<'_> {
.items
.iter()
.zip(&item_margins)
.map(|(item, margin)| item.align_along_cross_axis(margin));
.zip(&item_used_cross_sizes)
.map(|((item, margin), size)| {
item.align_along_cross_axis(margin, size, line_cross_size)
});

let item_fragments = self
.items
@@ -1149,14 +1152,29 @@ impl FlexItem<'_> {
}

/// Return the coordinate of the cross-start side of the content area
fn align_along_cross_axis(&self, margin: &FlexRelativeSides<Length>) -> Length {
fn align_along_cross_axis(
&self,
margin: &FlexRelativeSides<Length>,
content_size: &Length,
line_cross_size: Length,
) -> Length {
let outer_cross_start =
if self.margin.cross_start.is_auto() || self.margin.cross_end.is_auto() {
Length::zero()
} else {
// FIXME: “Align all flex items along the cross-axis per `align-self`”
// For now we hard-code the behavior of `stretch`:
Length::zero()
match self.align_self {
AlignItems::Stretch | AlignItems::FlexStart => Length::zero(),
AlignItems::FlexEnd => {
let margin_box_cross = *content_size + self.pbm_auto_is_zero.cross;
line_cross_size - margin_box_cross
},
AlignItems::Center => {
let margin_box_cross = *content_size + self.pbm_auto_is_zero.cross;
(line_cross_size - margin_box_cross) / 2.
},
// FIXME: handle baseline alignment
AlignItems::Baseline => Length::zero(),
}
};
outer_cross_start + margin.cross_start + self.border.cross_start + self.padding.cross_start
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.