You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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.
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.
What problem does this solve or what need does it fill?
Dimension::Percent(x)
reads asx%
, and mathematically speakingx%
is the same asx/100
. This heavily implies that the value insideDimension::Percent
goes from0.0
to100.0
while it actually goes from0.0
to1.0
.What solution would you like?
Ideally,
Dimension::Percent
would be renamed toDimension::Fraction
(or maybeProportion
, ifFraction
is too close to thefr
kind). This name implies that the value has a range from0.0
to1.0
. The same applies toLengthPercentage::Percent
andLengthPercentageAuto::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
orstyle_helpers::proportion
should also be added.What alternative(s) have you considered?
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
The text was updated successfully, but these errors were encountered: