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

Support Calc val #225

Open
Tracked by #345
zyxkad opened this issue Sep 6, 2022 · 2 comments
Open
Tracked by #345

Support Calc val #225

zyxkad opened this issue Sep 6, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@zyxkad
Copy link

zyxkad commented Sep 6, 2022

What problem does this solve or what need does it fill?

In css, we have calc() expression that can auto calculate and update when value is changed (e.g. window resized)

What solution would you like?

See bevyengine/bevy#5893

What alternative(s) have you considered?

Other solutions to solve and/or work around the problem presented.

Additional context

Any other information you would like to add such as related previous work,
screenshots, benchmarks, etc.

@TimJentzsch
Copy link
Collaborator

TimJentzsch commented Apr 9, 2023

Some important insights and considerations from the prior implementation attempt:

  • I think the size of the Calc variant of Dimension should be at most 64 bits (/usize sized). Concerns have already Allow Taffy to be used with f64 values where we currently f32 #332 (comment) about even this size, but IMO calc is important enough a feature that it trumps concerns about memory usage. This implies that the entire Calc expression should be boxed in some way.
  • Dimension remaining Copy probably isn't super important, but Dimension remaining cheap to clone is. That implies the Calc variant being an Arc, Rc, or a slotmap key rather than a Box. Possibly we could use an opaque newtype around one of the above to allow to change the underlying implementation in future.
  • The order of operations is important. And the implementation should make sure to respect the standard order of operations for maths operators.
  • As well as basic mathematical operators, CSS also supports functions like min, max, clamp and round. We don't need to support these right away, but it would be a good if a design supported expanding to support them in future.

#232 (comment)

@nicoburns
Copy link
Collaborator

Some further thoughts on this:

  • I'm now less concerned about memory usage, as I think there are various schemes that can deduplicate styles which almost entirely alleviate this. However, I think dimension values fitting into a single 64bit register is likely to be important for performance.
  • I therefore think we will definitely want to change Dimension (and LengthPercentage / LengthPercentageAuto / MinTrackSizingFunction / MaxTrackSizingFunction) to a manually tagged representation.
  • If we force the Calc value to be aligned to 128 bits with a repr attribute`, then that gives us 4 bits to play with as a tag (as the last 4 bits of the pointer will always be 0) which ought to be enough to represent all of the variants we have or anticipate adding in future.

I may attempt an implementation of this soon (possibly just the new value representation first, then we can implement calc on top of that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

3 participants