How to change slider label? (controlP5)

image

Change to something like that:
image

1 Like

Look at the reference and source under Slider and TickMark – a Slider lets you get its number of ticks, and retrieve each TickMark object by index; a TickMark lets you add a label.

So to autolabel you can retrieve your slider, loop over its ticks, and label each one – for example, with their index value:

void tickLabeler(Slider sl){
  for(int i=0; i<sl.getNumberOfTickMarks(); i++){
     TickMark t = sl.getTickMark(i);
     t.setLabel(str(i));
  }
}

You can use that function like this:

Slider s = cp5.get(Slider.class, "mySlider");
tickLabeler(s);

17%20PM

Or, in your example, just do it manually:

Slider s = cp5.get(Slider.class, "mySlider");
s.getTickMark(0).setLabel("Slow");
s.getTickMark(1).setLabel("Medium");
s.getTickMark(2).setLabel("Fast");
1 Like

Thanks :grinning::grinning: