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

Option to set 'Folders closed by default'

Open optimus007 opened this issue 2 years ago • 5 comments

When we initialise the gui maybe we can pass 'defaultClosed:true' or something like that to set the folder's default open or close state

i'm migrating a three js project with lots of folders being created in different files and to prevent all the folder from getting opened ,at the end of all the folder creation , I loop/traverse/foldersRecursive through the folders and do close.() on them . works great but not ideal while developing

excellent work btw !

optimus007 avatar Jun 30 '22 13:06 optimus007

Thanks! I could see us adding something like this if enough people want it. Maybe closeFolders: true? Or do you imagine that applying to the root GUI as well?

georgealways avatar Jun 30 '22 13:06 georgealways

const gui = new GUI({closeFolders: true});

the root folder & every folder created from now on is closed

and user can just do gui.open() to keep the root open if needed

optimus007 avatar Jun 30 '22 13:06 optimus007

So if it was called closeFolders I'd probably assume it only applies to "inner GUI's"—the root panel isn't typically referred to as a folder even though it technically is.

It makes me wonder which is the more common scenario: everything closed like you describe, or only folders closed. I'm thinking of the PIXI filter demo as one example, but I'll let others chime in with what they might expect a feature like this to do.

georgealways avatar Jul 05 '22 11:07 georgealways

the pixi demo portrays my problem nicely , my project is similar + there's folders inside folders and each folder is created in a different js file

if all folders created in this gui no matter how deep , are closed, it's a win.

should the root should stay open or not ? i'll leave it up to you/others

optimus007 avatar Jul 05 '22 11:07 optimus007

Cool—we could do closeFolders: true so that everything made with addFolder is closed, and the root is open by default (which you're obviously free to close() as well). Interestingly enough, that basically that makes folders behave exactly as they do in dat.gui.

georgealways avatar Jul 05 '22 11:07 georgealways

Hi, I also want this feature, close all folders by deafult. Thanks, Pavan

pavank61295 avatar Oct 21 '22 06:10 pavank61295

new GUI({ closeFolders: true }) is definitely planned for the next release.

Until then, anyone can use this snippet for the same result:

const addFolder = GUI.prototype.addFolder;
GUI.prototype.addFolder = function(...args) {
  return addFolder.call(this, ...args).close();
};

georgealways avatar Oct 23 '22 14:10 georgealways

As of version 0.18, new GUI({ closeFolders: true }) works as described above.

georgealways avatar Feb 22 '23 18:02 georgealways