Snapping DPs to grid on drop drag

Hi!

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.

Live sample

File: resize-with-drag-handles_snap_to_nearest_xy.rp (89.4 KB)

[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:

[[ Math.max( ((startDragY + TotalDragY + This.height - Target.y)/nearestY).toFixed(0) * nearestY, nearestY ) ]]

2 Likes