Percentages in math ops for number fields
The current feature of doing math operations, like adding number values in the number fields is super helpful. If possible, please enable adding percentages as well. For example, current value is 123. Allow the use of 123+10%, which would add 10 percent of the current value to the current value.
Hey @ellthompson - should I transfer this issue to the PCUI repo, or do you think this request should remain Editor-specific?
This should be moved to PCUI as it's a feature request for the NumericInput component. We'll need to update the logic here: https://github.com/playcanvas/pcui/blob/ad64183f99aeb75bf99316c30774f21403027891/src/components/NumericInput/index.ts#L199
So my attempt to implement this was rejected and reverted. Can we be clear about the exact functionality of what's desired here, please?
Is it purely:
- NumericInput has
200set. - User edits the field to
200 + 10% - User presses Enter
- NumerInput evaluates to
220
Questions:
- Supported operators would be
+,-but should* and/` be allowed? - Should expressions work with this?
@Maksims, @LeXXik - please comment.
The addition/subtraction looks correct, yes.
Basically: a + c% = a + (a * c)
Where c is floating representation of a percentage (10% = 0.1; 150% = 1.5; etc).
With multiplication/division, it is even more direct: 200 * 10% = 20, so a * c% = a * c.
Good, good. I think personally, I would go with a bare minimum in this PR. That is I'd just add plus and minus operands, as you described them. Its actually, the operation I wanted originally in this issue. I don't really see a value in mul/div, but perhaps someone is used to use those in some other apps. I'd leave those until a feature request is made, though.