mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
Attempt at listen fix
checks dom.isactive & allows displayUpdate(force), set true for by default for setValue fixes isactive problems allows drag events, and re-added key up/down
This commit is contained in:
parent
743a16b398
commit
5212bd428e
@ -17,6 +17,7 @@
|
|||||||
* @param {Object} object The object to be manipulated
|
* @param {Object} object The object to be manipulated
|
||||||
* @param {string} property The name of the property to be manipulated
|
* @param {string} property The name of the property to be manipulated
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
constructor(object, property) {
|
constructor(object, property) {
|
||||||
this.initialValue = object[property];
|
this.initialValue = object[property];
|
||||||
@ -92,7 +93,7 @@ class Controller {
|
|||||||
this.__onChange.call(this, newValue);
|
this.__onChange.call(this, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateDisplay();
|
this.updateDisplay(true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ class Controller {
|
|||||||
* with the object's current value.
|
* with the object's current value.
|
||||||
* @returns {Controller} this
|
* @returns {Controller} this
|
||||||
*/
|
*/
|
||||||
updateDisplay() {
|
updateDisplay(force) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,11 +94,22 @@ class NumberControllerBox extends NumberController {
|
|||||||
dom.bind(this.__input, 'mousedown', onMouseDown);
|
dom.bind(this.__input, 'mousedown', onMouseDown);
|
||||||
dom.bind(this.__input, 'keydown', function(e) {
|
dom.bind(this.__input, 'keydown', function(e) {
|
||||||
// When pressing enter, you can be as precise as you want.
|
// When pressing enter, you can be as precise as you want.
|
||||||
if (e.keyCode === 13) {
|
const step = _this.__step || 1;
|
||||||
|
switch (e.keyCode) {
|
||||||
|
case 13:
|
||||||
_this.__truncationSuspended = true;
|
_this.__truncationSuspended = true;
|
||||||
this.blur();
|
this.blur();
|
||||||
_this.__truncationSuspended = false;
|
_this.__truncationSuspended = false;
|
||||||
onFinish();
|
onFinish();
|
||||||
|
break;
|
||||||
|
case 38:
|
||||||
|
var newVal = _this.getValue() + step;
|
||||||
|
_this.setValue(newVal);
|
||||||
|
break;
|
||||||
|
case 40: // down
|
||||||
|
var newVal = _this.getValue() - step;
|
||||||
|
_this.setValue(newVal);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -107,7 +118,8 @@ class NumberControllerBox extends NumberController {
|
|||||||
this.domElement.appendChild(this.__input);
|
this.domElement.appendChild(this.__input);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDisplay() {
|
updateDisplay(force) {
|
||||||
|
if (!force && dom.isActive(this.__input)) return this;
|
||||||
this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal(this.getValue(), this.__precision);
|
this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal(this.getValue(), this.__precision);
|
||||||
return super.updateDisplay();
|
return super.updateDisplay();
|
||||||
}
|
}
|
||||||
|
@ -75,10 +75,10 @@ class OptionController extends Controller {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDisplay() {
|
updateDisplay(force) {
|
||||||
if (dom.isActive(this.__select)) return this; // prevent number from updating if user is trying to manually update
|
if (!force && dom.isActive(this.__select)) return this; // prevent number from updating if user is trying to manually update
|
||||||
this.__select.value = this.getValue();
|
this.__select.value = this.getValue();
|
||||||
return super.updateDisplay();
|
return super.updateDisplay(force);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user