mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
closing
This commit is contained in:
parent
d3b01eef71
commit
e3fa6b31c2
File diff suppressed because one or more lines are too long
73
build/dat.gui.min.js
vendored
73
build/dat.gui.min.js
vendored
File diff suppressed because one or more lines are too long
@ -7,7 +7,7 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var obj = { x: 5 };
|
var obj = { x: 5 };
|
||||||
var gui = new dat.GUI();
|
var gui = new dat.GUI();
|
||||||
gui.add(obj, 'x', 0, 10);
|
gui.add(obj, 'x');
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -82,8 +82,8 @@ _To export minified source using Closure Compiler, open {{{utils/build_gui.js}}}
|
|||||||
----
|
----
|
||||||
|
|
||||||
==Thanks==
|
==Thanks==
|
||||||
The following libraries and open-source projects were used in the development of dat.GUI.
|
The following libraries / open-source projects were used in the development of dat.GUI:
|
||||||
* [http://requirejs.org/ require.js]
|
* [http://requirejs.org/ require.js]
|
||||||
* [http://sass-lang.com/ Sass]
|
* [http://sass-lang.com/ Sass]
|
||||||
* [http://nodejs.org/ node.js]
|
* [http://nodejs.org/ node.js]
|
||||||
* [https://github.com/jquery/qunit QUnit] / [http://jquery.com jquery]
|
* [https://github.com/jquery/qunit QUnit] / [http://jquery.com/ jquery]
|
@ -35,8 +35,10 @@ define([
|
|||||||
|
|
||||||
this.__button = document.createElement('div');
|
this.__button = document.createElement('div');
|
||||||
this.__button.innerHTML = text === undefined ? 'Fire' : text;
|
this.__button.innerHTML = text === undefined ? 'Fire' : text;
|
||||||
dom.bind(this.__button, 'click', function() {
|
dom.bind(this.__button, 'click', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
_this.fire();
|
_this.fire();
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
dom.addClass(this.__button, 'button');
|
dom.addClass(this.__button, 'button');
|
||||||
|
@ -43,6 +43,9 @@ define([
|
|||||||
|
|
||||||
var HIDE_KEY_CODE = 72;
|
var HIDE_KEY_CODE = 72;
|
||||||
|
|
||||||
|
/** The only value shared between the JS and SCSS. Use caution. */
|
||||||
|
var CLOSE_BUTTON_HEIGHT = 20;
|
||||||
|
|
||||||
var DEFAULT_DEFAULT_PRESET_NAME = 'Default';
|
var DEFAULT_DEFAULT_PRESET_NAME = 'Default';
|
||||||
|
|
||||||
var SUPPORTS_LOCAL_STORAGE = (function() {
|
var SUPPORTS_LOCAL_STORAGE = (function() {
|
||||||
@ -197,7 +200,6 @@ define([
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles <code>GUI</code>'s element placement for you
|
* Handles <code>GUI</code>'s element placement for you
|
||||||
* @type Boolean
|
* @type Boolean
|
||||||
@ -285,7 +287,10 @@ define([
|
|||||||
// Lets just check our height against the window height right off
|
// Lets just check our height against the window height right off
|
||||||
// the bat.
|
// the bat.
|
||||||
this.onResize();
|
this.onResize();
|
||||||
// resetWidth();
|
|
||||||
|
if (_this.__closeButton) {
|
||||||
|
_this.__closeButton.innerHTML = v ? GUI.TEXT_OPEN : GUI.TEXT_CLOSED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -329,6 +334,7 @@ define([
|
|||||||
if (common.isUndefined(params.parent)) {
|
if (common.isUndefined(params.parent)) {
|
||||||
|
|
||||||
params.closed = false;
|
params.closed = false;
|
||||||
|
|
||||||
dom.addClass(this.domElement, GUI.CLASS_MAIN);
|
dom.addClass(this.domElement, GUI.CLASS_MAIN);
|
||||||
dom.makeSelectable(this.domElement, false);
|
dom.makeSelectable(this.domElement, false);
|
||||||
|
|
||||||
@ -349,6 +355,19 @@ define([
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.__closeButton = document.createElement('div');
|
||||||
|
this.__closeButton.innerHTML = GUI.TEXT_CLOSED;
|
||||||
|
dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BUTTON);
|
||||||
|
this.domElement.appendChild(this.__closeButton);
|
||||||
|
|
||||||
|
dom.bind(this.__closeButton, 'click', function() {
|
||||||
|
|
||||||
|
_this.closed = !_this.closed;
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Oh, you're a nested GUI!
|
// Oh, you're a nested GUI!
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -363,7 +382,6 @@ define([
|
|||||||
|
|
||||||
var on_click_title = function(e) {
|
var on_click_title = function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation()
|
|
||||||
_this.closed = !_this.closed;
|
_this.closed = !_this.closed;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
@ -420,18 +438,18 @@ define([
|
|||||||
localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject()));
|
localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Small hack to fix CSS positioning bug in Chrome
|
var root = _this.getRoot();
|
||||||
function resetWidth() {
|
function resetWidth() {
|
||||||
var root = _this.getRoot();
|
var root = _this.getRoot();
|
||||||
root.width += 1;
|
root.width += 1;
|
||||||
common.defer(function() {
|
common.defer(function() {
|
||||||
root.width -= 1;
|
root.width -= 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.parent) {
|
if (!params.parent) {
|
||||||
resetWidth();
|
resetWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -450,8 +468,12 @@ define([
|
|||||||
GUI.CLASS_CONTROLLER_ROW = 'cr';
|
GUI.CLASS_CONTROLLER_ROW = 'cr';
|
||||||
GUI.CLASS_TOO_TALL = 'taller-than-window';
|
GUI.CLASS_TOO_TALL = 'taller-than-window';
|
||||||
GUI.CLASS_CLOSED = 'closed';
|
GUI.CLASS_CLOSED = 'closed';
|
||||||
|
GUI.CLASS_CLOSE_BUTTON = 'close-button';
|
||||||
|
GUI.CLASS_DRAG = 'drag';
|
||||||
|
|
||||||
GUI.DEFAULT_WIDTH = 245;
|
GUI.DEFAULT_WIDTH = 245;
|
||||||
|
GUI.TEXT_CLOSED = 'Close Controls';
|
||||||
|
GUI.TEXT_OPEN = 'Open Controls';
|
||||||
|
|
||||||
dom.bind(window, 'keydown', function(e) {
|
dom.bind(window, 'keydown', function(e) {
|
||||||
|
|
||||||
@ -573,44 +595,40 @@ define([
|
|||||||
|
|
||||||
var li = addRow(this, gui.domElement);
|
var li = addRow(this, gui.domElement);
|
||||||
dom.addClass(li, 'folder');
|
dom.addClass(li, 'folder');
|
||||||
|
|
||||||
gui.open = function() {
|
|
||||||
this.closed = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
gui.close = function() {
|
|
||||||
this.closed = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
return gui;
|
return gui;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onResize: function() {
|
open: function() {
|
||||||
|
this.closed = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
close: function() {
|
||||||
|
this.closed = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
onResize: function() {
|
||||||
|
|
||||||
var root = this.getRoot();
|
var root = this.getRoot();
|
||||||
|
|
||||||
|
|
||||||
if (root.scrollable) {
|
if (root.scrollable) {
|
||||||
|
|
||||||
var top = dom.getOffset(root.domElement).top;
|
var top = dom.getOffset(root.__ul).top;
|
||||||
|
|
||||||
var h = 0;
|
var h = 0;
|
||||||
|
|
||||||
common.each(root.__ul.childNodes, function(node) {
|
common.each(root.__ul.childNodes, function(node) {
|
||||||
h += dom.getHeight(node);
|
if (! (root.autoPlace && node === root.__save_row))
|
||||||
|
h += dom.getHeight(node);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (window.innerHeight - top - CLOSE_BUTTON_HEIGHT < h) {
|
||||||
if (window.innerHeight < h) {
|
|
||||||
dom.addClass(root.domElement, GUI.CLASS_TOO_TALL);
|
dom.addClass(root.domElement, GUI.CLASS_TOO_TALL);
|
||||||
root.__ul.style.height = window.innerHeight - top + 'px';
|
root.__ul.style.height = window.innerHeight - top - CLOSE_BUTTON_HEIGHT + 'px';
|
||||||
} else {
|
} else {
|
||||||
dom.removeClass(root.domElement, GUI.CLASS_TOO_TALL);
|
dom.removeClass(root.domElement, GUI.CLASS_TOO_TALL);
|
||||||
root.__ul.style.height = 'auto';
|
root.__ul.style.height = 'auto';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root.__resize_handle) {
|
if (root.__resize_handle) {
|
||||||
@ -619,6 +637,10 @@ define([
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (root.__closeButton) {
|
||||||
|
root.__closeButton.style.width = root.width + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1201,6 +1223,7 @@ define([
|
|||||||
var pmouseX;
|
var pmouseX;
|
||||||
|
|
||||||
dom.bind(gui.__resize_handle, 'mousedown', dragStart);
|
dom.bind(gui.__resize_handle, 'mousedown', dragStart);
|
||||||
|
dom.bind(gui.__closeButton, 'mousedown', dragStart);
|
||||||
|
|
||||||
gui.domElement.insertBefore(gui.__resize_handle, gui.domElement.firstElementChild);
|
gui.domElement.insertBefore(gui.__resize_handle, gui.domElement.firstElementChild);
|
||||||
|
|
||||||
@ -1210,6 +1233,7 @@ define([
|
|||||||
|
|
||||||
pmouseX = e.clientX;
|
pmouseX = e.clientX;
|
||||||
|
|
||||||
|
dom.addClass(gui.__closeButton, GUI.CLASS_DRAG);
|
||||||
dom.bind(window, 'mousemove', drag);
|
dom.bind(window, 'mousemove', drag);
|
||||||
dom.bind(window, 'mouseup', dragStop);
|
dom.bind(window, 'mouseup', dragStop);
|
||||||
|
|
||||||
@ -1222,6 +1246,7 @@ define([
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
gui.width += pmouseX - e.clientX;
|
gui.width += pmouseX - e.clientX;
|
||||||
|
gui.onResize();
|
||||||
pmouseX = e.clientX;
|
pmouseX = e.clientX;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -1230,6 +1255,7 @@ define([
|
|||||||
|
|
||||||
function dragStop() {
|
function dragStop() {
|
||||||
|
|
||||||
|
dom.removeClass(gui.__closeButton, GUI.CLASS_DRAG);
|
||||||
dom.unbind(window, 'mousemove', drag);
|
dom.unbind(window, 'mousemove', drag);
|
||||||
dom.unbind(window, 'mouseup', dragStop);
|
dom.unbind(window, 'mouseup', dragStop);
|
||||||
|
|
||||||
@ -1243,6 +1269,8 @@ define([
|
|||||||
// set the width manually if we want it to bleed to the edge
|
// set the width manually if we want it to bleed to the edge
|
||||||
if (gui.__save_row && gui.autoPlace) {
|
if (gui.__save_row && gui.autoPlace) {
|
||||||
gui.__save_row.style.width = w + 'px';
|
gui.__save_row.style.width = w + 'px';
|
||||||
|
}if (gui.__closeButton) {
|
||||||
|
gui.__closeButton.style.width = w + 'px';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
$nest-margin: 4px;
|
$nest-margin: 4px;
|
||||||
$row-height: 27px;
|
$row-height: 27px;
|
||||||
|
|
||||||
|
$button-height: 20px;
|
||||||
|
|
||||||
.dg {
|
.dg {
|
||||||
|
|
||||||
/** Clear list styles */
|
/** Clear list styles */
|
||||||
@ -22,12 +24,60 @@ $row-height: 27px;
|
|||||||
z-index: 0;
|
z-index: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&:not(.ac) .main {
|
||||||
|
/** Exclude mains in ac so that we don't hide close button */
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
&.main {
|
&.main {
|
||||||
|
|
||||||
@include transition(opacity, 0.1s, linear);
|
@include transition(opacity, 0.1s, linear);
|
||||||
/*overflow-y: hidden;*/
|
|
||||||
&.taller-than-window {
|
&.taller-than-window {
|
||||||
|
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|
||||||
|
.close-button {
|
||||||
|
|
||||||
|
opacity: 1;
|
||||||
|
|
||||||
|
/* TODO, these are style notes */
|
||||||
|
margin-top: -1px;
|
||||||
|
border-top: 1px solid $border-color;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ul.closed .close-button {
|
||||||
|
opacity: 1 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
&:hover .close-button,
|
||||||
|
.close-button.drag {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-button {
|
||||||
|
/*opacity: 0;*/
|
||||||
|
@include transition(opacity, 0.1s, linear);
|
||||||
|
border: 0;
|
||||||
|
position: absolute;
|
||||||
|
|
||||||
|
line-height: $button-height - 1;
|
||||||
|
height: $button-height;
|
||||||
|
|
||||||
|
/* TODO, these are style notes */
|
||||||
|
cursor: pointer;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #000;
|
||||||
|
&:hover {
|
||||||
|
background-color: #111;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Auto-placed GUI's */
|
/* Auto-placed GUI's */
|
||||||
@ -37,10 +87,15 @@ $row-height: 27px;
|
|||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
|
|
||||||
&.has-save {
|
&.has-save ul {
|
||||||
margin-top: $row-height;
|
margin-top: $row-height;
|
||||||
|
&.closed {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.save-row {
|
.save-row {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
@ -49,6 +104,10 @@ $row-height: 27px;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
li {
|
||||||
|
@include transition(height, 0.1s, ease-out);
|
||||||
|
}
|
||||||
|
|
||||||
/* Line items that don't contain folders. */
|
/* Line items that don't contain folders. */
|
||||||
li:not(.folder) {
|
li:not(.folder) {
|
||||||
cursor: auto;
|
cursor: auto;
|
||||||
@ -56,7 +115,6 @@ $row-height: 27px;
|
|||||||
line-height: $row-height;
|
line-height: $row-height;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: 0 4px 0 5px;
|
padding: 0 4px 0 5px;
|
||||||
@include transition(height, 0.1s, ease-out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
li.folder {
|
li.folder {
|
||||||
@ -155,13 +213,14 @@ $row-height: 27px;
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
margin-left: -9px;
|
margin-left: -9px;
|
||||||
margin-top: 23px;
|
margin-top: 23px;
|
||||||
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.c:hover .selector,
|
.c:hover .selector,
|
||||||
.selector.drag {
|
.selector.drag {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
li.save-row {
|
li.save-row {
|
||||||
@ -183,6 +242,7 @@ $row-height: 27px;
|
|||||||
line-height: 15px;
|
line-height: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO Separate style and structure */
|
/* TODO Separate style and structure */
|
||||||
|
File diff suppressed because one or more lines are too long
@ -10,7 +10,7 @@ $string-color: #1ed36f;
|
|||||||
$function-color: #e61d5f;
|
$function-color: #e61d5f;
|
||||||
$save-row-color: #dad5cb;
|
$save-row-color: #dad5cb;
|
||||||
$button-color: darken($save-row-color, 10%);
|
$button-color: darken($save-row-color, 10%);
|
||||||
|
$border-color: lighten($background-color, $border-lighten);
|
||||||
$input-color: lighten($background-color, 8.5%);
|
$input-color: lighten($background-color, 8.5%);
|
||||||
|
|
||||||
@mixin transition($prop, $time, $curve) {
|
@mixin transition($prop, $time, $curve) {
|
||||||
@ -79,7 +79,7 @@ $input-color: lighten($background-color, 8.5%);
|
|||||||
|
|
||||||
&:not(.folder) {
|
&:not(.folder) {
|
||||||
background: $background-color;
|
background: $background-color;
|
||||||
border-bottom: 1px solid lighten($background-color, $border-lighten);
|
border-bottom: 1px solid $border-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.save-row {
|
&.save-row {
|
||||||
|
@ -1034,7 +1034,8 @@
|
|||||||
|
|
||||||
var gui = new GUI();
|
var gui = new GUI();
|
||||||
|
|
||||||
while (dom.getHeight(gui.domElement) < window.innerHeight) {
|
// Add a lot of controllers. This will fail if you have some freakishly tall monitor.
|
||||||
|
for (var i = 0; i < 50; i++) {
|
||||||
gui.add({ x: 0 }, 'x');
|
gui.add({ x: 0 }, 'x');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1395,6 +1396,7 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user