这是indexloc提供的服务,不要输入任何密码
Skip to content

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.

@alice-i-cecile alice-i-cecile requested a review from nicoburns April 8, 2024 12:31
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.

.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

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
@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