Horizonatl/Vertical Dragger


#1

Hi, I need the kind of ComponentDragger that restricts the component's position to only one of the directions. I think this is common enough a feature so it should be done easilly. But I don't see any way how to achieve this using ComponentBoundsConstrainer. If I understand it well, You can only restrict the component's size, and the amount of pixels it can go offscreen.

 

I achieved the desired effect by inheriting ComponentDragger and basically overriding it's methods and altering the mouseEvent so that it has the same y-coordinate as the event that initiated the mouseDrag. But this solution seems kinda hackish and I don't like it. Is there a nicer solution in JUCE for this? I think that it is that common a feature that ComponentDragger could just have a property (that you could specify in the constructor or whatever) saying that it would drag in just one of the directions.

 

Thanks


#2

Any idea?


#3

ComponentBoundsConstrainer would be the thing to use. You can put restrictions on the bounds in any way you want, not just the size.


#4

But I just don't see how. There's no "setLimits()" method. There are methods for setting maximum/minimum size, and methods for fixed aspect ratio. But those are useful only for resizing the component. My component is fixed-size and I need to drag it, but restrain it's movement to x direction only (wherever it currently is...). There are also methods for setting minimum onscreen amount of pixels but those are apparently not useful for this action either.

 

thanks


#5

Override ComponentBoundsConstrainer::checkBounds() and do whatever you need to do in there.


#6

Well yes, I figured that much, but I was trying to say that dragging in just one of the directions is common enough a task (or so I think) that it should be some basic ComponentBoundsConstrainer feature, or maybe ComponentDragger feature. So if you find a little of Your time (I know it sounds unlikely) maybe You could consider that.

 

Thanks anyeay, I will then stick with my current solution...