mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
Merged my changes with doob's -- exact same external functionality, some internal differences
This commit is contained in:
commit
ad78b157e1
31
README
31
README
@ -1,31 +0,0 @@
|
|||||||
var controllableObject =
|
|
||||||
{
|
|
||||||
numberProperty: 20,
|
|
||||||
anotherNumberProperty: 0,
|
|
||||||
textProperty: "a string",
|
|
||||||
booleanProperty: false,
|
|
||||||
functionProperty: function() {
|
|
||||||
alert("I am a function!");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onload = function() {
|
|
||||||
|
|
||||||
GUI.start();
|
|
||||||
|
|
||||||
// Creates a number box
|
|
||||||
GUI.add(controllableObject, "numberProperty");
|
|
||||||
|
|
||||||
// Creates a slider (min, max)
|
|
||||||
GUI.add(controllableObject, "anotherNumberProperty", -100, 100);
|
|
||||||
|
|
||||||
// Creates a text field
|
|
||||||
GUI.add(controllableObject, "textProperty");
|
|
||||||
|
|
||||||
// Creates a checkbox
|
|
||||||
GUI.add(controllableObject, "booleanProperty");
|
|
||||||
|
|
||||||
// Creates a button
|
|
||||||
GUI.add(controllableObject, "functionProperty");
|
|
||||||
|
|
||||||
}
|
|
44
README.md
Normal file
44
README.md
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# gui-dat
|
||||||
|
**gui-dat** is a lightweight controller library for JavaScript. It allows you to easily manipulate variables and fire functions on the fly.
|
||||||
|
## Basic Usage
|
||||||
|
<script type="text/javascript" src="demo/demo.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
window.onload = function() {
|
||||||
|
|
||||||
|
var fizzyText = new FizzyText("gui-dat");
|
||||||
|
|
||||||
|
GUI.start();
|
||||||
|
|
||||||
|
// 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>
|
||||||
|
+ ui-dat will infer the type of the property you're trying to add (based on its initial value) and create the corresponding control.
|
||||||
|
+ The properties must be public, i.e. defined by `this.prop = value`.
|
||||||
|
|
||||||
|
Monitor variable changes <i>outside</i> of the GUI
|
||||||
|
--------------------------------------------------
|
||||||
|
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, "propName").listen();
|
||||||
|
## Fire a function when someone uses a control
|
||||||
|
GUI.add(obj, "propName").onChange(function(n) {
|
||||||
|
alert("You changed me to " + n);
|
||||||
|
});
|
||||||
|
Initiated by [George Michael Brower](http://georgemichaelbrower.com/) and [Jono Brandel](http://jonobr1.com/) of the Data Arts Team, Google Creative Lab.
|
@ -1,6 +1,7 @@
|
|||||||
var BooleanController = function() {
|
var BooleanController = function() {
|
||||||
|
|
||||||
this.type = "boolean";
|
this.type = "boolean";
|
||||||
Controller.apply(this, arguments);
|
Controller.apply(this, arguments);
|
||||||
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
var input = document.createElement('input');
|
var input = document.createElement('input');
|
||||||
@ -26,4 +27,4 @@ var BooleanController = function() {
|
|||||||
|
|
||||||
};
|
};
|
||||||
BooleanController.prototype = new Controller();
|
BooleanController.prototype = new Controller();
|
||||||
BooleanController.prototype.constructor = BooleanController;
|
BooleanController.prototype.constructor = BooleanController;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
var FunctionController = function() {
|
var FunctionController = function() {
|
||||||
this.type = "function";
|
this.type = "function";
|
||||||
var _this = this;
|
var that = this;
|
||||||
Controller.apply(this, arguments);
|
Controller.apply(this, arguments);
|
||||||
this.domElement.addEventListener('click', function() {
|
this.domElement.addEventListener('click', function() {
|
||||||
_this.object[_this.propertyName].call(_this.object);
|
that.object[that.propertyName].call(that.object);
|
||||||
}, false);
|
}, false);
|
||||||
this.domElement.style.cursor = "pointer";
|
this.domElement.style.cursor = "pointer";
|
||||||
this.propertyNameElement.style.cursor = "pointer";
|
this.propertyNameElement.style.cursor = "pointer";
|
||||||
};
|
};
|
||||||
FunctionController.prototype = new Controller();
|
FunctionController.prototype = new Controller();
|
||||||
FunctionController.prototype.constructor = FunctionController;
|
FunctionController.prototype.constructor = FunctionController;
|
||||||
|
@ -26,12 +26,18 @@ Controller.prototype.name = function(n) {
|
|||||||
Controller.prototype.listen = function() {
|
Controller.prototype.listen = function() {
|
||||||
this.parent.listenTo(this);
|
this.parent.listenTo(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Controller.prototype.unlisten = function() {
|
||||||
|
this.parent.unlistenTo(this); // <--- hasn't been implemented yet
|
||||||
|
}
|
||||||
|
|
||||||
Controller.prototype.setValue = function(n) {
|
Controller.prototype.setValue = function(n) {
|
||||||
this.object[this.propertyName] = n;
|
this.object[this.propertyName] = n;
|
||||||
if (this.changeFunction != null) {
|
if (this.changeFunction != null) {
|
||||||
this.changeFunction.call(this, n);
|
this.changeFunction.call(this, n);
|
||||||
}
|
}
|
||||||
|
// Whenever you call setValue, the display will be updated automatically.
|
||||||
|
// This reduces some clutter in subclasses. We can also use this method for listen().
|
||||||
this.updateDisplay();
|
this.updateDisplay();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -45,4 +51,4 @@ Controller.prototype.updateDisplay = function() {}
|
|||||||
Controller.prototype.onChange = function(fnc) {
|
Controller.prototype.onChange = function(fnc) {
|
||||||
this.changeFunction = fnc;
|
this.changeFunction = fnc;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -81,10 +81,11 @@ var NumberController = function() {
|
|||||||
var dragNumberField = function(e) {
|
var dragNumberField = function(e) {
|
||||||
draggedNumberField = true;
|
draggedNumberField = true;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// We don't want to be highlighting this field as we scroll.
|
// We don't want to be highlighting this field as we scroll.
|
||||||
// Or any other fields in this gui for that matter ...
|
// Or any other fields in this gui for that matter ...
|
||||||
// TODO: Make makeUselectable go through each element and child element.
|
// TODO: Make makeUselectable go through each element and child element.
|
||||||
|
|
||||||
GUI.makeUnselectable(_this.parent.domElement);
|
GUI.makeUnselectable(_this.parent.domElement);
|
||||||
GUI.makeUnselectable(numberField);
|
GUI.makeUnselectable(numberField);
|
||||||
|
|
||||||
@ -120,8 +121,7 @@ var NumberController = function() {
|
|||||||
numberField.value = roundToDecimal(_this.getValue(), 4);
|
numberField.value = roundToDecimal(_this.getValue(), 4);
|
||||||
if (slider) slider.value = _this.getValue();
|
if (slider) slider.value = _this.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NumberController.prototype = new Controller();
|
NumberController.prototype = new Controller();
|
||||||
NumberController.prototype.constructor = NumberController;
|
NumberController.prototype.constructor = NumberController;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
var StringController = function() {
|
var StringController = function() {
|
||||||
|
|
||||||
this.type = "string";
|
this.type = "string";
|
||||||
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
Controller.apply(this, arguments);
|
Controller.apply(this, arguments);
|
||||||
|
|
||||||
@ -10,6 +11,7 @@ var StringController = function() {
|
|||||||
|
|
||||||
input.setAttribute('value', initialValue);
|
input.setAttribute('value', initialValue);
|
||||||
input.setAttribute('spellcheck', 'false');
|
input.setAttribute('spellcheck', 'false');
|
||||||
|
|
||||||
this.domElement.addEventListener('mouseup', function() {
|
this.domElement.addEventListener('mouseup', function() {
|
||||||
input.focus();
|
input.focus();
|
||||||
input.select();
|
input.select();
|
||||||
@ -24,6 +26,8 @@ var StringController = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.domElement.appendChild(input);
|
this.domElement.appendChild(input);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
StringController.prototype = new Controller();
|
StringController.prototype = new Controller();
|
||||||
StringController.prototype.constructor = StringController;
|
StringController.prototype.constructor = StringController;
|
||||||
|
@ -60,4 +60,4 @@ var Slider = function(numberController, min, max, step, initValue) {
|
|||||||
|
|
||||||
this.value = initValue;
|
this.value = initValue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
11
demo/demo.js
11
demo/demo.js
@ -1,15 +1,18 @@
|
|||||||
function FizzyText(message) {
|
function FizzyText(message) {
|
||||||
|
|
||||||
|
var that = this;
|
||||||
|
|
||||||
// These are the variables that we manipulate with gui-dat.
|
// These are the variables that we manipulate with gui-dat.
|
||||||
// Notice they're all defined with "this". That makes them public.
|
// Notice they're all defined with "this". That makes them public.
|
||||||
// Otherwise, gui-dat can't see them.
|
// Otherwise, gui-dat can't see them.
|
||||||
|
|
||||||
this.growthSpeed = 0.5; // how fast do particles change size?
|
this.growthSpeed = 0.5; // how fast do particles change size?
|
||||||
this.maxSize = 3.2; // how big can they get?
|
this.maxSize = 3.2; // how big can they get?
|
||||||
this.noiseStrength = 10; // how turbulent is the flow?
|
this.noiseStrength = 10; // how turbulent is the flow?
|
||||||
this.speed = 0.4; // how fast do particles move?
|
this.speed = 0.4; // how fast do particles move?
|
||||||
this.displayOutline = false; // should we draw the message as a stroke?
|
this.displayOutline = false; // should we draw the message as a stroke?
|
||||||
|
this.framesRendered = 0;
|
||||||
|
|
||||||
// __defineGetter__ and __defineSetter__ makes JavaScript believe that
|
// __defineGetter__ and __defineSetter__ makes JavaScript believe that
|
||||||
// we've defined a variable 'this.message'. This way, whenever we
|
// we've defined a variable 'this.message'. This way, whenever we
|
||||||
// change the message variable, we can call some more functions.
|
// change the message variable, we can call some more functions.
|
||||||
@ -98,6 +101,8 @@ function FizzyText(message) {
|
|||||||
// Called once per frame, updates the animation.
|
// Called once per frame, updates the animation.
|
||||||
var render = function () {
|
var render = function () {
|
||||||
|
|
||||||
|
that.framesRendered ++;
|
||||||
|
|
||||||
g.clearRect(0, 0, width, height);
|
g.clearRect(0, 0, width, height);
|
||||||
|
|
||||||
if (_this.displayOutline) {
|
if (_this.displayOutline) {
|
||||||
@ -216,4 +221,4 @@ function FizzyText(message) {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
1538
demo/prettify.js
Normal file
1538
demo/prettify.js
Normal file
File diff suppressed because it is too large
Load Diff
8
gui.css
8
gui.css
@ -8,9 +8,6 @@
|
|||||||
left: 100%;
|
left: 100%;
|
||||||
margin-left: -300px;
|
margin-left: -300px;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
-moz-transition: margin-top .2s ease-out;
|
|
||||||
-webkit-transition: margin-top .2s ease-out;
|
|
||||||
transition: margin-top .2s ease-out;
|
|
||||||
-webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
|
-webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
|
||||||
-moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
|
-moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
|
||||||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
|
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
|
||||||
@ -26,6 +23,9 @@
|
|||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
background-color: rgba(0,0,0,0.1);
|
background-color: rgba(0,0,0,0.1);
|
||||||
|
-moz-transition: height .2s ease-out;
|
||||||
|
-webkit-transition: height .2s ease-out;
|
||||||
|
transition: height .2s ease-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
#guidat-toggle {
|
#guidat-toggle {
|
||||||
@ -155,4 +155,4 @@ width: 148px;
|
|||||||
.guidat-slider-fg {
|
.guidat-slider-fg {
|
||||||
background-color: #00aeff;
|
background-color: #00aeff;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
}
|
}
|
||||||
|
145
gui.js
145
gui.js
@ -7,6 +7,35 @@ var GUI = function() {
|
|||||||
|
|
||||||
var autoListen = true;
|
var autoListen = true;
|
||||||
var listenInterval;
|
var listenInterval;
|
||||||
|
|
||||||
|
var _this = this, open = false,
|
||||||
|
controllers = [], controllersWatched = [];
|
||||||
|
|
||||||
|
this.domElement = document.createElement('div');
|
||||||
|
this.domElement.setAttribute('id', 'guidat');
|
||||||
|
|
||||||
|
controllerContainer = document.createElement('div');
|
||||||
|
controllerContainer.setAttribute('id', 'guidat-controllers');
|
||||||
|
|
||||||
|
// @doob
|
||||||
|
// I think this is way more elegant than the negative margin.
|
||||||
|
// Only wish we didn't have to see the scrollbar on its way open.
|
||||||
|
// Any thoughts?
|
||||||
|
controllerContainer.style.height = '0px';
|
||||||
|
|
||||||
|
toggleButton = document.createElement('a');
|
||||||
|
toggleButton.setAttribute('id', 'guidat-toggle');
|
||||||
|
toggleButton.setAttribute('href', '#');
|
||||||
|
toggleButton.innerHTML = "Show Controls";
|
||||||
|
toggleButton.addEventListener('click', function(e) {
|
||||||
|
_this.toggle();
|
||||||
|
e.preventDefault();
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
this.domElement.appendChild(controllerContainer);
|
||||||
|
this.domElement.appendChild(toggleButton);
|
||||||
|
|
||||||
|
|
||||||
this.autoListenIntervalTime = 1000/60;
|
this.autoListenIntervalTime = 1000/60;
|
||||||
|
|
||||||
var createListenInterval = function() {
|
var createListenInterval = function() {
|
||||||
@ -14,7 +43,6 @@ var GUI = function() {
|
|||||||
_this.listen();
|
_this.listen();
|
||||||
}, this.autoListenIntervalTime);
|
}, this.autoListenIntervalTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.__defineSetter__("autoListen", function(v) {
|
this.__defineSetter__("autoListen", function(v) {
|
||||||
autoListen = v;
|
autoListen = v;
|
||||||
@ -55,41 +83,66 @@ var GUI = function() {
|
|||||||
|
|
||||||
this.autoListen = true;
|
this.autoListen = true;
|
||||||
|
|
||||||
this.add = function() {
|
var handlerTypes = {
|
||||||
|
"number": NumberController,
|
||||||
// We need to call GUI.start() before .add()
|
"string": StringController,
|
||||||
if (!started) {
|
"boolean": BooleanController,
|
||||||
error("Make sure to call GUI.start() in the window.onload function");
|
"function": FunctionController
|
||||||
return;
|
};
|
||||||
|
|
||||||
|
var alreadyControlled = function(object, propertyName) {
|
||||||
|
for (var i in controllers) {
|
||||||
|
if (controllers[i].object == object &&
|
||||||
|
controllers[i].propertyName == propertyName) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
var error = function(str) {
|
||||||
|
if (typeof console.log == 'function') {
|
||||||
|
console.error("[GUI ERROR] " + str);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var construct = function(constructor, args) {
|
||||||
|
function F() {
|
||||||
|
return constructor.apply(this, args);
|
||||||
|
}
|
||||||
|
F.prototype = constructor.prototype;
|
||||||
|
return new F();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.add = function() {
|
||||||
|
|
||||||
var object = arguments[0];
|
var object = arguments[0];
|
||||||
var propertyName = arguments[1];
|
var propertyName = arguments[1];
|
||||||
|
|
||||||
// Have we already added this?
|
// Have we already added this?
|
||||||
if (alreadyControlled(object, propertyName)) {
|
if (alreadyControlled(object, propertyName)) {
|
||||||
error("Controller for \"" + propertyName+"\" already added.");
|
error("Controller for \"" + propertyName+"\" already added.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var value = object[propertyName];
|
var value = object[propertyName];
|
||||||
|
|
||||||
// Does this value exist? Is it accessible?
|
// Does this value exist? Is it accessible?
|
||||||
if (value == undefined) {
|
if (value == undefined) {
|
||||||
error(object + " either has no property \""+propertyName+"\", or the property is inaccessible.");
|
error(object + " either has no property \""+propertyName+"\", or the property is inaccessible.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = typeof value;
|
var type = typeof value;
|
||||||
var handler = addHandlers[type];
|
var handler = handlerTypes[type];
|
||||||
|
|
||||||
// Do we know how to deal with this data type?
|
// Do we know how to deal with this data type?
|
||||||
if (handler == undefined) {
|
if (handler == undefined) {
|
||||||
error("Cannot create controller for data type \""+type+"\"");
|
error("Cannot create controller for data type \""+type+"\"");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var args = [_this];
|
var args = [_this]; // Set first arg (parent) to this
|
||||||
for (var j = 0; j < arguments.length; j++) {
|
for (var j = 0; j < arguments.length; j++) {
|
||||||
args.push(arguments[j]);
|
args.push(arguments[j]);
|
||||||
}
|
}
|
||||||
@ -97,15 +150,15 @@ var GUI = function() {
|
|||||||
var controllerObject = construct(handler, args);
|
var controllerObject = construct(handler, args);
|
||||||
|
|
||||||
// Were we able to make the controller?
|
// Were we able to make the controller?
|
||||||
if (!controllerObject) {
|
if (!controllerObject) {
|
||||||
error("Error creating controller for \""+propertyName+"\".");
|
error("Error creating controller for \""+propertyName+"\".");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success.
|
// Success.
|
||||||
controllerContainer.appendChild(controllerObject.domElement);
|
controllerContainer.appendChild(controllerObject.domElement);
|
||||||
controllers.push(controllerObject);
|
controllers.push(controllerObject);
|
||||||
|
|
||||||
return controllerObject;
|
return controllerObject;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -145,64 +198,22 @@ var GUI = function() {
|
|||||||
|
|
||||||
// GUI ... GUI
|
// GUI ... GUI
|
||||||
|
|
||||||
this.domElement = null;
|
|
||||||
var controllerContainer;
|
|
||||||
var started = false;
|
|
||||||
var open = false;
|
|
||||||
|
|
||||||
// TODO: obtain this dynamically?
|
|
||||||
var domElementMarginTop = 300;
|
|
||||||
|
|
||||||
this.start = function() {
|
|
||||||
|
|
||||||
this.domElement = document.createElement('div');
|
|
||||||
this.domElement.setAttribute('id', 'guidat');
|
|
||||||
|
|
||||||
controllerContainer = document.createElement('div');
|
|
||||||
controllerContainer.setAttribute('id', 'guidat-controllers');
|
|
||||||
|
|
||||||
toggleButton = document.createElement('a');
|
|
||||||
toggleButton.setAttribute('id', 'guidat-toggle');
|
|
||||||
toggleButton.setAttribute('href', '#');
|
|
||||||
toggleButton.innerHTML = "Show Controls";
|
|
||||||
toggleButton.addEventListener('click', function(e) {
|
|
||||||
_this.toggle();
|
|
||||||
e.preventDefault();
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
this.domElement.appendChild(controllerContainer);
|
|
||||||
this.domElement.appendChild(toggleButton);
|
|
||||||
|
|
||||||
this.domElement.style.marginTop = -domElementMarginTop+"px";
|
|
||||||
|
|
||||||
document.body.appendChild(this.domElement);
|
|
||||||
|
|
||||||
started = true;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
this.toggle = function() {
|
this.toggle = function() {
|
||||||
|
open ? this.hide() : this.show();
|
||||||
if (open) {
|
|
||||||
this.hide();
|
|
||||||
} else {
|
|
||||||
this.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.show = function() {
|
this.show = function() {
|
||||||
this.domElement.style.marginTop = 0+"px";
|
controllerContainer.style.height = '300px';
|
||||||
toggleButton.innerHTML = "Hide Controls";
|
toggleButton.innerHTML = "Hide Controls";
|
||||||
open = true;
|
open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hide = function() {
|
this.hide = function() {
|
||||||
this.domElement.style.marginTop = -domElementMarginTop+"px";
|
controllerContainer.style.height = '0px';
|
||||||
toggleButton.innerHTML = "Show Controls";
|
toggleButton.innerHTML = "Show Controls";
|
||||||
open = false;
|
open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Util functions
|
// Util functions
|
||||||
|
121
index.html
121
index.html
@ -1,82 +1,72 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<head>
|
<head>
|
||||||
<title>gui-dat</title>
|
<title>gui-dat</title>
|
||||||
|
<link rel="icon" type="image/png" href="demo/assets/favicon.png" />
|
||||||
<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="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="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"></script>-->
|
|
||||||
<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.number.js"></script>
|
|
||||||
<script type="text/javascript" src="controllers/controller.string.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="demo/improvedNoise.js"></script>
|
<!-- <script type="text/javascript" src="gui.min.js"></script> -->
|
||||||
<script type="text/javascript" src="demo/demo.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
var fizzyText;
|
|
||||||
var gui;
|
|
||||||
window.onload = function() {
|
|
||||||
|
|
||||||
// prettyPrint();
|
<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>
|
||||||
|
|
||||||
fizzyText = new FizzyText("gui-dat");
|
|
||||||
|
|
||||||
gui = new GUI();
|
<script type="text/javascript" src="demo/improvedNoise.js"></script>
|
||||||
gui.start();
|
<script type="text/javascript" src="demo/prettify.js"></script>
|
||||||
|
<script type="text/javascript" src="demo/demo.js"></script>
|
||||||
// Text field
|
<script type="text/javascript">
|
||||||
gui.add(fizzyText, "message").listen();
|
|
||||||
|
window.onload = function() {
|
||||||
|
|
||||||
|
prettyPrint();
|
||||||
|
|
||||||
|
var fizzyText = new FizzyText("gui-dat");
|
||||||
|
|
||||||
|
var gui = new GUI();
|
||||||
|
document.body.appendChild( gui.domElement );
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
// 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").onChange(function(v) {
|
|
||||||
alert(v);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fires a function called "explode"
|
|
||||||
gui.add(fizzyText, "explode")
|
|
||||||
.name('Explode!'); // Specify a custom name.
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
var _gaq = _gaq || [];
|
|
||||||
_gaq.push(['_setAccount', 'UA-20996084-1']);
|
|
||||||
_gaq.push(['_trackPageview']);
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
||||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
|
||||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
||||||
})();
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="container">
|
<div id="container">
|
||||||
<div id = "helvetica-demo"></div>
|
<div id = "helvetica-demo"></div>
|
||||||
<div id = "notifier"></div>
|
<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>
|
<h1><a href = "http://twitter.com/guidat"><img src = "demo/assets/profile.png" border = "0" alt = "GUI-DAT flag" /></a></h1>
|
||||||
<p>
|
<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.
|
<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>
|
</p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="https://github.com/jonobr1/GUI-DAT/raw/master/gui.min.js"><strong>Download the minified source</strong></a> <small>[9.8kb]</small></li>
|
<li><a href="https://github.com/jonobr1/GUI-DAT/raw/master/gui.min.js"><strong>Download the minified source</strong></a> <small>[9.8kb]</small></li>
|
||||||
<li><a href="http://github.com/jonobr1/GUI-DAT">Contribute on GitHub!</a></li>
|
<li><a href="http://github.com/jonobr1/GUI-DAT">Contribute on GitHub!</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h2>Basic Usage</h2>
|
<h2>Basic Usage</h2>
|
||||||
<pre class="prettyprint"><script type="text/javascript" src="demo/demo.js"></script>
|
<pre id="demo-pre" class="prettyprint"><script type="text/javascript" src="demo/demo.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
@ -84,8 +74,8 @@ window.onload = function() {
|
|||||||
var fizzyText = new <a href="demo/demo.js">FizzyText</a>("gui-dat");
|
var fizzyText = new <a href="demo/demo.js">FizzyText</a>("gui-dat");
|
||||||
|
|
||||||
var gui = new GUI();
|
var gui = new GUI();
|
||||||
gui.start();
|
document.body.appendChild( gui.domElement );
|
||||||
|
|
||||||
// Text field
|
// Text field
|
||||||
gui.add(fizzyText, "message");
|
gui.add(fizzyText, "message");
|
||||||
|
|
||||||
@ -93,20 +83,20 @@ window.onload = function() {
|
|||||||
gui.add(fizzyText, "maxSize", 0.5, 7);
|
gui.add(fizzyText, "maxSize", 0.5, 7);
|
||||||
gui.add(fizzyText, "growthSpeed", 0.01, 1);
|
gui.add(fizzyText, "growthSpeed", 0.01, 1);
|
||||||
gui.add(fizzyText, "speed", 0.1, 2);
|
gui.add(fizzyText, "speed", 0.1, 2);
|
||||||
|
|
||||||
// Sliders with min, max and increment
|
// Sliders with min, max and increment.
|
||||||
gui.add(fizzyText, "noiseStrength", 10, 100, 5);
|
gui.add(fizzyText, "noiseStrength", 10, 100, 5);
|
||||||
|
|
||||||
// Boolean checkbox
|
// Boolean checkbox
|
||||||
gui.add(fizzyText, "displayOutline");
|
gui.add(fizzyText, "displayOutline");
|
||||||
|
|
||||||
// Fires a function called "explode"
|
// Fires a function called "explode"
|
||||||
gui.add(fizzyText, "explode").name("Explode!"); // Specify a custom name.
|
gui.add(fizzyText, "explode").name("Explode!"); // Specify a custom name.
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
</script></pre>
|
</script></pre>
|
||||||
|
|
||||||
<ul id="desc">
|
<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><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>
|
<li>The properties must be public, i.e. defined by <code><strong>this</strong>.prop = value</code>.</li>
|
||||||
@ -148,6 +138,7 @@ setInterval(function() {
|
|||||||
<footer>
|
<footer>
|
||||||
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.
|
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.
|
||||||
</footer>
|
</footer>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user