Every jam project of mine seems to involve drag and drop in some way. I build it from scratch every time, and every time there is some aspect of it that absolutely kicks my ass. I figured I should jot down my overall approach here so people (read: my future self) can maybe learn something from it.
In my opinion, any self-respecting drag and drop system needs to handle a couple potentially tricky features:
-
"Gesture recognition", or rather, allowing clicks and double-clicks on draggable items. In particular I find it very important that an item is not recognized as dragging until the mouse has strayed by a few pixels from the location where it went down. It is very common for the mouse to drift by a pixel or two while someone is clicking, and if this cancels the click, users will be frustrated.
In addition, I feel strongly that, once a drag starts, the dragged item should subsequently be offset by
mouse_pos - original_mouse_down_pos, not `mouse_pos - mouse_pos_when_drag_