Scroll through a list of strings in ofxGui?


#1

Currently, I’ve been using an ofxIntSlider to select the index of the object in the vector of objects, but this is obviously unintuitive since I don’t know what the object is called.

I have an ofxLabel below the slider that populates with the string name of the object every time the slider is adjusted - however, instead, I’d like to use a gui slider to select an object in a vector of objects, and i’d like to see the string ‘name’ of the object in the slider.

How can I do this? Thanks in advance!!


#2

Hi,
You can edit the ofxSlider.cpp, or copy it and create a new class like ofxCustomSlider.
In the .h file I put
bool bDisplayValue = false;
In the .cpp file I modified the generateText() function

if(bDisplayValue)
        textMesh.append(getTextMesh(valStr, b.x + b.width - textPadding - getTextBoundingBox(valStr,0,0).width, b.y + b.height / 2 + 4));

I now see things are different in OF 0.10.0, I’m talking about 0.9.8 here :slight_smile:
(In 0.10.0 you can comment this in the function (edit: now I see it’s almost the same…)

// textMesh.append(getTextMesh(valStr, b.x + b.width - textPadding - getTextBoundingBox(valStr,0,0).width, b.y + b.height / 2 + 4));

To set the right object name in the slider:
Add a listener to the slider (see guiExample), let that set the name of the slider, based on its value, like:
myIntSlider.getParameter().setName(objects[value]->name);
I think this might work? Good luck


#3

This works great; thanks!! :hugs: