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

Add IntToFloat (and FloatToInt) in bindings #4666

Closed
2 tasks done
chran554 opened this issue Feb 22, 2024 · 2 comments
Closed
2 tasks done

Add IntToFloat (and FloatToInt) in bindings #4666

chran554 opened this issue Feb 22, 2024 · 2 comments
Labels
Data binding Issue related to bug or improvement of data binding

Comments

@chran554
Copy link

chran554 commented Feb 22, 2024

Checklist

  • I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
  • This issue only relates to a single feature. I will open new issues for any other features.

Is your feature request related to a problem?

When sing the Slider with bind data your are bound to use (no pun intended) binding.Float.
I have tried to use the slider bound to an int value and there were some unnecessary (?) work around to make it work.

Is it possible to construct a solution with the existing API?

A binding.IntToFloat can be created like below:

binding.StringToFloatWithFormat(binding.IntToStringWithFormat(myBoundInt, "%d.000000"), "%f")
boundTeaPotCount := binding.NewInt()

slider := widget.NewSliderWithData(0, 130, binding.StringToFloatWithFormat(binding.IntToStringWithFormat(boundTeaPotCount, "%d.000000"), "%f"))
label := widget.NewLabelWithData(binding.IntToString(boundTeaPotCount))

Describe the solution you'd like to see.

I am missing a (in convert.go, binding package):

func IntToFloat(v Int) Float 

and maybe

func FloatToInt(v Float) Int 

for completeness, but I am aware of the problem with design regarding rounding vs truncating of decimals.

boundTeaPotCount := binding.NewInt()

slider := widget.NewSliderWithData(0, 130, binding.IntToFloat(boundTeaPotCount))
label := widget.NewLabelWithData(binding.IntToString(boundTeaPotCount))
@chran554 chran554 changed the title Add IntToFloat and (FloatToInt) in bindings Add IntToFloat (and FloatToInt) in bindings Feb 22, 2024
@andydotxyz
Copy link
Member

Sounds like a good idea, thanks.

@andydotxyz andydotxyz added the Data binding Issue related to bug or improvement of data binding label Feb 26, 2024
@andydotxyz
Copy link
Member

Thanks to @Dorbmon this is now done on develop and will be in v2.5.0 in the coming month

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Data binding Issue related to bug or improvement of data binding
Projects
None yet
Development

No branches or pull requests

2 participants