mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
Add property to specify if open/close button shows on top or bottom of the menu
Adds the 'closeOnTop' property to the GUI constructor params to specify if open/close button shows on top or bottom of the menu (bottom by default)
This commit is contained in:
parent
d5b6178e33
commit
9540dd1c2f
@ -75,6 +75,7 @@ const hideableGuis = [];
|
|||||||
* @param {Boolean} [params.auto=true]
|
* @param {Boolean} [params.auto=true]
|
||||||
* @param {dat.gui.GUI} [params.parent] The GUI I'm nested in.
|
* @param {dat.gui.GUI} [params.parent] The GUI I'm nested in.
|
||||||
* @param {Boolean} [params.closed] If true, starts closed
|
* @param {Boolean} [params.closed] If true, starts closed
|
||||||
|
* @param {Boolean} [params.closeOnTop] If true, close/open button shows on top of the GUI
|
||||||
*/
|
*/
|
||||||
const GUI = function(pars) {
|
const GUI = function(pars) {
|
||||||
const _this = this;
|
const _this = this;
|
||||||
@ -129,6 +130,7 @@ const GUI = function(pars) {
|
|||||||
|
|
||||||
// Default parameters
|
// Default parameters
|
||||||
params = common.defaults(params, {
|
params = common.defaults(params, {
|
||||||
|
closeOnTop: false,
|
||||||
autoPlace: true,
|
autoPlace: true,
|
||||||
width: GUI.DEFAULT_WIDTH
|
width: GUI.DEFAULT_WIDTH
|
||||||
});
|
});
|
||||||
@ -196,6 +198,16 @@ const GUI = function(pars) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles <code>GUI</code>'s position of open/close button
|
||||||
|
* @type Boolean
|
||||||
|
*/
|
||||||
|
closeOnTop: {
|
||||||
|
get: function() {
|
||||||
|
return params.closeOnTop;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The identifier for a set of saved values
|
* The identifier for a set of saved values
|
||||||
* @type String
|
* @type String
|
||||||
@ -335,7 +347,13 @@ const GUI = function(pars) {
|
|||||||
this.__closeButton = document.createElement('div');
|
this.__closeButton = document.createElement('div');
|
||||||
this.__closeButton.innerHTML = GUI.TEXT_CLOSED;
|
this.__closeButton.innerHTML = GUI.TEXT_CLOSED;
|
||||||
dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BUTTON);
|
dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BUTTON);
|
||||||
this.domElement.appendChild(this.__closeButton);
|
if (params.closeOnTop) {
|
||||||
|
dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_TOP);
|
||||||
|
this.domElement.insertBefore(this.__closeButton, this.domElement.childNodes[0]);
|
||||||
|
} else {
|
||||||
|
dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BOTTOM);
|
||||||
|
this.domElement.appendChild(this.__closeButton);
|
||||||
|
}
|
||||||
|
|
||||||
dom.bind(this.__closeButton, 'click', function() {
|
dom.bind(this.__closeButton, 'click', function() {
|
||||||
_this.closed = !_this.closed;
|
_this.closed = !_this.closed;
|
||||||
@ -441,6 +459,8 @@ 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_CLOSE_BUTTON = 'close-button';
|
||||||
|
GUI.CLASS_CLOSE_TOP = 'close-top';
|
||||||
|
GUI.CLASS_CLOSE_BOTTOM = 'close-bottom';
|
||||||
GUI.CLASS_DRAG = 'drag';
|
GUI.CLASS_DRAG = 'drag';
|
||||||
|
|
||||||
GUI.DEFAULT_WIDTH = 245;
|
GUI.DEFAULT_WIDTH = 245;
|
||||||
|
@ -62,7 +62,6 @@ $button-height: 20px;
|
|||||||
/*opacity: 0;*/
|
/*opacity: 0;*/
|
||||||
@include transition(opacity, 0.1s, linear);
|
@include transition(opacity, 0.1s, linear);
|
||||||
border: 0;
|
border: 0;
|
||||||
position: absolute;
|
|
||||||
|
|
||||||
line-height: $button-height - 1;
|
line-height: $button-height - 1;
|
||||||
height: $button-height;
|
height: $button-height;
|
||||||
@ -71,6 +70,12 @@ $button-height: 20px;
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
background-color: #000;
|
background-color: #000;
|
||||||
|
&.close-top {
|
||||||
|
position:relative;
|
||||||
|
}
|
||||||
|
&.close-bottom {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #111;
|
background-color: #111;
|
||||||
}
|
}
|
||||||
|
@ -1051,11 +1051,23 @@ console.log(c2.__checkbox.getAttribute('checked'));
|
|||||||
|
|
||||||
gui.destroy();
|
gui.destroy();
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('close/open button position', function() {
|
||||||
|
|
||||||
|
var gui = new GUI({closeOnTop:true});
|
||||||
|
var gui2 = new GUI({closeOnTop:false});
|
||||||
|
var gui3 = new GUI();
|
||||||
|
|
||||||
|
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($(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();
|
||||||
|
gui2.destroy();
|
||||||
|
gui3.destroy();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
test('Folders', function() {
|
test('Folders', function() {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user