SnapEngine
import { SnapEngine } from 'pixi-silk/ui/snap';
Experimental
Pure 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.
Experimental: the API may change in a minor release.
Constructors#
Constructor#
new SnapEngine(options?: SnapEngineOptions): SnapEngine;
Experimental
Parameters#
| Parameter | Type |
|---|---|
options | SnapEngineOptions |
Returns#
SnapEngine
Properties#
| Property | Type | Description | Defined in |
|---|---|---|---|
centres | boolean | Experimental Uses target centres as snap anchors. | ui/snap.ts:99 |
edges | boolean | Experimental Uses target edges as snap anchors. | ui/snap.ts:97 |
lines | { x: number[]; y: number[]; } | Experimental Fixed guide lines. Guides.bindSnap() from pixi-silk/ui/guides keeps them in step with a guides layer. | ui/snap.ts:105 |
lines.x | number[] | - | ui/snap.ts:105 |
lines.y | number[] | - | ui/snap.ts:105 |
points | { x: number; y: number; }[] | Experimental Points, used like zero-size targets. | ui/snap.ts:107 |
spacing | boolean | Experimental Snaps to equal gaps between neighbours. | ui/snap.ts:101 |
targets | SnapRect[] | Experimental Rectangles to snap against. | ui/snap.ts:103 |
threshold | number | Experimental Distance within which things snap, in the snapping space’s units. | ui/snap.ts:95 |
Methods#
snap()#
snap(rect: SnapRect, exclude?: readonly SnapRect[]): SnapResult;
Experimental
Snaps a moving rectangle and returns the move and the guides. Does not change rect.
exclude leaves out targets by identity, usually the moving object’s own rectangle.
Parameters#
| Parameter | Type | Default value |
|---|---|---|
rect | SnapRect | undefined |
exclude | readonly SnapRect[] | [] |
Returns#
snapPoint()#
snapPoint(x: number, y: number): {
guides: SnapGuide[];
x: number;
y: number;
};
Experimental
Snaps a single point, as a zero-size rectangle, and returns where it lands.
Parameters#
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns#
{
guides: SnapGuide[];
x: number;
y: number;
}
| Name | Type | Defined in |
|---|---|---|
guides | SnapGuide[] | ui/snap.ts:153 |
x | number | ui/snap.ts:153 |
y | number | ui/snap.ts:153 |