[Solved] How to prevent Slider thumb movement on mousedown when cursor is on it?

So I have a custom (linear vertical) slider, with a thumb image which is much larger than the default drawn one. When the slider is all the way down and you mousedown on the thumb, it would jump up a bit, before actually dragging.

Is there an API for telling the slider not to change value if you have mousedown-ed on the thumb (before any dragging), and only keep the behavior for moving the thumb to mousedown position (jump to a new value) if you clicked somewhere else on the body of the slider?


Update (last):

There is another topic about this same thing. They reached the same conclusion - to use setSliderSnapsToMousePosition (false).
Evidently, the 2nd part of the problem needs to be custom implemented.

setSliderSnapsToMousePosition (false) will solve half of the problem. As much as I can see there is no way to keep the jump to mouse position when you are not over the thumb, is there?

Have a look at the MouseListener methods the slider is using. You’ll probably want to override mouseDown() in your custom slider to ignore clicks within the bounds of the current thumb.

Thanks. Sure, that’s what I will do in case there is no API for it. I am trying not to reimplement something that’s already there.

What do you mean “in case there is no API for it”? JUCE is the API for it! :joy:

I meant exactly what I said. :slight_smile:

JUCE provides a set of classes and they have an API/interface.
If there is a flag (method) that switches on/off the Slider behavior in question - I want to know about it, so I don’t reimplement something that is already there.

All the code’s there for you to look at - get digging.

Is it just me, or this sounds disrespectful?

I always do (reasonable) research before posting in the forum. And I always document the solutions to the problems I post, too. In a forum setting, people post and answer questions, voluntarily. There hardly is ever a problem that one absolutely cannot solve on their own. But, as in many other communities, we try to help each-other and solve those issues faster, when we can.

So I don’t really see a reason for you to try and check me on “not digging deep enough”. In fact, on my question “Is there an API for X?” you basically answered “no, the solution is to implement it on your own” and that’s not even true, since it turned out half of the issue is solvable through an API call.

So, in summary, you didn’t contribute a valuable info on the topic, you made (so far) 3 unnecessary & unhelpful comments and managed to write something offensive. That is impressive in a way, but it’s less than useful.

No more disrespectful than “I meant exactly what I said. :slightly_smiling_face:

Just suggesting what I would do in this case - wasn’t suggesting it was the only correct way of doing it. If you want to find something built-in to JUCE to solve a problem then look through documentation and code - if it’s not there, it’s not there.

1 Like