How to use ofxSlider value in code

so I’m in one of my first programs and solving problems 1 by 1. I am currently struggling with the ofxGui component.

I managed to add a slider onscreen and I want to use it to ultimately print different messages somewhere else. This is my setup:

squareModeSlider.setup(“mode”, squareMode, 0, 3, 80, 12 );

I can get it on screen with the draw function, looks like it’s doing exactly what I need to. However, when I reference the variable squareMode in my code (to draw the value on screen for instance) it doesn’t seem to change.

if (squareMode == 1){
        font.drawString("it is 1", 200, 342);
}
else {
     font.drawString("it is not 1", 200, 342);
}

I’ve seen some examples of the ofxGUI component with listeners, but I’m a bit puzzled if that is needed (and when it is not). I’m used to Arduino coding and am perhaps missing something obvious that I missed here?

it’s easier to use an ofParameter and add into ofxPanel.
You can check this example (with callbacks handling too):

openFrameworks\examples\gui\guiFromParametersExample

//ofApp.h
#include "ofxGui.h"
ofxPanel gui;
ofParameter<int> circleResolution;

//ofApp.cpp
gui.setup("panel"); // most of the time you don't need a name but don't forget to call setup
gui.add(circleResolution.set("circleRes", 5, 3, 90));
...

I’ve added a ‘single’ toggle via ofxToggle and I can read that boolean value fine in my code. I tried the panel, and it works. However, I am planning to add multiple sliders and toggles at various places on screen (sort of like a setup menu). The panel doesn’t work so well for that, and I would also need it to be static, I couldn’t find any reference to making it locked (by default you can move the panel across the screen apparently).

If I am not wrong, using odfxGui, you can’t put “isolated” widgets on the canvas out of a panel container…

If you want a more customizable (layout) gui lib you need to look for other addons:
https://ofxaddons.com/
https://addons.braitsch.io/

I would go with:


very interesting, will have a look!