I was having some trouble binding ofParameter references to ofxUI widgets – I was able to fix it in a hacky way.
For example, say I have an ofParameter<float>
variable which I want to bind to a slider. ofParameter’s get()
function returns a reference to the value, so it compiles, but the variable does not change when I adjust the slider.
ofParameter<float> var;
ofxUICanvas *gui = new ofxUICanvas("gui");
gui->addSlider("slider", 0.0, 1.0, var.get());
I suspect the problem was that reference was a constant, so I got around this by making a getRef()
method in ofParameter which is the same as get() except not const.
const ParameterType & get() const;
ParameterType & getRef(); // added
template<typename ParameterType>
inline ParameterType & ofParameter<ParameterType>::getRef() {
return obj->value;
}
The slider now works properly, but I am wondering if there is a better way to do this using whats already in the ofParameter class?