dat.gui/elements/gui-panel/gui-panel.js

71 lines
1.5 KiB
JavaScript
Raw Normal View History

2014-08-15 16:32:49 +00:00
Polymer('gui-panel', {
ready: function() {
2014-08-15 22:04:51 +00:00
document.body.appendChild( this );
},
add: function( object, property ) {
var row = document.createElement( 'gui-row' );
var controller;
2014-08-16 21:16:02 +00:00
var value;
// gui.add( object, 'property' ...
if ( typeof object == 'object' ) {
value = object[ property ];
// gui.add( 0, 'anonymous-value' ...
} else {
value = object;
}
if ( typeof value == 'number' ) {
2014-08-15 22:04:51 +00:00
controller = document.createElement( 'controller-number' );
2014-08-15 22:04:51 +00:00
if ( arguments[ 2 ] !== undefined ) controller.min = arguments[ 2 ];
if ( arguments[ 3 ] !== undefined ) controller.max = arguments[ 3 ];
if ( arguments[ 4 ] !== undefined ) controller.step = arguments[ 4 ];
}
2014-08-16 21:16:02 +00:00
// gui.add( object, 'property' ...
if ( typeof object == 'object' ) {
controller.object = object;
controller.property = property;
}
row.name = property;
2014-08-15 22:04:51 +00:00
controller.name = function( name ) {
row.name = name;
};
2014-08-16 21:16:02 +00:00
controller.comment = function( comment ) {
row.comment = comment;
};
2014-08-15 22:04:51 +00:00
row.appendChild( controller );
this.appendChild( row );
return controller;
},
listenAll: function() {
console.warn( 'controller.listenAll() is deprecated. All controllers are listened for free.' );
2014-08-15 16:32:49 +00:00
}
});