home/ atoms/ of-gui-float-slider

An ofxFloatSlider added to an ofxPanel binds a live variable to a draggable GUI control

The ofxGui addon provides an immediate-mode GUI. You generate the project with ofxGui, declare an ofxPanel (the gui container) and an ofxFloatSlider, then in setup() add the slider with gui.add(radius.setup(“radius”, 140, 10, 300)) — arguments are label, initial value, min, and max. Call gui.draw() in draw() to render the panel. The slider’s current value is read directly by using the slider object as its value type (e.g. passing radius into ofDrawCircle), so dragging it live-controls the linked variable.

Examples

// ofApp.h: ofxPanel gui; ofxFloatSlider radius; // setup(): gui.add(radius.setup(“radius”, 140, 10, 300)); // draw(): gui.draw(); ofDrawCircle(ofGetWidth()/2, ofGetHeight()/2, radius);

Assessment

Add a float slider labelled “speed” ranging 0–5 defaulting to 1, draw the panel, and use its value to move a shape. Which addon and which two classes are required?

“You simply generate a project with the GUI add on, initialize an ofxFloatSlider and gui, draw the gui, and link the slider to a specific variable.”