ofxDatGui remove items from folder

When using ofxDatGui, I understand how to add items to a folder as follows:

    f1 = new ofxDatGuiFolder("folder 1", ofColor::fromHex(0xFFD00B));
    f1->addToggle("toggle1”);
    f1->addToggle("toggle2");
    f1->addBreak();

etc…
But, if I want to remove items from the folder, i.e. a dynamic update of what toggles are available, how would I do this?

S

Hi,
I don’t see an actual remove function, but you can hide the elements:
f1->getComponent(ofxDatGuiType::TOGGLE, "toggle1")->setVisible(false);

Yes I know about hiding, but I want to create varying numbers of toggles, named differently, based on the contents of a file that I’m opening.

So hiding probably is no good, destroying and adding new would be better…

I understand.
Since I haven’t discovered a remove function in the add-on I think it’s easiest for now to delete the current folder and thereby removing all items, and recreate everything (using the same pointer) based upon the opened file?
It may be a valid workaround.

Ah yes, perhaps just redeclaring the folder will do the trick, I hadn’t thought of that… presumably doing so will trigger any destructors. I’ll try now!

Hmmm, nope, this has issues when I am adding the folder to an overall GUI (called drawMenu)

    solidWalls = drawMenu->addFolder("toggle folder 1");
    solidWalls->addToggle("toggle");
    solidWalls->collapse();

    solidWalls = drawMenu->addFolder("toggle folder 2");
    solidWalls->addToggle("toggle2");
    solidWalls->collapse();

Doesn’t quite work… we end up with two toggles rather than one
also, because the ‘addFolder’ call works on the GUI layout overall, adding the line:

    delete drawMenu->getFolder("toggle folder 1");

just results in a gap where toggle folder 1 was, and toggle folder 2 becomes unresponsive to the mouse… hummmmm, I’m stuck.

Hi,
However not so elegant: you can use the same workaround, by regenerating the whole GUI.
addFolder (or whatever add-function) calls attachItem(), which pushes the object to a vector called items.
It’s possible to write a remove(-Folder) function that removes the items from the vector, but it takes some time to dig into the add-on I think.
So I would go for deleting the whole GUI, and then to recreating it.
Without attaching the folder with addFolder, you can see it works:

void ofApp::update(){
    if(ofGetFrameNum() % 60 == 0){
        delete f1;
        f1 = new ofxDatGuiFolder("folder 1", ofColor::fromHex(0xFFD00B));
        for(int i=0; i<int(ofGetFrameNum()/60); i++){
            f1->addToggle("toggle");
        }
        f1->setPosition(0, 0);
        f1->expand();
    }
    f1->update();
    f2->update();
}

Hey, yeah I reached pretty much the same conclusion, had a dig around in the add on functions and didn’t like the idea of trying to write a remove function, so ended up deleting and re-adding the GUI. Not brilliant but it works.

Thanks,
S

1 Like