Slider UI that allows "snapping" to an increment value

I’m trying to create a slider that allows a float range, say from 1 to 2 but in increments of 0.1. I’m currently using ofxGui and have looked at ofxUI but they don’t seem to have this functionality.

Does anyone know if this is possible with either of these libs or any other out there?

ofxUI lets you set an increment value for sliders, but only uses that lookup with keyboard input. All the guis I’ve used either use floats without increments or integers.

I think your best bet would be to round the input value yourself like so:

float nearest = floorf(value * 10.0 + 0.5) / 10.0f;

(where ‘value’ is your slider val)
This will round your values to the nearest tenth (e.g. 1.1987 becomes 1.2)

Thanks, @robotconscience, that is very similar to what I’m doing right now. Pretty much listening for the “end” event on the widget, quantizing using an algorithm very similar to yours and setting the quantized value back into the slider so that it shows the same value.

I guess I was hoping that some lib already had this built-in but this will do for now.