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

Enable correct image measure functions #661

Merged
merged 4 commits into from
May 30, 2024

Conversation

nicoburns
Copy link
Collaborator

Objective

Allow image measure functions to correctly apply their inherent aspect ratio to style sizes.

Context

Changes made

  • Use SizingMode::Inherent when sizing absolute children of flexbox nodes. This basically turns on application of styles which is what we want.
  • Pass style: &Style into measure functions. This allows measure functions to access a node's styles which is necessary if they are to apply their aspect ratio to those styles.
  • Make MaybeMath, MaybeResolve and ResolveOrZero traits public. These were previously private to keep Taffy's API surface area smaller, but they're very useful when implementing the image measure function as above.

Notes

  • We may want more built-in support for replaced elements at some point (e.g. a Display::Replaced mode that knows about aspect ratios). This is the quick fix targeting the upcoming Bevy 0.14 release.
  • Somehow this wasn't an issue with Taffy 0.3. I think fixes for other issues have exposed this issue (IIRC we were previously passing the style size as a known_size but this breaks some other use cases that I can't remember right now)

@nicoburns nicoburns added bug Something isn't working breaking-change A change that breaks our public interface labels May 28, 2024
@nicoburns nicoburns added this to the 0.5 milestone May 28, 2024
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.

It's been a while since I looked at complex rust code & spent time looking at taffy so I'm a bit rusty, pun intended.

The code looks good, clean and structured 👍
The high level changes makes sense to me, as well as making the Maybe / Resolve traits public.

I think the only thing missing may be an example showcasing how or when you would use this in practice, but that may also be part of a future PR.

Copy link
Collaborator

@TimJentzsch TimJentzsch left a comment

Choose a reason for hiding this comment

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

Surprisingly many changes necessary, but it does make sense (and I suppose a lot of it is just docs reformatting).

Just to make sure I understand correctly: The measure function is only used (or rather, defined) by the clients like bevy, right?

src/tree/taffy_tree.rs Show resolved Hide resolved
@alice-i-cecile
Copy link
Collaborator

I'm happy with the overall fix here. I'll let you handle the release process by default, but let me know if you'd like a hand at any point :)

@nicoburns nicoburns merged commit 09c7a71 into DioxusLabs:main May 30, 2024
19 checks passed
github-merge-queue bot pushed a commit to bevyengine/bevy that referenced this pull request May 30, 2024
…zes (#13555)

# Objective

- Fixes #13155
- fixes #13517
- Supercedes #13381
- Requires DioxusLabs/taffy#661

## Solution

- Taffy has been updated to:
    - Apply size styles to absolutely positioned children
    - Pass the node's `Style` through to the measure function
- Bevy's image measure function has been updated to make use of this
style information

## Notes

- This is currently using a git version of Taffy. If this is tested as
fixing the issue then we can turn that into a Taffy 0.5 release (this
would be the only change between Taffy 0.4 and Taffy 0.5 so upgrading is
not expected to be an issue)
- This implementation may not be completely correct. I would have
preferred to extend Taffy's gentest infrastructure to handle images and
used that to nail down the correct behaviour. But I don't have time for
that atm so we'll have to iterate on this in future. This PR at least
puts that under Bevy's control.

## Testing

- I manually tested the game_menu_example (from
#13155)
- More testing is probably merited

---

## Changelog

No changelog should be required as it fixes a regression on `main` that
was not present in bevy 0.13. The changelog for "Taffy upgrade" may want
to be changed from 0.4 to 0.5 if this change gets merged.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: François Mockers <francois.mockers@vleue.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change A change that breaks our public interface bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants