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 "percent" naming confusion #625

Open
Garmelon opened this issue Mar 6, 2024 · 0 comments
Open

Fix "percent" naming confusion #625

Garmelon opened this issue Mar 6, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Garmelon
Copy link

Garmelon commented Mar 6, 2024

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

Dimension::Percent(x) reads as x%, and mathematically speaking x% is the same as x/100. This heavily implies that the value inside Dimension::Percent goes from 0.0 to 100.0 while it actually goes from 0.0 to 1.0.

What solution would you like?

Ideally, Dimension::Percent would be renamed to Dimension::Fraction (or maybe Proportion, if Fraction is too close to the fr kind). This name implies that the value has a range from 0.0 to 1.0. The same applies to LengthPercentage::Percent and LengthPercentageAuto::Percent.

The range should also be mentioned in the documentation of each item.

After the renaming, style_helpers::percentage should either divide its argument by 100 (as would make mathematical sense) or be removed.

A style_helpers::fraction or style_helpers::proportion should also be added.

What alternative(s) have you considered?

  1. All values called "percentage" should go from 1 to 100. This is more likely to silently break code for users updating to 0.5 but it matches common CSS usage.
  2. If nothing else, the range should be documented wherever the term "percentage" appears with a big WARNING that it deviates from the obvious meaning.

I like both the renaming solution and the solution of making percentages go from 1 to 100 from an API user's point of view, without clear preference.

Additional context

#323

https://github.com/DioxusLabs/taffy/blob/main/RELEASES.md#new-feature-style-helpers shows an example with Dimension::Percent(50.0), showing how easy it is to misunderstand the range (unless it has changed since 0.3.0?)

Bevy UI also has to convert its percentages (which go from 0 to 100 as expected) to taffy's range of 0 to 1: https://github.com/bevyengine/bevy/blob/6533170e9447df61f84010fa233aa0f30e5bf298/crates/bevy_ui/src/layout/convert.rs#L19

@Garmelon Garmelon added the enhancement New feature or request label Mar 6, 2024
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
None yet
Development

No branches or pull requests

1 participant