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

NumberController Step not working properly #48

Closed
TylerOrtiz opened this issue Aug 7, 2014 · 6 comments
Closed

NumberController Step not working properly #48

TylerOrtiz opened this issue Aug 7, 2014 · 6 comments

Comments

@TylerOrtiz
Copy link

No matter what I do, I can't get decimals to show up in a number controller. I pass in something like 106.108383382 and I always get 106 no matter what.

I've been digging through the source and can't figure out how or why the parameters for step are being lost...
var gui = new dat.GUI({autoPlace: true});
gui .add(data, 'length').step(0.25);

I have also tried making the step: (999.999, 0.999, 999.000) and nothing seems to affect how it functions at all...even though the source says it should modify precision.

However the issue seems to be in the factory:

return new NumberControllerBox(object, property, { min: arguments[2], max: arguments[3] });

Where it doesn't seem to care about any properties except for min and max.

@miketahani
Copy link

Having this problem also. Value is a float but the number in the GUI is always displayed as an int.

@milcktoast
Copy link

This was fixed by #31, but this change is not reflected in the 0.5.0 built distributable.
See source vs build.

@doug
Copy link
Contributor

doug commented Feb 4, 2015

updated the build to 0.5.1 with latest from master. https://github.com/dataarts/dat.gui/releases

@doug doug closed this as completed Feb 4, 2015
@backspaces
Copy link

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

@anhr
Copy link

anhr commented Feb 2, 2019

I still see this issue. You can use my code for resolving of problem.
First, add my new method into dat.gui

if ( dat.controllerZeroStep === undefined ) {

	//Solving of dat.gui NumberController Step bug.
	//
	//folder: GUI or folder for new Controller.
	//object: The object to be manipulated. See https://github.com/dataarts/dat.gui/blob/master/API.md#GUI+add for details
	//property: The name of the property to be manipulated. See https://github.com/dataarts/dat.gui/blob/master/API.md#GUI+add for details
	//onchange: Callback function will be called if controller value was changed. Can be undefined.
	//
	dat.controllerZeroStep = function ( folder, object, property, onchange ) {

		var controller = folder.add( object, property ),
			input = controller.__input;
		controller.__input = document.createElement( 'input' );
		input.value = object[property];
		input.onchange = function ( value ) {

			object[property] = parseFloat( input.value );

			if ( onchange !== undefined )
				onchange( object[property] );

		};
		return controller;

	};

} else console.error( 'Duplicate dat.controllerZeroStep method.' );

Next, add a controller into gui. For example:

var gui = new dat.GUI();
var object = { min: 123.456 }
dat.controllerZeroStep( gui, object, 'min', function ( value ) {

	console.log( 'object.min = ' + object.min + ' value = ' + value );

} );

@anhr
Copy link

anhr commented Feb 3, 2019

Another way of resolving of issue is debug of dat.GUI. See my
"NumberController Step is working properly" commit for details.

Now you can set step = 0 to gui controller. For example:

var gui = new dat.GUI();
var object = { min: 123.456 }
gui.add( object, 'min', undefined, undefined, 0).onChange( function (value) {

	console.log( 'object.min = ' + object.min + ' value = ' + value );

} )

Note: Plaese do not use gui.add( object, 'min').step( 0 ).

Currently I have made pull request. Please write a comments to my pull request if you want to see my code in next dat.GUI release.

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

6 participants