<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>
<h3id="folders-comments">Folders & Comments</h3>
<p>You can nest as many dat-gui as you want. Nested dat-gui 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.open();
</code></pre>
<p>The comment method adds a tooltip to a controller.</p>
<pre><codeclass="lang-javascript">f2.add(text, 'message').comment( 'This is the comment.' );
</code></pre>
<h3id="saving-values">Saving Values</h3>
<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 dat-gui 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>
<h3id="presets">Presets</h3>
<p>The save menu also allows you to save all of your settings as presets. Click Save to modify the current preset, or New to create a new preset from existing settings. Clicking Revert will clear all unsaved changes to the current preset.</p>
<p>Switch between presets using the dropdown in the save menu. You can specify the default like this:</p>
<pre><codeclass="lang-javascript">var gui = new Gui({
load: JSON,
preset: 'Flow'
});
</code></pre>
<p>A word of caution about localStorage:</p>
<p>Paste the JSON save object into your source frequently. Using localStorage to save presets can make you faster, but its easy to lose your settings by clearing browsing data, changing browsers, or even by changing the URL of the page you're working on.</p>
<h3id="save-to-disk">Save to Disk</h3>
<p>dat-gui comes with a node server that saves your settings to disk. This way you don't have to worry about losing your values to 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. dat-gui will read from this file on load and write to this file on change.</p>
<pre><codeclass="lang-javascript">var gui = new Gui( { load: 'path/to/file.json' } );
</code></pre>
<h3id="custom-placement">Custom Placement</h3>
<p>By default, Gui panels are created with fixed position, and are automatically appended to the body. 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>
<p>Since dat-gui is built using <ahref="todo">Web Components</a>, you can also 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 test function 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 determines if a controller is appropriate for a given value. This example registers <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 ) {