2011-01-31 04:53:33 +00:00
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns = "http://www.w3.org/1999/xhtml" >
< head >
< meta name = "generator" content = "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" / >
< title > gui-dat< / title >
< link rel = "icon" type = "image/png" href = "demo/assets/favicon.png" / >
< link href = "demo/demo.css" media = "screen" rel = "stylesheet" type = "text/css" / >
< link href = "gui.css" media = "screen" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "gui.js" >
< / script >
< script type = "text/javascript" src = "controllers/slider.js" >
< / script >
< script type = "text/javascript" src = "controllers/controller.js" >
< / script >
< script type = "text/javascript" src = "controllers/controller.boolean.js" >
< / script >
< script type = "text/javascript" src = "controllers/controller.function.js" >
< / script >
< script type = "text/javascript" src = "controllers/controller.number.js" >
< / script >
< script type = "text/javascript" src = "controllers/controller.string.js" >
< / script >
< script type = "text/javascript" src = "demo/improvedNoise.js" >
< / script >
< script type = "text/javascript" src = "demo/prettify.js" >
< / script >
< script type = "text/javascript" src = "demo/demo.js" >
< / script >
< script type = "text/javascript" >
2011-01-31 20:21:14 +00:00
//< ![CDATA[
2011-01-31 04:53:33 +00:00
window.onload = function() {
prettyPrint();
var fizzyText = new FizzyText("gui-dat");
var gui = new GUI();
2011-01-31 15:47:07 +00:00
2011-01-31 04:53:33 +00:00
// Text field
gui.add(fizzyText, "message");
// Sliders with min and max
gui.add(fizzyText, "maxSize", 0.5, 7);
gui.add(fizzyText, "growthSpeed", 0.01, 1);
gui.add(fizzyText, "speed", 0.1, 2);
// Sliders with min, max and increment.
gui.add(fizzyText, "noiseStrength", 10, 100, 5);
// Boolean checkbox
gui.add(fizzyText, "displayOutline");
// Fires a function called "explode"
gui.add(fizzyText, "explode").name("Explode!"); // Specify a custom name.
2011-01-31 20:21:14 +00:00
// Javascript for documentation
getCollapsables();
handleListening();
2011-01-31 04:53:33 +00:00
};
2011-01-31 20:21:14 +00:00
function toggle(e) {
2011-02-03 22:36:28 +00:00
var collapsable = this.childNodes[3],
wrapper = collapsable.childNodes[1];
if (this.className === 'collapsed') {
2011-01-31 20:21:14 +00:00
this.className = 'expanded';
2011-02-03 22:36:28 +00:00
collapsable.style.height = wrapper.clientHeight + 'px';
2011-01-31 20:21:14 +00:00
} else {
this.className = 'collapsed';
2011-02-03 22:36:28 +00:00
collapsable.style.height = '0px';
2011-01-31 20:21:14 +00:00
}
}
function getCollapsables() {
if (document.getElementsByClassName == undefined) {
document.getElementsByClassName = function(className)
{
var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
var allElements = document.getElementsByTagName("*");
var results = [];
var element;
for (var i = 0; (element = allElements[i]) != null; i++) {
var elementClass = element.className;
if (elementClass & & elementClass.indexOf(className) != -1 & & hasClassName.test(elementClass))
results.push(element);
}
return results;
};
}
collapsed = document.getElementsByClassName('collapsed');
expanded = document.getElementsByClassName('expanded');
}
function handleListening() {
for(var i = 0; i < collapsed.length ; i + + ) {
collapsed[i].addEventListener('click', toggle, false);
}
for(var j = 0; j < expanded.length ; j + + ) {
expanded[i].addEventListener('click', toggle, false);
}
}
2011-01-31 04:53:33 +00:00
//]]>
< / script >
< / head >
< body >
< div id = "container" >
2011-01-31 20:21:14 +00:00
<!-- GUIDAT logo -->
2011-01-31 04:53:33 +00:00
< div id = "helvetica-demo" > < / div >
2011-01-31 20:21:14 +00:00
<!-- It gives you this! -->
2011-01-31 04:53:33 +00:00
< div id = "notifier" > < / div >
< h1 > < a href = "http://twitter.com/guidat" > < img src = "demo/assets/profile.png" border = "0" alt = "GUI-DAT flag" / > < / a > < / h1 >
< p > < strong > gui-dat< / strong > is a lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly.< / p >
< ul >
< li > < a href = "https://github.com/jonobr1/gui-dat/raw/versions/gui.min.js" > < strong > Download the minified source< / strong > < / a > < small > [11kb]< / small > < / li >
< li > < a href = "http://github.com/jonobr1/gui-dat" > Contribute on GitHub!< / a > < / li >
< / ul >
< h2 > Basic Usage< / h2 >
< pre id = "demo-pre" class = "prettyprint" >
2011-02-01 01:24:30 +00:00
< script type="text/javascript" src="gui.min.js"> < /script>
2011-01-31 04:53:33 +00:00
< script type="text/javascript">
2011-01-28 20:26:38 +00:00
window.onload = function() {
2011-01-31 04:53:33 +00:00
var fizzyText = new < a href = "demo/demo.js" > FizzyText< / a > ("gui-dat");
2011-01-28 20:26:38 +00:00
2011-01-29 04:04:33 +00:00
var gui = new GUI();
2011-01-29 00:38:58 +00:00
2011-01-28 20:26:38 +00:00
// Text field
2011-01-31 04:53:33 +00:00
gui.add(fizzyText, "message");
2011-01-28 20:26:38 +00:00
// Sliders with min and max
2011-01-31 04:53:33 +00:00
gui.add(fizzyText, "maxSize", 0.5, 7);
gui.add(fizzyText, "growthSpeed", 0.01, 1);
gui.add(fizzyText, "speed", 0.1, 2);
2011-01-29 00:38:58 +00:00
// Sliders with min, max and increment.
2011-01-31 04:53:33 +00:00
gui.add(fizzyText, "noiseStrength", 10, 100, 5);
2011-01-29 00:38:58 +00:00
2011-01-28 20:26:38 +00:00
// Boolean checkbox
2011-01-31 04:53:33 +00:00
gui.add(fizzyText, "displayOutline");
2011-01-28 20:26:38 +00:00
2011-01-31 04:53:33 +00:00
// Fires a function called "explode"
gui.add(fizzyText, "explode").name("Explode!"); // Specify a custom name.
2011-01-29 00:38:58 +00:00
2011-01-28 20:26:38 +00:00
};
2011-01-31 04:53:33 +00:00
< /script>
< / pre >
< ul id = "desc" >
< li > < strong > gui-dat< / strong > will infer the type of the property you're trying to add< br / >
(based on its initial value) and create the corresponding control.< / li >
< li > The properties must be public, i.e. defined by < code > < strong > this< / strong > .prop = value< / code > .< / li >
< / ul >
<!--
< h2 class = "collapsed" > Fire a function when someone uses a control< / h2 >
< pre class = "prettyprint" > gui.add(obj, "propName").onChange(function(n) {
alert("You changed me to " + n);
});< / pre > -->
2011-01-31 20:21:14 +00:00
< div class = "collapsed" >
2011-02-01 00:49:14 +00:00
< h2 class = "section" > Saving your parameters< / h2 >
2011-01-31 20:21:14 +00:00
< div class = "collapsable" >
2011-02-03 22:36:28 +00:00
< div >
< p > The simplest way to save your parameters is via < code > GUI.saveURL()< / code > . This method directs your browser to a URL containing the current GUI settings.< / p >
< pre class = "prettyprint" >
2011-01-31 04:53:33 +00:00
// Make a button for the url function
2011-02-01 00:49:14 +00:00
gui.add(GUI, "saveURL");< / pre >
2011-02-03 22:36:28 +00:00
< / div >
2011-01-31 20:21:14 +00:00
< / div >
< / div >
< div class = "collapsed" >
2011-02-01 00:49:14 +00:00
< h2 class = "section" > Advanced saving< / h2 >
2011-01-31 20:21:14 +00:00
< div class = "collapsable" >
2011-02-03 22:36:28 +00:00
< div >
< p > Let's say you'd like to share your settings with someone. Instead of sending a long link with lots of parameters stored in it, you can make your saved settings the defaults.< / p >
2011-01-31 04:53:33 +00:00
2011-02-03 22:36:28 +00:00
< p > First, add the method < code > GUI.showSaveString()< / code > to a gui object:< / p >
< pre class = "prettyprint" > var gui = new GUI();
2011-01-31 04:53:33 +00:00
// Add some stuff (and pretend I change their values);
gui.add(someObject, "someProperty");
gui.add(someObject, "someOtherProperty");
// Make a save button.
2011-02-01 00:49:14 +00:00
gui.add(GUI, "showSaveString");< / pre >
2011-01-31 04:53:33 +00:00
2011-02-03 22:36:28 +00:00
< p > Clicking the "showSaveString" button bring up an alert with a string. Copy and paste that string into the method < code > GUI.load()< / code > before you instantiate any gui objects.< / p >
< pre class = "prettyprint" >
2011-02-01 01:24:30 +00:00
// Replace COPIED STRING with the value you got from showSaveString()
2011-01-31 04:53:33 +00:00
GUI.load("COPIED STRING");
var gui = new GUI();
// Now these properties will be set to the values you just saved.
gui.add(someObject, "someProperty");
2011-02-01 00:49:14 +00:00
gui.add(someObject, "someOtherProperty");< / pre >
2011-01-31 04:53:33 +00:00
2011-02-03 22:36:28 +00:00
< p > < strong > Save strings won't work if you change the order in which you've added properties to your gui objects, or the order of the gui objects themselves.< / strong > . If you want to add more parameters to your gui and use an old save string, make sure they're added after the properties whose values you've saved.< / p >
< / div >
< / div >
2011-01-31 04:53:33 +00:00
< / div >
2011-01-31 20:21:14 +00:00
< div class = "collapsed" >
2011-02-01 00:49:14 +00:00
< h2 class = "section" > Listen for variable changes outside of the GUI< / h2 >
2011-01-31 20:21:14 +00:00
< div class = "collapsable" >
2011-02-03 22:36:28 +00:00
< div >
< p > Let's say you have a variable that changes by itself from time to time. If you'd like the GUI to reflect those changes, use the < code > listen()< / code > method.< / p >
< pre class = "prettyprint" > gui.add(obj, "changingProperty").listen();< / pre >
< / div >
< / div >
2011-01-31 20:21:14 +00:00
< / div >
2011-01-31 04:53:33 +00:00
2011-01-31 20:21:14 +00:00
< div class = "collapsed" >
2011-02-01 00:49:14 +00:00
< h2 class = "section" > Advanced listening< / h2 >
2011-01-31 20:21:14 +00:00
< div class = "collapsable" >
2011-02-03 22:36:28 +00:00
< div >
< p > By default, < strong > gui-dat< / strong > will create an internal interval that checks for changes in the values you've marked with < code > listen()< / code > . If you'd like to check for these changes in an interval of your own definition, use the following:< / p >
< pre class = "prettyprint" >
2011-01-29 04:04:33 +00:00
gui.autoListen = false; // disables internal interval
2011-01-30 23:03:09 +00:00
gui.add(obj, "changingProperty").listen();
2011-01-29 04:04:33 +00:00
// Make your own loop
setInterval(function() {
2011-02-02 00:04:39 +00:00
gui.listen(); // updates values you've marked with listen()
2011-02-01 00:49:14 +00:00
}, 1000 / 60);< / pre >
2011-01-31 04:53:33 +00:00
2011-02-03 22:36:28 +00:00
< p > Alternatively, you can forego calling < code > listen()< / code > on individual controllers, and instead choose to monitor changes in < em > all< / em > values controlled by your gui.< / p >
< pre class = "prettyprint" >
2011-01-29 04:04:33 +00:00
gui.autoListen = false; // disables internal interval
gui.add(obj, "add");
gui.add(obj, "lotsa");
gui.add(obj, "properties");
// Make your own loop
setInterval(function() {
2011-02-02 00:04:39 +00:00
gui.listenAll(); // updates ALL values managed by this gui
2011-02-01 00:49:14 +00:00
}, 1000 / 60);< / pre >
2011-02-03 22:36:28 +00:00
< / div >
2011-01-31 20:21:14 +00:00
< / div >
< / div >
2011-01-31 04:53:33 +00:00
2011-01-31 20:21:14 +00:00
< div class = "collapsed" >
2011-02-01 00:49:14 +00:00
< h2 class = "section" > Multiple panels and custom placement< / h2 >
2011-01-31 20:21:14 +00:00
< div class = "collapsable" >
2011-02-03 22:36:28 +00:00
< div >
< p > You can instantiate multiple < code > GUI< / code > objects and name them however you'd like.< / p >
< pre class = "prettyprint" > var gui1 = new GUI();
2011-01-30 23:03:09 +00:00
var gui2 = new GUI();
// The name function overwrites the "Show Controls" text.
gui1.name("Utilities");
2011-02-01 00:49:14 +00:00
gui2.name("Camera Placement");< / pre >
2011-01-31 04:53:33 +00:00
2011-02-03 22:36:28 +00:00
< p > By default, < strong > gui-dat< / strong > panels will be automatically added to the HTML document and fixed to the top of the screen. You can disable this behavior / styling and append the gui DOM element to a container of your choosing.< / p >
< pre class = "prettyprint" >
2011-01-31 04:53:33 +00:00
// Notice this belongs to the GUI class (uppercase)
2011-01-30 23:03:09 +00:00
// and not an instance thereof.
GUI.autoPlace = false;
var gui = new GUI();
// Do some custom styles ...
gui.domElement.style.position = "absolute";
gui.domElement.style.top = "20px";
gui.domElement.style.left = "20px";
2011-02-01 00:49:14 +00:00
document.getElementById("my-gui-container").appendChild( gui.domElement );< / pre >
2011-02-03 22:36:28 +00:00
< / div >
2011-01-31 20:21:14 +00:00
< / div >
2011-01-31 04:53:33 +00:00
< / div >
2011-01-31 20:21:14 +00:00
< div class = "collapsed" >
2011-02-03 22:36:28 +00:00
< h2 class = "section" > Pro tips.< / h2 >
2011-01-31 20:21:14 +00:00
< div class = "collapsable" >
2011-02-03 22:36:28 +00:00
< div >
< ol id = "secrets" >
< li > < strong > gui-dat< / strong > panels are resizeable. Drag the show/hide button.< / li >
2011-01-31 20:21:14 +00:00
2011-02-03 22:36:28 +00:00
< li > Pro tip #2 forthcoming.< / li >
< / ol >
< / div >
2011-01-31 20:21:14 +00:00
< / div >
< / div >
2011-02-03 22:36:28 +00:00
< div class = "trans" > < / div >
< footer class = "trans" > Initiated by < a href = "http://georgemichaelbrower.com/" > George Michael Brower< / a > and < a href = "http://jonobr1.com/" > Jono Brandel< / a > of the Data Arts Team, Google Creative Lab.
2011-01-31 20:21:14 +00:00
< / footer >
2011-01-31 04:53:33 +00:00
< / body >
2011-01-29 00:38:58 +00:00
< / html >