ofxGui Sliders and buttons

I have two subjects here:

The first is how do you set object positions with the ofxGui.

Like a slider or button for example, adding them to a panel is easy enough but the position on the panel I cannot figure out.

Also, can sliders and buttons be associated with arrays, I remember this in VB a scrollbar could be scrollbar(x).value = somevalue

I asked because i want to have 24 sliders that I can read and set easily in a loop.

Thanks

Hey @cogsandwheels , thanks for starting a thread in the forum!

Hey how about using the ofParameter class? ofParameter is templated, so there can be different types of them. If all 24 sliders are the same type, they can be stored in a std::vector<ofParameter<T>>. ofParameters of the same and/or different types can be added to an ofParameterGroup. The individual parameters or the entire group can be added to an ofxPanel. Each ofParameterGroup will have its own “section” in an ofxPanel, and each ofParameter will have its own slider (or related gui control) whether it’s in a group or not.

The ofParameter class is fantastic because each parameter can have a unique name, its own min and max values, and it can often be used just like a variable. Some types require the .get() and .set() functions though. And the groups are kinda nice because the class has a set of functions for dealing with its parameters.

There are some examples of using these classes in the /examples/gui/ folder. But essentially something like the following might work well.

// in ofApp.h
    ofxPanel panel;
    ofParameterGroup group;
    std::vector<ofParameter<float>> params;

// in ofApp::setup()
    params.resize(24);
    for(size_t i{0}; i < params.size(); ++i){
        params.at(i).set(ofToString(i), ofRandom(0.f, i), 0.f, i);
        group.add(params.at(i));
    }
    panel.setup();
    panel.add(group);

The order in which you add an ofParameter to an ofxPanel or an ofParameterGroup is one way to determine the order in which their sliders appear in the ofxPanel. There might be other ways though.