ofxGui over multiple classes

Hey guys, I’m having a lot of trouble with learning ofxGui.

I have a Gui class of which i made one public instance in my ofApp.
Also i have a class that i use to draw things with, of which i also have one instance in my ofApp.
Now if i want to add parameters i have in my drawing class to my gui, what is the best way to do this?

i thought maybe i could give my drawing class a pointer of my gui class and then communicate from my drawing class to the gui class, but i feel like there must be a better way to do this.
I also looked into the ofGetAppPtr() fucntion, to acces my my gui like this

ofGetAppPtr()->myGui.add(someParameter)

but i couldn’t find my gui like this.
Any help is appreciated,
Thank you!

i usually have something like:

class Drawing{
public:
    ofParameter<float> position{"position", 0, 0, 100};
    ofParameter<ofColor> color{"color", ofColor::white};
    ofParameterGroup{
        "drawing parameters",
        position,
        color,
    }
}

class ofApp{
public:
    ofxPanel gui;
    Drawing drawing;
}

// ofApp.cpp

void ofApp::setup(){
   gui.setup("parameters", 10, 10);
   gui.add(drawing.parameters);
}

if you want to have the gui in a separate class you can just have an add method in the gui class that will add an ofParameterGroup or even an ofAbstractParameter (so it works with any parameter) to the gui.

The way i’m initializing the parameters here allows you to initialize them in the header without having to do it in the cpp but you can also do it in a setup method or the constructor of the class if you prefer

3 Likes