Behavior: Dragging past component "bounds" then back


#1

So I've noticed this behavior a lot when using JUCE. Lets say you're dragging the slider's thumb to the right and the thumb reaches the end. Well if you keep dragging to the right then try to go to the left to bring the thumb back down, you have to drag to the left the same amount until you can actually change the position of the thumb. To me, this is really undesired behavior. I just noticed this same thing again when using ComponentDragger and going passed the bounds of a ComponentBoundsConstrainer. 

Do components like these have something built in that allows you to not have this behavior? When I go back in the opposite direction, I want it to pick up right then, not when I drag back enough. I think velocity mode actually stops this behavior for the Slider class, but I usually don't want to use velocity mode. 

If JUCE can't do this already, are there any easy fixes you can think of? I really hope this is something in JUCE already. Out of curiosity, does this bother anyone else? I don't think I've ever used an app that's had this behavior. 


#2

That's the behaviour you'll see for every slider/scrollbar/draggable object works in every major OS and graphics library.

The alternative, where it uses relative movements regardless of the absolute mouse position, is something you'll occasionally see in custom UIs, but always just looks to me like it was written naively.

The Slider class does however have a mode where it hides the mouse and uses relative positioning, which might be what you're looking for?


#3

Hey, 

I'm making an xy component and would like to hide the cursor when dragging. 

This same issue makes it feel a bit unintuitive when the user drags past the edge of the pad and then back.

 

Is there a way to set boundaries on the mouseevent to stay within it's current component? 

Any ideas on how one could do that? I've tried to use the setCursorPosition, but was only able to get it to work within the context of the whole Desktop, which wasn't readily giving me the desired results.

 

Thanks, any advice appreciated

J


#4

Have a look at MouseInputSource::enableUnboundedMouseMovement(), it's for exactly this purpose.


#5

Thanks Jules,

I'm using unbounded mouse movement, but while the cursor is invisible it can wander far beyond the edge of the component. If you want to go back the other direction, like jordan said, the user needs to compensate for how far past the edge they went.

Any ideas how that's stopped?

Sorry if this has a stupid straight forward answer. I was trying to set the cursor position through the Desktop::, but seems a bit hacky.


#6

Hey,

Sorry i was able to sort it out with this little bit of code

As an example for anyone : this works to stop the mouse from leaving the left side of a component if the user keeps dragging

    if (e.getEventRelativeTo(this).x < 0)

    {

        Point<int> p = Desktop::getMousePosition();

        p.x = this->getScreenX();

        Desktop::setMousePosition(p);

    }


#7

No, you've misunderstood, and this code is a bad example for anyone to follow!

If you're using unbounded mouse movement then it'll do what you're asking for if you ignore the absolute coordinates and just look at the amount it moves between events. The MouseInputSource will take care of making sure the mouse doesn't hit the edges of the screen, so it should seem to carry on moving forever. That's how things like the Slider work if you have them in unbounded mode.