Dynamically adding / removing ofxGui controls?

Currently, I’ve built a system where (1) I have a bunch of UI controls (such as shape size, shape orientation, shape colour, shape on-screen quantity, shape location xy, etc.), and (2) i have a slider that changes the shapes I’m generating from circles to squares to cubes to cylinders to any shape i want.

However, instead, I want to have the UI controls themselves also change according to the shape I’ve selected to draw. Ex: if i select circles, i want to be able to control their radii, and whether they are oval; if i select cubes i want to control the colour on each face of the cube.

To do this, I’d need to have UI controls dynamically appear and disappear (or load and unload) whenever i select a shape - where the controls are specifically meant to control the shape and each shape’s unique properties.

(How) is this possible?

(i’m trying to create basically a graphical “plug-in” system like in photoshop or ableton/VST).

(thank you! :slight_smile: )

Hi,
You can use multiple instances of ofxPanel, like circleGui and rectangleGui.
Each gui can have it’s own sliders / buttons, but give each panel an option to select the (other) gui to use (with buttons?).
So if you press circleButton, the button calls a function (see guiExample for addListener()) that set’s a char for example, which you can use in ofApp::draw();

switch(guiState){
    case 0:
        circleGui.draw();
        break;
    case 1:
        rectangleGui.draw();
        break;
}

Now I review this: it isn’t really dynamic, but it’s a way to do it? :sweat_smile:

Hi @lethalrush on the github master there is ofxGui support for removing anything you add to it (I added it), although I just noticed that it is missing a function for doing such!!

Maybe it might be better and easier to use ofxImGui, which is an immediate mode drawing gui, which is intrinsically dynamic, and it should be quite straight forwards to do what you want to

1 Like

You can use two ofParameterGroup’s added to the ofxGui panel. Then you can
minimize/maximize one group of the panel by code.
Something like gui.getGroup(“rectGroup”).minimize()