Skip to content
pixi-silk
GitHub repository
Entry point

pixi-silk/ui/snap

SnapEngine and SnapGuides: snap boxes to edges, centres and lines.

import { SnapEngine, SnapGuides } from 'pixi-silk/ui/snap';

Classes#

ClassDescription
SnapEnginePure snapping maths, no drawing. It moves a rectangle so its edges or centre line up with other rectangles, guide lines and points, or so it sits at an equal gap from its neighbours. Each axis picks the nearest candidate within the threshold. Works in whatever space the rectangles are given in, axis-aligned only. Change the properties at any time.
SnapGuidesDraws what a SnapEngine found: dashed alignment lines with end marks, and equal-gap markers with their distance in a pill. Each alignment fades in when found and out when lost, so the guides never slide from one alignment to the next. Add it to the same space as the rectangles you snap. It ignores pointer events.

Interfaces#

InterfaceDescription
SnapEngineOptionsOptions of SnapEngine. Each one sets the engine property of the same name.
SnapGuideA line the snap engine found, ready to draw, in the snapping space.
SnapGuidesOptionsOptions of SnapGuides.
SnapRectAxis-aligned rectangle in the snapping space. Targets are compared by identity in exclude.
SnapResultWhat SnapEngine.snap found. Add dx and dy to the moving rectangle to snap it.