Giter Site home page Giter Site logo

Comments (6)

backspaces avatar backspaces commented on July 18, 2024 3

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

from dat.gui.

miketahani avatar miketahani commented on July 18, 2024

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

from dat.gui.

milcktoast avatar milcktoast commented on July 18, 2024

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

from dat.gui.

doug avatar doug commented on July 18, 2024

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

from dat.gui.

anhr avatar anhr commented on July 18, 2024

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 );

} );

from dat.gui.

anhr avatar anhr commented on July 18, 2024

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.

from dat.gui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.