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: single-line flex-container should clamp the line's cross-size #638

Merged
merged 4 commits into from
Apr 9, 2024

Conversation

TtTRz
Copy link
Contributor

@TtTRz TtTRz commented Apr 8, 2024

Objective

In Taffy, missing a step when calculate the cross size of each flex line. https://www.w3.org/TR/css-flexbox-1/#algo-cross-line

//  If the flex container is single-line, then clamp the line’s cross-size to be within the container’s computed min and max cross sizes.

This PR tries to complement this step.

Copy link
Collaborator

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've requested a couple of changes, but this generally looks very good: thanks for the PR!

We may also wish to generally review the interaction of:

  • The logic added in this PR
  • The "if" statement at the top of calculate_cross_size
  • The presence of min/max sizes (with no preferred size)
  • The presence of wrap vs. nowrap
    But that does not need to happen in this PR.

@@ -1396,6 +1396,16 @@ fn calculate_cross_size(flex_lines: &mut [FlexLine], node_size: Size<Option<f32>
})
.fold(0.0, |acc, x| acc.max(x));
}
// If the flex container is single-line, then clamp the line’s cross-size to be within the container’s computed min and max cross sizes.
if flex_lines.len() == 1 {
Copy link
Collaborator

@nicoburns nicoburns Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (confusingly) should be controlled by flex-wrap being nowrap (such that the container is inherently always single line) rather than just when it happens to contain a single line.

See https://www.w3.org/TR/css-flexbox-1/#flex-wrap-property:

The flex-wrap property controls whether the flex container is single-line or multi-line

We'll also need tests to check "nowrap" vs. "happens to be single-line"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that flex_lines.len() == 1 is used in https://github.com/DioxusLabs/taffy/blob/main/src/compute/flexbox.rs#L1352 to determine if it is a single line.
I've also looked at some other browser layout engine implementations, I see no difference between "nowrap" and "happends to be single-line", but i'll add some tests to check it.

Copy link
Collaborator

@nicoburns nicoburns Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also looked at some other browser layout engine implementations, I see no difference between "nowrap" and "happends to be single-line", but i'll add some tests to check it.

If you add flex-wrap: wrap (the default is nowrap) to the test you created for this PR then you'll find that the layout ends up changing. I rather suspect that line 1532 is wrong too (although that if does also include the flex_wrap property later in the condition).

but i'll add some tests to check it.

Thanks!

Copy link
Contributor Author

@TtTRz TtTRz Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the difference just like you said, we should use flex_wrap to determine if it is single-line or not.

I've added some test cases and it looks fine :)

  • padding/border
  • min/max size
  • wrap/no-wrap

src/compute/flexbox.rs Show resolved Hide resolved
Copy link
Collaborator

@nicoburns nicoburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me now. Thanks for the fixes (and the tests)!

@nicoburns nicoburns merged commit aad4f02 into DioxusLabs:main Apr 9, 2024
19 checks passed
@TtTRz
Copy link
Contributor Author

TtTRz commented Apr 9, 2024

This looks good to me now. Thanks for the fixes (and the tests)!

Thanks for the review XD!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants