Suggested change to Slider


Since Slider isn’t written to be extendable much, I’ve had to “fork” it instead of sub-classing.

With that said, the change I made might be useful to others, so here it is as a suggestion.

This specifically is for when the slider has min, max and current value.

When using it I’ve frequently found that when I expect to modify the main value, I ended up dragging min and max instead. This gets a lot worse if I use the slider inside of a zoomable view, for example as an indicator for the transport of a zoomable timeline view, with min / max being loop points (beginning end), and current value being current time. Then often start/end are even out of view, but then you click, expecting current value to change, and the start end unexpectedly keep pop in.

Anyway, the change is to only engage min/max moving, if directly clicking near min/max, rather than if the mouse is vaguely closer to those than the current value:

 int getThumbIndexAt(const MouseEvent& e)
        if (isTwoValue() || isThreeValue())
            auto mousePos = isVertical() ? e.position.y : e.position.x;
            auto thumbSize = isVertical() ? e.eventComponent->getWidth() : e.eventComponent->getHeight();

            auto normalPosDistance = std::abs(getLinearSliderPos(currentValue.getValue()) - mousePos);
            auto minPosDistance = std::abs(getLinearSliderPos(valueMin.getValue()) + (isVertical() ? 0.1f : -0.1f) - mousePos);
            auto maxPosDistance = std::abs(getLinearSliderPos(valueMax.getValue()) + (isVertical() ? -0.1f : 0.1f) - mousePos);

            if (isTwoValue())
                return maxPosDistance <= minPosDistance ? 2 : 1;

            if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance && minPosDistance <= thumbSize * 2)
                return 1;

            if (normalPosDistance >= maxPosDistance && maxPosDistance <= thumbSize * 2)
                return 2;

        return 0;