dat-gui has a color selector and understands many different representations of color. The following creates color controllers for color variables of different formats.
You can listen for events on individual controllers using an event listener syntax.
```javascript
var controller = gui.add(fizzyText, 'maxSize', 0, 10);
controller.onChange(function(value) {
// Fires on every change, drag, keypress, etc.
});
controller.onFinishChange(function(value) {
// Fires when a controller loses focus.
alert("The new value is " + value);
});
```
## Folders
You can nest as many Gui's as you want. Nested Gui's act as collapsible folders.
```javascript
var gui = new Gui();
var f1 = gui.addFolder('Flow Field');
f1.add(text, 'speed');
f1.add(text, 'noiseStrength');
var f2 = gui.addFolder('Letters');
f2.add(text, 'growthSpeed');
f2.add(text, 'maxSize');
f2.add(text, 'message');
f2.open();
```
## Saving Values
Add a save menu to the interface by calling `gui.remember` on all the objects you've added to the Gui.
```javascript
var fizzyText = new FizzyText();
var gui = new Gui();
gui.remember(fizzyText);
// Add controllers ...
```
Click the gear icon to change your save settings. You can either save your Gui's values to localStorage, or by copying and pasting a JSON object into your source code as follows:
dat-gui comes with a node server that listens for changes to your Gui and saves them to disk. This way you don't have to worry about losing your local storage or copying and pasting a JSON string.
var controller = document.getElementById( 'my-controller' );
controller.onChange( function() {
// react to UI changes ...
} );
</script>
</body>
```
## Defining Custom Controllers
dat-gui uses [Polymer]( todo ) under the hood to define custom elements. A dat-gui controller is just a [Polymer element]( todo ) with two important requirements:
- Controllers must extend `<controller-base>`.
- Controllers must be associated with a data type.
Take for example this (simplified) source for dat-gui's `<controller-number>`:
```javascript
Polymer( 'controller-number', {
// Define element ...
} );
Gui.register( 'controller-number', function( value ) {
return typeof value == 'number';
} );
```
`Gui.register` takes an element name and a test function. The call to `Gui.register` tells dat-gui to add a `<controller-number>` to the panel when the user adds a variable whose type is `'number'`.
A test function takes a value added with `gui.add` and returns a boolean that determines if the controller is appropriate for the value. This example uses [duck typing]( todo ) to register `<vector-controller>` for values that have properties `x`, `y` and `z`.
```javascript
Gui.register( 'vector-controller', function( value ) {
return value.hasOwnProperty( 'x' ) &&
value.hasOwnProperty( 'y' ) &&
value.hasOwnProperty( 'z' );
} );
```
## Publishing Custom Controllers
You should use bower and format your plugin all nice and it should have a certain prefix yada yada.