Slider::onDragStart won't let call Slider::setValue() properly?

Why doesn’t this work:

Let’s say I have:
juce::Slider slider;

Then I want to do the following in a class that owns that slider:

        slider.onDragStart = [this, number]()
        {
                slider.setValue(number);
        };

Now when I drag the slider, setting the value doesn’t actually seem to affect the value at all nor the slider’s position on screen.

If I do the same by overriding the slider’s own mouseDown() method and calling that exact same setValue() from inside the slider itself, then everything works fine.

Is there a way to set the slider’s value from onDragStart callback?

You’re capturing number by copy, not reference.

Try [this, &number] instead.

No, I don’t think it’s that. I’m intentionally using copy of the number so whenever the slider is touched, i would change it’s value to that what the number was when the lambda was defined. Just to test that the setValue() actually works in that context.

So I could just write: slide.setValue(0) and it still wouldn’t change the value to 0.

I tested this and it doesn’t work. But I think it is intentional.
Stepping through the debugger, the lambda is executed and the value is set. But since you are dragging the knob, it will jump immediately to the position where your mouse is pointing to.

Why it should behave differently with the Slider::Listener is a mystery to me.

Have you tried overriding Slider::snapValue() ?

That gets called by mouseDrag()

Rail