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

Float slider fails if initial value is integer #77

Closed
backspaces opened this issue Aug 2, 2015 · 3 comments
Closed

Float slider fails if initial value is integer #77

backspaces opened this issue Aug 2, 2015 · 3 comments

Comments

@backspaces
Copy link

Using release 0.5.1, I initially posted this as a comment for issue #48 but decided it should be its own issue.

Issue: Float slider (step is float) fails to display float value if initial value is integer, even tho the onChange shows the correct value. It is a display problem

This (es6, babel):
var gui = new dat.GUI()
var callback = (val) => console.log('message', val, UI)
var UI = {speed: 0}
gui.add(UI, 'speed').min(-10).max(10).step(.5).onChange(callback)
.. the console shows the .5 steps but the dat.gui display only shows integer values.

This workaround shows the correct float steps, appearing to be initialized as the 0 int value:
var UI = {speed: .5}
gui.add(UI, 'speed').min(-10).max(10).step(.5).listen().onChange(callback)
UI.speed = 0

Prior comment:
This did not completely fix it for me. If I have a float slider that starts out with an integer value, I still get this problem. Works fine if the initial value is non-integer.

Does the fix here work for everyone else? I.e. float slider that starts out with integer initial value?

I did find a work-around:

Make sure the initial value is non-integer.
Add .listen() to the property.
Then set the property to the integer value.
I.e. I start with:
var UI = {
...
x: .1, // workaround for float slider bug
y: .1,
z: .1,
...
}
gui.add(UI, 'x').min(-10).max(10).step(.1).listen().onChange(callback)
gui.add(UI, 'y').min(-10).max(10).step(.1).listen().onChange(callback)
gui.add(UI, 'z').min(-10).max(10).step(.1).listen().onChange(callback)
UI.x = UI.y = UI.z = 0

@makc
Copy link

makc commented Oct 18, 2015

@backspaces thanks for workaround (setting to non-integer). I wish they had .precision(.01) method.

@makc makc mentioned this issue Oct 18, 2015
@wassname
Copy link

Fixed by pull request #47 (if you use step). Not sure when if it will be merged

@customlogic
Copy link
Contributor

fixes to step behavior have been merged into develop 922de64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants