Skip to content

Instantly share code, notes, and snippets.

@rhysburnie
Created October 29, 2017 03:41
Show Gist options
  • Save rhysburnie/a945c8bfca8ce704ee39d5d6280509c7 to your computer and use it in GitHub Desktop.
Save rhysburnie/a945c8bfca8ce704ee39d5d6280509c7 to your computer and use it in GitHub Desktop.
dat.GUI convert a field to a display instead of input
dat.GUI.prototype.convertToDisplay = function(owner, property) {
var field = this.__controllers.find(function(item){return item.property === property});
var parent = field.domElement.parentElement;
var value = owner[property];
delete owner[property];
Object.defineProperty(owner, property, {
get: function() {
return value;
},
set: function(newValue) {
value = newValue;
parent.innerText = newValue;
}
});
}
@rhysburnie
Copy link
Author

function Thing() {
  this.message = '';
}
var thing = new Thing();
var gui = new dat.GUI();
gui.add(thing, 'message');
gui.convertToDisplay(thing, 'message');
setInterval(function(){
  thing.message = Date.now();
},500);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment