-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
adding object properties of snapAngle and snapThreshold to enable object snapping. #3383
adding object properties of snapAngle and snapThreshold to enable object snapping. #3383
Conversation
Hello Stefan, thank for bringing this to the finish line. There is some linting failing: Also we have sort of convention to group sequential var declaration ( first this was lintend, now no more, i think i lost the rule in a conversion process ) so + var snapAngle = t.target.snapAngle;
+ var snapThreshold = t.target.snapThreshold || snapAngle;
+ var rightAngleLocked = Math.ceil(angle / snapAngle) * snapAngle;
+ var leftAngleLocked = Math.floor(angle / snapAngle) * snapAngle; should be + var snapAngle = t.target.snapAngle,
+ snapThreshold = t.target.snapThreshold || snapAngle,
+ rightAngleLocked = Math.ceil(angle / snapAngle) * snapAngle,
+ leftAngleLocked = Math.floor(angle / snapAngle) * snapAngle; |
a couple of things come to my mind.
sorry for not bringing this up before. |
…true if a rotation angle changed has happened.
good thoughts. updated! |
i think we are good to go. |
…ect snapping. (#3383) * adding object properties of and to enable object snapping.
Hi, Nice feature, i tried it on a fiddle : http://jsfiddle.net/pec86/128/ For example if i have set the snap threshold at 10° : If I made a manual rotation at 13.5°(it's the last value show in the console, then clear the console) after i made a snapped rotation (by pressing the shift key, and I continue the rotation), the angle show in the console is first 13.6° then 10°. Looks like there is a first setAngle called but without the snapped value. So it's result with a sligth forward&backward movement for the object. Can you confirm it ? Keep up the good work. |
I guess the real issue is with the example. The rotation event is called after rotation has happened so if you wait for rotation to set the snapAngle then you get a single tick of a normal angle. The solution is to set the snapAngle on shift keydown / keyup events. Here is your jsfiddle updated to get rid of the extra rotation tick before the snap: http://jsfiddle.net/yvo89upg/ and here is the bulk of the change in the jsfiddle:
|
Thank you, i understand better how to use this. hope this will go in the documentation. have a good day |
That jsfiddle didn't work for me. It was saying canvas.getActiveGroup() wasn't a function I updated it and used canvas.getActiveObjects()
|
Adds a way to set an angle interval to snap to during rotation (
snapAngle
) and the ability to set the threshold of how far away it snaps to that angle (snapThreshold
).When the
snapThreshold
is null (the default) it will use thesnapAngle
until the user sets thesnapThreshold
. This is good because it makes the api easier to use and also setting thesnapAngle
will feel more obvious with the threshold and the angle the same.Here is an example of just the
snapAngle
set toe 45:@asturur mentioned adding a shift or alt modifier key to turn the behavior off but I think that might be better handled in code like so:
To me this keep fabric feeling more like a tool, while assigning predetermined modifier keys to disable behavior makes the library feel more opinionated then a tool should be. This code to disable the snap behavior could easily go in a tutorial somewhere.
close #3369