Merge branch 'Sigill-removefolder'

This commit is contained in:
Don McCurdy 2017-12-23 12:00:12 -05:00
commit 269fda085f
2 changed files with 56 additions and 19 deletions

View File

@ -628,6 +628,29 @@ common.extend(
return gui; return gui;
}, },
/**
* Removes a subfolder GUI instance.
* {dat.gui.GUI} folder The folder to remove.
* @instance
*/
removeFolder: function(folder) {
this.__ul.removeChild(folder.domElement.parentElement);
delete this.__folders[folder.name];
// Do we have saved appearance data for this folder?
if (this.load && // Anything loaded?
this.load.folders && // Was my parent a dead-end?
this.load.folders[folder.name]) {
delete this.load.folders[folder.name];
}
const _this = this;
common.defer(function() {
_this.onResize();
});
},
/** /**
* Opens the GUI. * Opens the GUI.
*/ */

View File

@ -6,7 +6,7 @@
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen"/> <link rel="stylesheet" href="qunit.css" type="text/css" media="screen"/>
<script type="text/javascript" src="qunit.js"></script> <script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="../build/dat.gui.js"></script> <script type="text/javascript" src="../build/dat.gui.js"></script>
<script type="text/javascript"> <script type="text/javascript">
@ -421,7 +421,7 @@
}); });
function match(a, b, msg) { function match(a, b, msg) {
for (var i in b) { for (var i in b) {
if (b[i] !== b[i]) { if (b[i] !== b[i]) {
ok(a[i] !== a[i], msg) ok(a[i] !== a[i], msg)
@ -429,15 +429,15 @@
equal(b[i], a[i], msg); equal(b[i], a[i], msg);
} }
} }
} }
function equalish(a, b, tolerance, label) { function equalish(a, b, tolerance, label) {
return ok(Math.abs(a - b) < tolerance, label); return ok(Math.abs(a - b) < tolerance, label);
} }
function initObject() { function initObject() {
return { return {
@ -494,9 +494,9 @@
equal(c1.__checkbox.checked, equal(c1.__checkbox.checked,
object.booleanProperty); object.booleanProperty);
console.log(c2.__checkbox.getAttribute('checked')); console.log(c2.__checkbox.getAttribute('checked'));
equal(c2.__checkbox.getAttribute('checked') === 'checked', equal(c2.__checkbox.getAttribute('checked') === 'checked',
object.anotherBooleanProperty); object.anotherBooleanProperty);
@ -518,7 +518,7 @@ console.log(c2.__checkbox.getAttribute('checked'));
dom.fakeEvent(c1.__checkbox, 'click'); dom.fakeEvent(c1.__checkbox, 'click');
equal(true, object.booleanProperty, 'changes back'); equal(true, object.booleanProperty, 'changes back');
equal(true, c1.__checkbox.checked, 'checkbox valid'); equal(true, c1.__checkbox.checked, 'checkbox valid');
@ -756,7 +756,7 @@ console.log(c2.__checkbox.getAttribute('checked'));
module("NumberControllerSlider"); module("NumberControllerSlider");
test("Acknowledges original value", function() { test("Acknowledges original value", function() {
var object = initObject(); var object = initObject();
var min = 0, max = 50; var min = 0, max = 50;
@ -813,7 +813,7 @@ console.log(c2.__checkbox.getAttribute('checked'));
dom.fakeEvent(window, 'mouseup'); dom.fakeEvent(window, 'mouseup');
dom.fakeEvent(window, 'mousemove', { dom.fakeEvent(window, 'mousemove', {
x: o.left+w, x: o.left+w,
y: o.top y: o.top
@ -902,7 +902,7 @@ console.log(c2.__checkbox.getAttribute('checked'));
c4.onChange(function() { c4.onChange(function() {
c4_changed = true; c4_changed = true;
}); });
c5.onChange(function() { c5.onChange(function() {
c5_changed = true; c5_changed = true;
}); });
@ -1006,7 +1006,7 @@ console.log(c2.__checkbox.getAttribute('checked'));
return ok(Math.abs(a - b) < tolerance, label); return ok(Math.abs(a - b) < tolerance, label);
} }
module('GUI Appearance'); module('GUI Appearance');
@ -1052,7 +1052,7 @@ console.log(c2.__checkbox.getAttribute('checked'));
gui.destroy(); gui.destroy();
}, 0); }, 0);
}); });
test('close/open button position', function() { test('close/open button position', function() {
var gui = new GUI({closeOnTop:true}); var gui = new GUI({closeOnTop:true});
@ -1062,12 +1062,12 @@ console.log(c2.__checkbox.getAttribute('checked'));
ok($(gui.domElement).find('ul').prev().hasClass(GUI.CLASS_CLOSE_BUTTON) && $(gui.domElement).find('ul').prev().hasClass(GUI.CLASS_CLOSE_TOP), 'GUI has close/open button on top'); ok($(gui.domElement).find('ul').prev().hasClass(GUI.CLASS_CLOSE_BUTTON) && $(gui.domElement).find('ul').prev().hasClass(GUI.CLASS_CLOSE_TOP), 'GUI has close/open button on top');
ok($(gui2.domElement).find('ul').next().hasClass(GUI.CLASS_CLOSE_BUTTON) && $(gui2.domElement).find('ul').next().hasClass(GUI.CLASS_CLOSE_BOTTOM), 'GUI has close/open button on bottom'); ok($(gui2.domElement).find('ul').next().hasClass(GUI.CLASS_CLOSE_BUTTON) && $(gui2.domElement).find('ul').next().hasClass(GUI.CLASS_CLOSE_BOTTOM), 'GUI has close/open button on bottom');
ok($(gui3.domElement).find('ul').next().hasClass(GUI.CLASS_CLOSE_BUTTON) && $(gui3.domElement).find('ul').next().hasClass(GUI.CLASS_CLOSE_BOTTOM), 'GUI has close/open button on bottom by default'); ok($(gui3.domElement).find('ul').next().hasClass(GUI.CLASS_CLOSE_BUTTON) && $(gui3.domElement).find('ul').next().hasClass(GUI.CLASS_CLOSE_BOTTOM), 'GUI has close/open button on bottom by default');
gui.destroy(); gui.destroy();
gui2.destroy(); gui2.destroy();
gui3.destroy(); gui3.destroy();
}); });
test('Folders', function() { test('Folders', function() {
@ -1187,6 +1187,20 @@ console.log(c2.__checkbox.getAttribute('checked'));
}); });
test('removeFolder', function() {
var gui = new GUI();
var f = gui.addFolder('Temporary folder');
ok($.contains(gui.domElement, f.domElement), "Now you see it");
gui.removeFolder(f);
ok(!$.contains(gui.domElement, f.domElement), "Now you don't.");
gui.destroy();
});
test('min, max & step', function() { test('min, max & step', function() {
@ -1417,11 +1431,11 @@ console.log(c2.__checkbox.getAttribute('checked'));
equal($(gui.__preset_select).children('option:selected')[0].value, gui.preset, "Dropdown display matches preset value"); equal($(gui.__preset_select).children('option:selected')[0].value, gui.preset, "Dropdown display matches preset value");
} }
}); });
</script> </script>
</head> </head>
<body> <body>
<h1 id="qunit-header"></h1> <h1 id="qunit-header"></h1>
@ -1433,4 +1447,4 @@ console.log(c2.__checkbox.getAttribute('checked'));
<ol id="qunit-tests"></ol> <ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div> <div id="qunit-fixture">test markup, will be hidden</div>
</body> </body>
</html> </html>