Customizing Slider sensitivity

I always find Slider to be one of the hardest things to work with in Juce, even though it should be one of the easiest…

I’m trying to create a slider that can scroll smoothly along integer values, but without arbitrary limits, just like the number box in PD:


LinearVertical mode seems similar to this, so I’ve been trying that. But when I set the limits high, it races to the top when you drag it. So I tried using setMouseDragSensitivity() to lower the sensitivity, but it has no effect.

Of course it would be easy enough to create my own Component that acts like this, but I want to make sure that I’m not missing something from the Slider class before I do that.

setMouseDragSensitivity sets the distance in pixels for a full drag across the whole slider’s range, so it has to be proportional to the range for a consistent behaviour. Say you want 5 pixels for each integer value. Then for a 0-100 slider you need a sensitivity of 500; for 0-50, a sensitivity of 250. This only works directly for sliders whose representation does not correspond to its range: the rotaries and IncDecButtons. If you want it to work with linear sliders, you have to setSliderSnapsToMousePosition to false.

1 Like

In case anyone faces the same problem, here is the solution I came up with, based on @kamedin’s advice:

    #include <limits>

    slider.setColour(Slider::ColourIds::trackColourId, Colour());

    const int sensitivity = 40;   // higher numbers mean less sensitivity

    slider.setRange(std::numeric_limits<int>::min() / sensitivity, std::numeric_limits<int>::max() / sensitivity, 1);