lil-gui icon indicating copy to clipboard operation
lil-gui copied to clipboard

Feature Request: Auto close all folders

Open Pickleheaded opened this issue 2 years ago • 2 comments

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.

Pickleheaded avatar May 25 '22 12:05 Pickleheaded

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.

georgealways avatar May 25 '22 16:05 georgealways

Thanks for the reply and I will look at the GUI.prototype.open

Pickleheaded avatar May 26 '22 23:05 Pickleheaded

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?

branaway avatar Jan 02 '23 18:01 branaway

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.

georgealways avatar Jan 02 '23 21:01 georgealways

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#

branaway avatar Jan 03 '23 04:01 branaway

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.

georgealways avatar Feb 11 '23 14:02 georgealways

That's perfect, thank you !

Pickleheaded avatar Feb 11 '23 17:02 Pickleheaded