ofxUI + ofParameter

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?

the correct thing would be to adapt ofxUI to use ofParameter so internally it will store an ofParameter, use it’s events… but that would be a lot of work.

oooh i like this. been thinking of moving from ofxGui, because whilst its good, it has many flaws. but i guess that anything in context :wink:

thanks for the hack just means i dont have to bash my head against a wall now thinking on what to do.

ofParameter/ofParameterGroup are possibly some of my most used oF things. hopefully it will start making it into future addons, just so then everything is more linked when needed to be