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

Fixes for aspect ratio and min/max sizes #317

Merged
merged 40 commits into from
Jan 12, 2023

Conversation

nicoburns
Copy link
Collaborator

@nicoburns nicoburns commented Jan 4, 2023

Objective

Fix #313 (and more generally fix support for aspect-ratio).
This PR now also fixes #167

Subtasks

  • Aspect ratio support for leaf nodes
  • Aspect ratio support for grid containers
  • Aspect ratio support for grid items
  • Aspect ratio support for flex containers
  • Aspect ratio support for regular flex items
  • Aspect ratio support for absolutely positioned flex items
  • Min/max size support for grid items
  • Fix margins for absolutely positioned flex items
  • Fix min/max interactions with aspect ratio for absolutely positioned flex items
  • Fix min/max interaction with inset-generated dimensions for absolutely positioned flex items

Context

Taffy has an aspect_ratio style property and claims to support CSS aspect-ratio. But actual support is patchy, and it is not covered by gentests.

@nicoburns nicoburns force-pushed the fix-aspect-ratio branch 3 times, most recently from 015934e to b28deaa Compare January 4, 2023 19:38
@nicoburns nicoburns marked this pull request as ready for review January 4, 2023 21:11
@nicoburns nicoburns changed the title WIP: Fix and test support for aspect ratio Fix and test support for aspect ratio Jan 4, 2023
@nicoburns
Copy link
Collaborator Author

I'm not sure if this covers everything (in fact I have 4 disabled tests), but aspect ratio is working a lot better with this PR than it was before (including the use case in #313), and I'm intending to move on to other tasks now and return to aspect ratio again later if required.

@nicoburns nicoburns mentioned this pull request Jan 4, 2023
87 tasks
@adjabaev
Copy link
Contributor

adjabaev commented Jan 4, 2023

@nicoburns hey!
thank for the quick answer/ implementation!
I just started playing with it and noticed this test isn't passing:
(the inset doesn't seem to change anything, it is just a representation of a real use case)

// aspect_ratio_leaf_inset_width
<div id="test-root" style="display: flex; width: 1280px; height: 720px;">
  <div style="position: absolute; top: 5%; left: 5%; width: 20%; aspect-ratio: 3;"></div>
</div>

@nicoburns
Copy link
Collaborator Author

@adjabaev Well spotted! I've fixed that case, but I think I'll need to test more cases using absolute positioning.

@nicoburns nicoburns force-pushed the fix-aspect-ratio branch 2 times, most recently from 7ff739f to fd02d7f Compare January 5, 2023 01:16
@nicoburns nicoburns marked this pull request as draft January 5, 2023 01:16
@adjabaev
Copy link
Contributor

adjabaev commented Jan 5, 2023

86509aa

It might be a mistake but both tests you commited (fixtures) have identical content

On a side note, I'll keep trying getting crazy with aspect ratio and keep you updated if I end up finding something behaving weirdly

@nicoburns
Copy link
Collaborator Author

It might be a mistake but both tests you commited (fixtures) have identical content

Ah yes, that'll be because the "rename" and "duplicate" buttons are right next to each other in my editor. I wanted to rename it "absolute" because it turns out that percentages have nothing to do with it.

@nicoburns nicoburns added the bug Something isn't working label Jan 5, 2023
Copy link
Collaborator

@Weibye Weibye left a comment

Choose a reason for hiding this comment

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

Some nitpicks and questions :)

src/geometry.rs Outdated Show resolved Hide resolved
src/geometry.rs Show resolved Hide resolved
scripts/gentest/test_helper.js Outdated Show resolved Hide resolved
src/compute/leaf.rs Show resolved Hide resolved
src/compute/flexbox.rs Outdated Show resolved Hide resolved
@nicoburns nicoburns marked this pull request as ready for review January 11, 2023 00:16
@nicoburns nicoburns changed the title Fix and test support for aspect ratio Fixes for aspect ratio and min/max sizes Jan 11, 2023
@nicoburns nicoburns changed the title Fixes for aspect ratio and min/max sizes Fixes for aspect ratio, min/max sizes and margins of absolutely positioned flex items Jan 11, 2023
@nicoburns
Copy link
Collaborator Author

@alice-i-cecile This is now ready for another round of review / merging when ready.

@Weibye Weibye self-requested a review January 11, 2023 13:11
@nicoburns nicoburns changed the title Fixes for aspect ratio, min/max sizes and margins of absolutely positioned flex items Fixes for aspect ratio and min/max sizes Jan 11, 2023
@nicoburns nicoburns mentioned this pull request Jan 12, 2023
3 tasks
Copy link
Collaborator

@Weibye Weibye left a comment

Choose a reason for hiding this comment

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

Looks good, I haven't been able to spot any issues but as usual I'm relying on your expertise and the tests to vouch for the correctness of the implementation.

Comment on lines +1738 to +1758
match (align_self, constants.is_wrap_reverse) {
// Stretch alignment does not apply to absolutely positioned items
// See "Example 3" at https://www.w3.org/TR/css-flexbox-1/#abspos-items
// Note: Stretch should be FlexStart not Start when we support both
(AlignSelf::Baseline | AlignSelf::Stretch | AlignSelf::Start, false) | (AlignSelf::End, true) => {
constants.padding_border.cross_start(constants.dir) + resolved_margin.cross_start(constants.dir)
}
AlignSelf::End => {
if constants.is_wrap_reverse {
constants.padding_border.cross_start(constants.dir)
} else {
free_cross_space - constants.padding_border.cross_end(constants.dir)
}
(AlignSelf::Baseline | AlignSelf::Stretch | AlignSelf::Start, true) | (AlignSelf::End, false) => {
constants.container_size.cross(constants.dir)
- constants.padding_border.cross_end(constants.dir)
- final_size.cross(constants.dir)
- resolved_margin.cross_end(constants.dir)
}
AlignSelf::Center => free_cross_space / 2.0,
AlignSelf::Baseline => free_cross_space / 2.0, // Treat as center for now until we have baseline support
AlignSelf::Stretch => {
if constants.is_wrap_reverse {
free_cross_space - constants.padding_border.cross_end(constants.dir)
} else {
constants.padding_border.cross_start(constants.dir)
}
(AlignSelf::Center, _) => {
(constants.container_size.cross(constants.dir)
+ constants.padding_border.cross_start(constants.dir)
- constants.padding_border.cross_end(constants.dir)
- final_size.cross(constants.dir)
+ resolved_margin.cross_start(constants.dir)
- resolved_margin.cross_end(constants.dir))
/ 2.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

I particularly like this way of structuring this code!

@@ -42,6 +43,19 @@ impl<T: Default> Default for Rect<T> {
}
}

impl<U, T: Add<U>> Add<Rect<U>> for Rect<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This deserves a note in the release notes; it's surprisingly useful.

@alice-i-cecile alice-i-cecile merged commit 610c92f into DioxusLabs:main Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants