Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to disable folders #106

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion examples/kitchen-sink/kitchen-sink.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function getDepth( g ) {
return depth;
}

make( { title: 'Disable' }, gui => {
make( { title: 'Disable Controllers' }, gui => {

gui.add( { Number: 0 }, 'Number' ).disable().enable();
gui.add( { Number: 0 }, 'Number' ).disable();
Expand All @@ -199,6 +199,15 @@ make( { title: 'Disable' }, gui => {
gui.addColor( { Color: 0xaa00ff }, 'Color' ).disable().enable();
gui.addColor( { Color: 0xaa00ff }, 'Color' ).disable();

const folder = gui.addFolder( 'Disable Folders' );
folder.add( { Number: 0 }, 'Number' );
folder.disable();

} );

make( { title: 'Disable Root' }, gui => {
gui.add( { Number: 0 }, 'Number' );
gui.disable();
} );

make( { title: 'Listen' }, gui => {
Expand Down
21 changes: 4 additions & 17 deletions src/Controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @module Controller */

import { disableItem, showItem } from './utils/itemUtils';

/**
* Base class for all controllers.
*/
Expand Down Expand Up @@ -227,16 +229,7 @@ export default class Controller {
* controller.disable( !controller._disabled ); // toggle
*/
disable( disabled = true ) {

if ( disabled === this._disabled ) return this;

this._disabled = disabled;

this.domElement.classList.toggle( 'disabled', disabled );
this.$disable.toggleAttribute( 'disabled', disabled );

return this;

return disableItem( this, disabled );
}

/**
Expand All @@ -249,13 +242,7 @@ export default class Controller {
* controller.show( controller._hidden ); // toggle
*/
show( show = true ) {

this._hidden = !show;

this.domElement.style.display = this._hidden ? 'none' : '';

return this;

return showItem( this, show );
}

/**
Expand Down
43 changes: 36 additions & 7 deletions src/GUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import StringController from './StringController';

import stylesheet from 'stylesheet';
import _injectStyles from './utils/injectStyles';
import { disableItem, showItem } from './utils/itemUtils';

let stylesInjected = false;

Expand Down Expand Up @@ -90,6 +91,12 @@ export default class GUI {
*/
this.folders = [];

/**
* Used to determine if the GUI is disabled. * Use `gui.disable( true|false )` to modify this value.
* @type {boolean}
*/
this._disabled = false;

/**
* Used to determine if the GUI is closed. Use `gui.open()` or `gui.close()` to change this.
* @type {boolean}
Expand Down Expand Up @@ -394,6 +401,34 @@ export default class GUI {

}

/**
* Enables this GUI.
* @param {boolean} enabled
* @returns {this}
* @example
* gui.enable();
* gui.enable( false ); // disable
* gui.enable( gui._disabled ); // toggle
*/
enable( enabled = true ) {
return this.disable( !enabled );
}

/**
* Disables this GUI.
* @param {boolean} disabled
* @returns {this}
* @example
* gui.disable();
* gui.disable( false ); // enable
* gui.disable( !gui._disabled ); // toggle
*/
disable( disabled = true ) {
if ( disabled ) this.close();

return disableItem( this, disabled );
}

/**
* Closes the GUI.
* @returns {this}
Expand All @@ -418,13 +453,7 @@ export default class GUI {
* gui.show( gui._hidden ); // toggle
*/
show( show = true ) {

this._hidden = !show;

this.domElement.style.display = this._hidden ? 'none' : '';

return this;

return showItem( this, show );
}

/**
Expand Down
18 changes: 18 additions & 0 deletions src/utils/itemUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function disableItem( item, disabled ) {
if ( disabled === item._disabled ) return item;

item._disabled = disabled;

item.domElement.classList.toggle( 'disabled', disabled );
item.domElement.toggleAttribute( 'disabled', disabled );

return item;
}

export function showItem( item, show ) {
item._hidden = !show;

item.domElement.style.display = item._hidden ? 'none' : '';

return item;
}
4 changes: 4 additions & 0 deletions style/base.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import 'shared';

@mixin touch-vars {

@media (pointer: coarse) {
Expand Down Expand Up @@ -62,6 +64,8 @@
}
}

@include can-disable;

// "Theme" properties
// -------------------------------------------------------------------------

Expand Down
9 changes: 2 additions & 7 deletions style/controllers.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'hover';
@import 'shared';

.lil-gui {
.controller {
Expand All @@ -7,12 +7,7 @@
padding: 0 var(--padding);
margin: var(--spacing) 0;

&.disabled {
opacity: 0.5;
&, & * {
pointer-events: none !important;
}
}
@include can-disable;

// > is used here to avoid styling FunctionController's .name,
// which gets put inside of its widget.
Expand Down
2 changes: 1 addition & 1 deletion style/hierarchy.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'hover';
@import 'shared';

.lil-gui {
.title {
Expand Down
2 changes: 1 addition & 1 deletion style/inputs.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'hover';
@import 'shared';

.lil-gui {
input {
Expand Down
9 changes: 9 additions & 0 deletions style/hover.scss → style/shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@
}
}
}

@mixin can-disable {
&.disabled {
opacity: 0.5;
&, & * {
pointer-events: none !important;
}
}
}