Make a linear vertical slider draggable only via the slider thumb

gui

#1

A linear vertical slider will drag if a mouse down event happens within any point of the slider bounds.

Is there a way to make a linear vertical slider drag happen by using only the slider thumb?


#2

Slider:: setSliderSnapsToMousePosition()

https://docs.juce.com/master/classSlider.html#acf58b7346a74cfc0a8c809567836df61

Rail


#3

It’s actually hard to explain exactly what I mean, I already have setSliderSnapsToMousePosition() set to false, and that part works fine. I think I will need to get the coordinates of the mouse down event to check if they are directly where the slider thumb is, and then go from there.


#4

Well, I use Component::hitTest() on my Slider’s thumb to make sure the mouse is over it…

bool CMixerFader::hitTest (const int x, const int y)
{
    // blah, blah, blah.. check for modifiers, etc...
    
    if (m_pProcessor->m_PlayerInfo.bSnapMixerFadersToClick)
        return true;

    return m_FaderCap.isPointInImage (x, y);
}

CMixerFader is my Slider derived class.

Rail


#5

If I understand you correctly, your Slider thumb is big, so if you click far left of the thumb, the middle of the thumb jumps to the clicked position, am I right?

I haven’t checked, if there is something present to remedy that, but if not I think your suggestion to keep the local position on mouseDown and subtract it in mouseDrag would be an option…


#6

I use hitTest because my Slider Thumb is smaller than the expected size.

Rail


#7

No, it doesn’t jump to the clicked position. It’s that I can drag the slider thumb by dragging on the slider track. It’s not a big deal, I just wanted to tweak it if I could.
I might just leave it. Also, I am using a rectangular slider knob image.


#8

Great, thanks for clarification. I felt like there was a misunderstanding, but seems it was on my end…