Alignment Guides
The smart guides of a drawing tool: with SnapToGuides on, a dragged node clicks into line with the nodes around it - by an edge or its centre, on each axis - and a thin guide shows what it matched. GuideDistance sets how close is close enough and GuideColor paints the line.
Press Tab to move between the nodes and edges of the diagram.
Press Enter or Space to select it, Shift with Enter to add it to the selection, the arrow keys to move the selected nodes, Delete to remove them and Escape to clear the selection. Press C to start a connection from it.
Press Enter or Space to select it, Delete to remove it and Escape to clear the selection. Press C to move its end to another node.
bit BlowTry it
- Drag "Drag me" toward Anchor: when its left edge, centre or right edge comes within the distance of one of Anchor's, it clicks into line and a vertical guide joins the two. The same happens on the other axis with tops, middles and bottoms.
- Line it up with two nodes at once - Small's top and Tall's left edge, say: each axis snaps to its own neighbour and each draws its own guide.
- Drag Distance up to snap from further away, or to 0 to turn snapping off. Zoom in or out first: the distance is the same on screen at any zoom.
- Pick a Guide colour and drag again to see the line in it.
- Tick Snap to grid: on an axis with no guide in reach the node lands on the 20-unit grid, while an axis that found a guide follows the guide.
- Untick Alignment guides and the node moves freely again.
How it works
SnapToGuides(false) tests the dragged node against every visible node not moving with it; each axis offers three lines - leading edge, centre, trailing edge - and the nearest match on each axis wins. A dragged selection moves as one block.GuideDistance(6) is in screen pixels, so the snap feels equally forgiving however far you have zoomed.GuideColor("#f43f5e") is any CSS colour, a custom property included; the guide is drawn one screen pixel thick at any zoom.SnapToGridwithSnapGridXandSnapGridY(15 by default, 20 here to match the background) snaps the axes a guide did not claim.- The matching itself is public as
BlowAlignment.Snap(moving, candidates, tolerance), for tools of your own.