dataarts / dat.gui

Lightweight controller library for JavaScript.
Apache License 2.0
7.5k stars 1.09k forks source link

Removing element from gui interface #114

Closed davejack1 closed 7 years ago

davejack1 commented 8 years ago
var guiControls = new function () {
        this.data1 = true;
        this.data2 = true;
};

var datGUI = new dat.GUI

datGUI.add(guiControls, 'data1')
datGUI.add(guiControls, 'data2')

Now I want to remove data2 from the datGUI interface. How can I do that?

Sigill commented 7 years ago

You can use the remove() method, but you need to store the controller returned by add(): https://github.com/dataarts/dat.gui/blob/d5b6178e33db91b168a1264dcc5252be2d6510ef/src/dat/gui/GUI.js#L502

var guiControls = new function () {
        this.data1 = true;
        this.data2 = true;
};
var datGUI = new dat.GUI

var controller1 = datGUI.add(guiControls, 'data1');
var controller2 = datGUI.add(guiControls, 'data2');
...
datGUI.remove(controller1);
datGUI.remove(controller2);

It also allows to remove controllers from folders (but not to remove folders).

krjk333 commented 5 years ago

Similarly, I need to add data3 with the gui after clicking data2. How to do that