dattasaurabh82 / dat-gui

Automatically exported from code.google.com/p/dat-gui
0 stars 0 forks source link

Events not sent when creating a "number" controller with both min() and max() called explicitely #55

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
create a controller on a number member of your object.
do not specify min or max there.
for eg: 
  var controller = gui.add(myObject, 'speed');

specify min and max after that:
  controller.min( 0 );      
  controller.max( 500 );

then register event listeners to it
  controller.onChange( function(value) { console.log("change"); } );
  controller.onFinishChange( function(value) { console.log("finishChange"); } );

The listeners should be called when the user changes the value but they're not.

The culprit is the max() method that in this context triggers reconstruction of 
the ui and breaks the event notifications.

I'm using Chrome on Windows 7 with dat.gui downloaded on the 21 dec. 2014.

Here is some code to reproduce the problem:
function MyObject(speed)
{
    this.speed = speed;
}

function reproduceBug()
{
    var datgui = new dat.GUI();
    var myObject = new MyObject(5);
    var controller = datgui.add(myObject, 'speed');
    controller.min( 0 );        
    controller.max( 500 );      
    controller.onChange( function(value) { console.log("change"); } );
    controller.onFinishChange( function(value) { console.log("finishChange"); } );
}

Original issue reported on code.google.com by jbiton...@gmail.com on 21 Dec 2014 at 2:34