Blockly. Grid
Class for a workspace's grid.
Constructor
Grid
new Grid(pattern, options)
Parameter |
|
---|---|
pattern |
The grid's SVG pattern, created during injection. Value must not be null. |
options |
A dictionary of normalized options for the grid. See grid documentation: https://developers.google.com/blockly/guides/configure/web/grid Value must not be null. |
Methods
createDom
createDom(rnd, gridOptions, defs) returns SVGElement
Create the DOM for the grid described by options.
Parameter |
|
---|---|
rnd |
string A random ID to append to the pattern's ID. |
gridOptions |
Object The object containing grid configuration. Value must not be null. |
defs |
SVGElement The root SVG element for this workspace's defs. Value must not be null. |
- Returns
-
non-null SVGElement
The SVG element for the grid pattern.
dispose
dispose()
Dispose of this grid and unlink from the DOM.
getPatternId
getPatternId() returns string
Get the ID of the pattern element, which should be randomized to avoid conflicts with other Blockly instances on the page.
- Returns
-
string
The pattern ID.
getSpacing
getSpacing() returns number
Get the spacing of the grid points (in px).
- Returns
-
number
The spacing of the grid points.
moveTo
moveTo(x, y)
Move the grid to a new x and y position, and make sure that change is visible.
Parameter |
|
---|---|
x |
number The new x position of the grid (in px). |
y |
number The new y position of the grid (in px). |
shouldSnap
shouldSnap() returns boolean
Whether blocks should snap to the grid, based on the initial configuration.
- Returns
-
boolean
True if blocks should snap, false otherwise.
update
update(scale)
Update the grid with a new scale.
Parameter |
|
---|---|
scale |
number The new workspace scale. |