Stay organized with collections
Save and categorize content based on your preferences.
blockly > Grid
Grid class
Class for a workspace's grid.
Signature:
export declare class Grid
Constructors
Methods
Method |
Modifiers |
Description |
alignXY(xy) |
|
Given a coordinate, return the nearest coordinate aligned to the grid. |
getLength() |
|
Get the length of the grid lines (in px). |
getSpacing() |
|
Get the spacing of the grid points (in px). |
setLength(length) |
|
Sets the length of the grid lines. |
setSnapToGrid(snap) |
|
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. |
setSpacing(spacing) |
|
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. |
shouldSnap() |
|
Whether blocks should snap to the grid. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-18 UTC."],[[["The `Grid` class manages the visual grid of a Blockly workspace, controlling its appearance and block snapping behavior."],["It provides methods to adjust grid spacing, line length, and alignment of elements to the grid."],["Blocks can be programmatically snapped to the grid, ensuring consistent placement and organization."],["The grid's visual characteristics and snapping behavior can be customized using its methods."]]],["The `Grid` class manages a workspace's grid. Key actions include constructing a grid, aligning coordinates to the grid (`alignXY`), and managing grid properties. Methods allow retrieving (`getLength`, `getSpacing`) and setting (`setLength`, `setSpacing`) the grid line length and spacing. `setSnapToGrid` enables grid snapping for blocks, which is activated upon the next drag-and-drop. `shouldSnap` checks if snapping is active.\n"]]