ofxGui add listener to vec3f

Is there a way to add listener to a vec3fSlider?

in my .h file I have

ofxVec3Slider camPositionGui;

and in my .cpp

gui.add(camPositionGui.setup("Position vec3", camPosition, ofVec3f(-1000, -1000, -1000), ofVec3f(1000,1000,1000)));

but I cannot use this function

camPositionGui.addListener(this, &ofApp::camPositionGuiChanged);

It has not been implemented, but I wonder if there is a reason why? I can of course use single sliders but the vec3f slider is quick and neat for this kind of thing.

Fred

Hello,

Have you tried ofParameter instead of ofxVec3Slider ?

Not yet, will do, but any idea why it is not extended to the other types of sliders?

I have never used ofxVec3Slider or other sliders. I always use ofParameter.
I know addListener() is part of ofParameter class so available for any type ofParameter handles.
I can’t tell for types when used outside the ofParameter class.

Hi, you can´t use the addListener function with the ofxVecSlider because it is not a slider, rather a group of sliders.
you can do the following to add a listener to the ofxVecSlider

yourOfxVec3Slider.getParameter().cast<ofVec3f>().addListener(this, &ofApp::yourCallBackFunc);

Its a bit long and ugly. I rather use the of parameter directly. Simply by adding an ofParameter to your gui it will create a slider.
Then add a listener to the ofParameter. It’s cleaner and simpler

ofParameter<ofVec3f> v3Param;

ofxPanel gui;

gui.add(v3Param.set("my vec3 param", ofVec3f(1),ofVec3f(0),ofVec3f(1) ); // this will create a slider group for your vec3 in the gui.

v3Param.addListener(this, &ofApp::yourCallBackFunc);

Hope it helps. best

the problem is probably that the signature of the listener function is not correct. it needs to be:

void listenerFunction(ofVec3f & value)

specially note the & that indicates that the value is passed by reference instead of making a copy. in general in OF when adding a listener to any event you need to use a function that receives a reference to the type of the event or parameter

Ok, thanks everyone, I will switch to ofParameter, it seems it is more flexible than the slider classes. I had made a habit out of using the sliders but no more.