lil-gui
lil-gui copied to clipboard
Feature Request: Auto close all folders
Would it be possible to add a function so that when you click on a folder all other folders in the Gui close automatically?
Just an idea for larger GUi's.
I'm not sure this is common enough to be part of the core library. For now you could override GUI.prototype.open() to close "sibling" folders. I could see the folders broadcasting open and close events at some point in the future, if there's enough need.
Thanks for the reply and I will look at the GUI.prototype.open
Following the prototype idea, however, I could not get it to work. My code is like:
GUI.prototype.open = function ( open = true ) { this._closed = !open; this.$title.setAttribute( 'aria-expanded', !this._closed ); this.domElement.classList.toggle( 'closed', this._closed ); if ( open ) this.parent.children .filter( f => f != this ) .forEach( f=> f.close() ); return this; };
Any ideas?
Yes, that's bad advice I'm giving above. Most likely this isn't working because we're actually calling the openAnimated
method when you open a folder via click. open
is for programmatic use.
For now, you could try putting your logic in the setter function of the example here: https://github.com/georgealways/lil-gui/issues/67#issuecomment-1179745352 — that's a way of observing any change to _closed
regardless of what method triggered it.
There will be a better mechanism for listening to folder open and close events in an upcoming release.
Thanks for the replay, but I did not immediately see how I can use the sample code to achieve the effect, as illustrated here: http://cbfranca.github.io/vertical-responsive-menu/demos/demo.html#
Hi there, I just published version 0.18 which has a new method called gui.onOpenClose. You can use that to listen for folder open/close events and then close sibling folders in the callback.
That's perfect, thank you !