-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add constrained bounds to SimpleDragHandler #3
Comments
A few options:
|
I'm fine with (2), letting the client handle it. I think the client could correct the problem if it noted the drag start point (in "start" function), like we do in Piccolo. SR seemed to think that this should be handled in SimpleDragHandler, perhaps he can elaborate? |
Can you take a look at phet/svn/RelativeDragHandler? It solves the problem of having an arbitrary constraint, never getting away from the cursor or hand, and playing nicely with MVC round trip.
The constraint function could be something like ImmutableRectangle.getClosestPoint(x,y); I think having something built in to scenery somewhere (maybe but not necessarily SimpleDragHandler) would be nice so we aren't duplicating this idea in lots of places in client code. |
I personally would like to have the bounds handled by Scenery, and for the planned pan/zoom handler it absolutely needs to do similar bounds constraints. Would passing in { constrain: <function( point ): truthy> } be a better option? |
I guess you are suggesting {constrain: } as an option for SimpleDragHandler, and that the argument might be a function or a rectangle? Those options sound like they would work well. SimpleDragHandler may need to be rewritten a bit to use relativeGrabPoint or equivalent so the mouse/touch doesn't get away from the object. |
I would imagine 'constrain' could be a Bounds2, a function of that type above, or in the future a Shape once it can support Shape.closestPointTo( point ). Bounds2 does not have an invertible transform, since when it rotates it expands to stay axis-aligned, so if we need rotated rectangle constraints we'll have to use the Shape form (i.e. Rectangle) |
Thinking about this more... I don't think drag constraints should be added to SimpleDragHandler. It's supposed to be "simple". I think it would be more appropriate to write BoundedDragHandler (or whatever you want to call it.) |
As noted during a developer meeting, I'll be trying out a mixin-style for drag handlers, so we could potentially mix in a BoundedDragBehavior into a simpler drag handler design, as it should allow more extension possibilities. |
This functionality should be added to DragListener, not SimpleDragHandler. See #131. |
Will track in #131. |
Try using SimpleDragHandler to drag a node that has constrained drag bounds. The cursor will become disconnected from the node.
Here's a use case (untested code). Note that node position is updated via a roundtrip to the model.
The text was updated successfully, but these errors were encountered: