<p>dat-gui has a color selector and understands many different representations of color. The following creates color controllers for color variables of different formats.</p>
<p>You can nest as many Gui's as you want. Nested Gui's act as collapsible folders.</p>
<pre><codeclass="lang-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();
</code></pre>
<h2id="saving-values">Saving Values</h2>
<p>Add a save menu to the interface by calling <code>gui.remember</code> on all the objects you've added to the Gui.</p>
<pre><codeclass="lang-javascript">var fizzyText = new FizzyText();
var gui = new Gui();
gui.remember(fizzyText);
// Add controllers ...
</code></pre>
<p>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:</p>
<pre><codeclass="lang-javascript">var fizzyText = new FizzyText();
var gui = new Gui({ load: JSON });
gui.remember(fizzyText);
// Add controllers ...
</code></pre>
<h2id="save-to-disk">Save to disk</h2>
<p>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.</p>
<p>First, run the node script:</p>
<pre><codeclass="lang-sh">$ node gui-server
</code></pre>
<p>Next, instantiate your Gui with a path to a JSON file to store settings. </p>
<pre><codeclass="lang-javascript">var gui = new Gui( { save: 'path/to/file.json' } );
gui.remember( fizzyText );
// Add controllers ...
</code></pre>
<h2id="custom-placement">Custom Placement</h2>
<p>By default, Gui panels are created with fixed position, and are automatically appended to the body.</p>
<p>You can change this behavior by setting the <code>autoPlace</code> parameter to <code>false</code>.</p>
<pre><codeclass="lang-javascript">var gui = new Gui( { autoPlace: false } );
var customContainer = document.getElementById('my-gui-container');
customContainer.appendChild(gui.domElement);
</code></pre>
<h2id="html-elements">HTML Elements</h2>
<p>Since dat-gui is built using <ahref="todo">Web Components</a>, you can use HTML syntax to add controllers to the page.</p>
<p>dat-gui uses <ahref="todo">Polymer</a> under the hood to define custom elements. A dat-gui controller is just a <ahref="todo">Polymer element</a> with two important requirements:</p>
<ul>
<li>Controllers must extend <code><controller-base></code>.</li>
<li>Controllers must be associated with a data type.</li>
</ul>
<p>Take for example this (simplified) source for dat-gui's <code><controller-number></code>:</p>
Gui.register( 'controller-number', function( value ) {
return typeof value == 'number';
} );
</code></pre>
<p><code>Gui.register</code> takes an element name and a test function. The call to <code>Gui.register</code> tells dat-gui to add a <code><controller-number></code> to the panel when the user adds a variable whose type is <code>'number'</code>.</p>
<p>A test function takes a value added with <code>gui.add</code> and returns a boolean that determines if the controller is appropriate for the value. This example uses <ahref="todo">duck typing</a> to register <code><vector-controller></code> for values that have properties <code>x</code>, <code>y</code> and <code>z</code>.</p>
<pre><codeclass="lang-javascript">Gui.register( 'vector-controller', function( value ) {