gui-dat is a lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly.
<script type="text/javascript" src="demo/demo.js"></script> <script type="text/javascript"> window.onload = function() { var fizzyText = new FizzyText("gui-dat"); var gui = new GUI(); // 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. }; </script>
this.prop = value
.gui.add(obj, "propName").onChange(function(n) { alert("You changed me to " + n); });
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 listen()
method.
gui.add(obj, "changingProperty").listen();
By default, gui-dat will create an internal interval that checks for changes in the values you've marked with listen()
. If you'd like to check for these changes in an interval of your own definition, use the following:
gui.autoListen = false; // disables internal interval gui.add(obj, "changingProperty").listen(); // Make your own loop setInterval(function() { gui.listen(); // updates values you've marked with listen() }, 1000 / 60);
Alternatively, you can forego calling listen()
on individual controllers, and instead choose to monitor changes in all values controlled by your gui.
gui.autoListen = false; // disables internal interval gui.add(obj, "add"); gui.add(obj, "lotsa"); gui.add(obj, "properties"); // Make your own loop setInterval(function() { gui.listenAll(); // updates ALL values managed by this gui }, 1000 / 60);
You can instantiate multiple GUI
objects and name them however you'd like.
var gui1 = new GUI(); var gui2 = new GUI(); // The name function overwrites the "Show Controls" text. gui1.name("Utilities"); gui2.name("Camera Placement");
By default, gui-dat 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.
// Notice this belongs to the GUI class (uppercase) // 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"; document.getElementById("my-gui-container").appendChild( gui.domElement );