ofxDropdown addListener

Hello,

I’m working with ofxDropdown to load files from a directory into a texture on the fly.

Right now I’m simply trying to use the addListerner function, but I don’t think I’m following how to accomplish this/use it properly.

void ofApp::setupGui(){
        gui.setup("DROPDOWNS", "DropdownsSettings.xml");
        gui.setPosition(20,20);
        
        strDropdown =  make_unique<ofxDropdown>("");
        gui.add(strDropdown->getDropdownParameters());

        strDropdown->addListener(this, &ofApp::togglePressed);
        options.setName("STR Options");

        ofSetWindowPosition(0, 0);
    
        //get specs
        //some path, may be absolute or relative to bin/data
        string path = "specs";
    
        ofDirectory dir(path);
        //only show png files
        dir.allowExt("png");
        //populate the directory object
        dir.listDir();

    //go through and print out all the paths
    for(int i = 0; i < dir.size(); i++){
        ofLogNotice(dir.getPath(i));
                strDropdown->add(dir.getPath(i));
        }
    
    
        gui.add(strDropdown.get());
}

My togglePressed function looks like this:

void ofApp::togglePressed(bool & newValue){
    cout << strDropdown->getParameter().toString() << endl;
}

Essentially all I want to do is click on something in the dropdown and have it call another function that will load in my texture referenced somewhere else.

Right now I’m getting this error:

/Users/jo/nomadic/programming/openframeworks/of_v0.11.0_osx_release/libs/openFrameworks/events/ofEvent.h:535:14: No matching member function for call to 'make_function'

Any direction/example on how to add listeners to ofxDropdown would be greatly appreciated! If there is a more straightforward way to use ofxDropdown or another GUI element as a simple file select drop down element, please let me know.

cc @roymacdonald

Hey, let me check.

the problem is are the arguments of the callback.
it should be

void ofApp::togglePressed(string & newValue){
1 Like

Great, thank you!