Add float support #51
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Argument for Enabling Floats in the UI Framework:
The decision to not render
Floatvalues directly in thehacksaw.uiframework is understandable given concerns about localization and formatting. However, in practical applications, especially those involving dynamic or interactive elements like sliders and audio controls, the ability to render and manipulateFloatvalues directly can greatly enhance the developer experience and the functionality of the UI. Below is an example of aPanVolumeViewcomponent that illustrates this point:Explanation:
Enhanced Real-Time User Interactions:
RangeInputcomponent in the example allows users to adjustpanandvolumewith fine granularity usingFloatvalues.0.001ensures a smooth and precise user experience. Without directFloatsupport, achieving this level of granularity would be cumbersome and might necessitate additional conversion logic, potentially leading to performance overhead or added complexity.Maintaining Format Control:
formatVolumeandformatPanconvert the float values into user-friendly strings for display.Reducing Boilerplate Code:
Floatvalues would reduce the need for repetitive conversion code across components. Developers could bindFloatvalues directly to UI elements, simplifying the codebase and minimizing the likelihood of errors in manual conversion logic.Supporting Advanced Use Cases:
Floatvalues would significantly enhance the framework's flexibility and power.Floatvalues directly allows them to see exact values, avoiding oversimplification or misinterpretation from forced string conversion.Internationalization Applies to Integers Too:
Using
IntInstead ofFloatAdds Extra Code and Complexity:Intvalues and scale them to represent floats (e.g., multiplying by 1000 to avoid usingFloatdirectly), this approach adds unnecessary complexity to the codebase. Developers must write additional logic to scale, convert, and then correctly format these values, which increases the likelihood of errors.0.001using an integer, you would need to store it as1and manually convert it back to0.001when needed. This not only complicates the code but also makes it harder to maintain and understand.Avoiding Unnecessary Developer Work:
Avoiding Redundancy in Simple Applications:
FloattoStringcan feel redundant and unnecessary.Minimizing Errors in Manual Conversion: