Skip to content

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.

Anchor
Small
Tall
Drag me
bit Blow

Try 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.
  • SnapToGrid with SnapGridX and SnapGridY (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.
An unhandled error has occurred. Reload 🗙