Class: Grid
Defined in: packages/blockly/core/grid.ts:23
Class for a workspace's grid.
Methods index
| Method | Description |
|---|---|
| setSpacing | Sets the spacing between the centers of the grid lines. |
| getSpacing | Get the spacing of the grid points (in px). |
| setLength | Sets the length of the grid lines. |
| getLength | Get the length of the grid lines (in px). |
| setSnapToGrid | Sets whether blocks should snap to the grid or not. |
| shouldSnap | Whether blocks should snap to the grid. |
| alignXY | Given a coordinate, return the nearest coordinate aligned to the grid. |
Constructors
Constructor
new Grid(pattern, options): Grid;
Defined in: packages/blockly/core/grid.ts:37
Parameters
| Parameter | Type | Description |
|---|---|---|
pattern | SVGElement | The grid's SVG pattern, created during injection. |
options | GridOptions | A dictionary of normalized options for the grid. See grid documentation: https://docs.blockly.com/guides/configure/grid/ |
Returns
Grid
Methods
setSpacing()
setSpacing(spacing): void;
Defined in: packages/blockly/core/grid.ts:65
Sets the spacing between the centers of the grid lines.
This does not trigger snapping to the newly spaced grid. If you want to snap blocks to the grid programmatically that needs to be triggered on individual top-level blocks. The next time a block is dragged and dropped it will snap to the grid if snapping to the grid is enabled.
Parameters
| Parameter | Type |
|---|---|
spacing | number |
Returns
void
getSpacing()
getSpacing(): number;
Defined in: packages/blockly/core/grid.ts:75
Get the spacing of the grid points (in px).
Returns
number
The spacing of the grid points.
setLength()
setLength(length): void;
Defined in: packages/blockly/core/grid.ts:80
Sets the length of the grid lines.
Parameters
| Parameter | Type |
|---|---|
length | number |
Returns
void
getLength()
getLength(): number;
Defined in: packages/blockly/core/grid.ts:86
Get the length of the grid lines (in px).
Returns
number
setSnapToGrid()
setSnapToGrid(snap): void;
Defined in: packages/blockly/core/grid.ts:98
Sets whether blocks should snap to the grid or not.
Setting this to true does not trigger snapping. If you want to snap blocks to the grid programmatically that needs to be triggered on individual top-level blocks. The next time a block is dragged and dropped it will snap to the grid.
Parameters
| Parameter | Type |
|---|---|
snap | boolean |
Returns
void
shouldSnap()
shouldSnap(): boolean;
Defined in: packages/blockly/core/grid.ts:107
Whether blocks should snap to the grid.
Returns
boolean
True if blocks should snap, false otherwise.
alignXY()
alignXY(xy): Coordinate;
Defined in: packages/blockly/core/grid.ts:195
Given a coordinate, return the nearest coordinate aligned to the grid.
Parameters
| Parameter | Type | Description |
|---|---|---|
xy | Coordinate | A workspace coordinate. |
Returns
Workspace coordinate of nearest grid point. If there's no change, return the same coordinate object.