Is it good practice to use UIs in multiple classes?

hello all,

so im back using oF, which im really happy about. know much more than what i did in c++ terms, so feel a lot more comfortable. but there are obviously still some things i need to learn.

but im back on a project i started ages ago when first on oF. just started again really.
but this project uses UIs [ofxGui] for a few different settings. but have put things in classes, to widen the load out. but some controls are in each class.

  1. is it wise to use a UI in one class, then make another class which has UIs in that?
    OR
  2. should i really just have one central class of controls that i should then call to the other classes that need control?

if the second option, could someone direct me to an example or a thorough description of sending UI data from one class to the other.
would mean a lot. if the first, then all is good already :wink:

thanks

A pattern I use often is to have an ofParameterGroup in an object returned from a getParams() function. Then you can have an ofxPanel in your ofApp while keeping your parameters close to the things they affect. Like this:

class Something {
    
public:
    void setup();
    ofParameterGroup getParams();
    
private:
    ofParameterGroup params;
    ofParameter<float> pA;
    ofParameter<float> pB;
    
};

void Something::setup() {
    params.setName("Something Params");
    params.add(pA.set("Param A", 1, 0, 1));
    params.add(pB.set("Param B", 2, 0, 2));
}

ofParameterGroup Something::getParams() {
    return params;
}
void ofApp::setup(){
    something.setup();
    
    panel.setup();
    panel.add(something.getParams());
}

thats great. thanks and have not used ofParameterGroup

but just to clear it for myself. with the class you put up above ‘class Something’, does that have all the UI in, then just called in ‘ofApp’?

many thanks none-the-less. will get on this as soon as i can :wink:

wait. ive read through it again (bloody dyslexia) and see that you said that you have the UI in the ofApp and really send the info ofdata between the class and the main ofApp

thanks

coolio, got it to work. after a little bit of trying different things, this way worked the best.

im actually going to make this available on my github, for others to learn from, which is commented as well. but is the most basic example i could think of. just a simple moving of a rectangle on the screen.

thanks again

here is the github location.

https://github.com/notpelsiwel/parameterSendingUI

again, thanks.
though if there is any typing errors, pleas tell. :wink: