I’m trying to drag a DP to an area where it needs to snap to a grid of x36, y51. I can partly do it but I’m obviously doing something wrong as its not quite working. See screenshot attached for visual explanation.
I’m using
(if area of This is over DP)
[[ (This.X / 36).toFixed(18) * 36 ]]
[[ (This.Y / 51).toFixed(25.5) * 51 ]]
Using a boundary area. If DP is outside this area it’ll move back to a specific point.
You want toFixed() to round off the expressions completely. The parameter to toFixed() specifies the number of decimal points, so you’ll want toFixed(0) in your expressions.
Here’s an example. This DP snaps to every 10 pixels horizontally and every 40 vertically.
In my scenario its a bit more complicated. I also need to resize each rectangle to the grid and still move it so it snaps to the x36 by y51 grid within a an area.
I’m also mimicking moving DP from one DP into others and potentially back.
If you have an idea how to get all that working as simply as possible, I’ll buy you a drink
I can get the DPs to resize. The challenge is to get them to resize and snap to grid on resize while being able to drag them onto different positions on the grid.
My demo seems to be getting forever more complicated. Maybe it’ll be easy to build the software
I modified the file in this post so that it will snap to grid on resize. It’s set to snap to the nearest 25 horizontally and the nearest 50 vertically. You can change the grid this by changing the “variables” (text labels storing values) in the hidden dynamic panel. It also drags using the same grid.
[Edit] It occurs to me that you probably want a minimum size on resize that matches the smallest grid size. You can do this by adding Math.max() to each expression in each drag handle. Example, here is the y resize on the lower-right-corner drag handle: