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

73 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-08-15 16:32:49 +00:00
Polymer('gui-panel', {
2014-08-21 17:20:06 +00:00
docked: false,
2014-08-15 16:32:49 +00:00
ready: function() {
2014-08-21 17:20:06 +00:00
this.anon.values = {};
2014-08-15 22:04:51 +00:00
},
2014-08-21 17:20:06 +00:00
anon: function( name, initialValue ) {
2014-08-15 22:04:51 +00:00
2014-08-21 17:20:06 +00:00
if ( arguments.length == 1 ) {
return this.anon.values[ name ];
}
2014-08-15 22:04:51 +00:00
2014-08-21 17:20:06 +00:00
var args = [ this.anon.values, name ];
args = args.concat( Array.prototype.slice.call( arguments, 2 ) );
2014-08-15 22:04:51 +00:00
2014-08-21 17:20:06 +00:00
this.anon.values[ name ] = initialValue;
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
return this.add.apply( this, args );
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
},
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
add: function( object, path ) {
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
// Make controller
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
var value = Path.get( path ).getValueFrom( object );
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
if ( value == null || value == undefined ) {
return console.error( object + ' doesn\'t have a value for path "' + path + '".' );
2014-08-16 21:16:02 +00:00
}
2014-08-21 17:20:06 +00:00
var args = Array.prototype.slice.call( arguments, 2 );
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
var controller = Gui.getController( value, args );
if ( !controller ) {
return console.error( 'Unrecognized type: ', value );
2014-08-15 22:04:51 +00:00
}
2014-08-21 17:20:06 +00:00
controller.watch( object, path )
controller.init.apply( controller, args );
// Make row
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
var row = document.createElement( 'gui-row' );
row.name = path;
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
}
});