mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
option controller
This commit is contained in:
parent
1dca89383b
commit
d76808c344
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -4,7 +4,6 @@
|
||||
[ ] onFinishChange( )
|
||||
|
||||
*/
|
||||
|
||||
Polymer('controller-base', {
|
||||
|
||||
ready: function() {
|
||||
@ -26,7 +25,7 @@ Polymer('controller-base', {
|
||||
this.object = object;
|
||||
this.path = path;
|
||||
|
||||
this.bind('value', new PathObserver(this.object, this.path));
|
||||
this.bind( 'value', new PathObserver( this.object, this.path ) );
|
||||
|
||||
},
|
||||
|
||||
@ -45,6 +44,11 @@ Polymer('controller-base', {
|
||||
return ( x - a ) / ( b - a ) * ( d - c ) + c;
|
||||
},
|
||||
|
||||
on: function( event, listener ) {
|
||||
this.addEventListener( event, listener );
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
// Legacy
|
||||
// -------------------------------
|
||||
|
@ -164,12 +164,16 @@ Polymer( 'controller-number', {
|
||||
this._rect = this.$.track.getBoundingClientRect();
|
||||
if ( !this._alt ) this.value = this.valueFromX( e.x );
|
||||
|
||||
this.fire( 'sliderDown' );
|
||||
|
||||
},
|
||||
|
||||
up: function( e ) {
|
||||
|
||||
// this.$.container.classList.add( 'transition' );
|
||||
|
||||
this.fire( 'sliderUp' );
|
||||
|
||||
},
|
||||
|
||||
trackstart: function( e ) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<script src="controller-option.js"></script>
|
||||
|
||||
<polymer-element name="controller-option" extends="controller-base" attributes="options">
|
||||
<polymer-element name="controller-option" extends="controller-base" attributes="options key">
|
||||
|
||||
<template>
|
||||
|
||||
@ -10,10 +10,10 @@
|
||||
|
||||
<div id="container" horizontal layout center>
|
||||
|
||||
<select value="{{ value }}">
|
||||
<select value="{{ key }}" on-change="{{ change }}">
|
||||
|
||||
<template repeat="{{ name in options | getKeys }}">
|
||||
<option value="{{ options[ name ] }}">{{ name }}</option>
|
||||
<template repeat="{{ name in options | keys }}">
|
||||
<option value="{{ name }}">{{ name }}</option>
|
||||
</template>
|
||||
|
||||
</select>
|
||||
|
@ -1,5 +1,7 @@
|
||||
Polymer( 'controller-option', {
|
||||
|
||||
key: null,
|
||||
|
||||
ready: function() {
|
||||
|
||||
this.options = {};
|
||||
@ -24,7 +26,27 @@ Polymer( 'controller-option', {
|
||||
|
||||
},
|
||||
|
||||
getKeys: function( object ) {
|
||||
valueChanged: function() {
|
||||
|
||||
for ( var i in this.options ) {
|
||||
if ( this.options[ i ] === this.value ) {
|
||||
this.key = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.super();
|
||||
|
||||
},
|
||||
|
||||
keyChanged: function() {
|
||||
|
||||
this.value = this.options[ this.key ];
|
||||
|
||||
},
|
||||
|
||||
keys: function( object ) {
|
||||
|
||||
if ( object ) return Object.keys( object );
|
||||
|
||||
|
@ -35,7 +35,6 @@ Polymer('gui-panel', {
|
||||
|
||||
add: function( object, path ) {
|
||||
|
||||
|
||||
// Make controller
|
||||
|
||||
var value = Path.get( path ).getValueFrom( object );
|
||||
|
@ -70,7 +70,7 @@
|
||||
gui.add( object, 'optionController', { A: 'a', B: 'b', C: 'c'} );
|
||||
gui.add( object, 'optionController', [ 'a', 'b', 'c' ] )
|
||||
.onChange( function( val ) {
|
||||
console.log( val );
|
||||
// console.log( val );
|
||||
});
|
||||
|
||||
} );
|
||||
|
Loading…
Reference in New Issue
Block a user