Search Docs
Loading...
Skip to content

Grid & Rulers

Enable and configure grid overlays, snap-to-grid behavior, and canvas rulers so users can position and align elements with precision in your CE.SDK editor.

5 mins
estimated time
Download
StackBlitz
GitHub

CE.SDK provides a configurable grid overlay and canvas rulers to help users align design elements. The grid renders evenly spaced lines across the page, and snap-to-grid constrains element movement to grid intersections. Rulers display along the top and left edges of the canvas showing measurement units.

Enable the Grid#

Toggle the grid overlay using the grid/enabled setting. When enabled, the engine draws a grid of lines across each page based on the configured spacing and color.

// Show the grid overlay on the canvas
engine.editor.setSettingBool('grid/enabled', true);

The grid is a visual aid rendered at the engine level. It does not affect the scene content or export output.

Enable Snap-to-Grid#

Snap-to-grid constrains element movement so blocks align to grid lines. Enable it with the grid/snapEnabled setting.

// Enable snapping so elements align to grid lines
engine.editor.setSettingBool('grid/snapEnabled', true);

When snap-to-grid is active, dragging or resizing a block snaps its edges to the nearest grid line. This works independently of the grid overlay visibility, so you can snap to an invisible grid if needed.

Configure Grid Spacing#

Set the horizontal and vertical distance between grid lines using grid/spacingX and grid/spacingY. Values are in design units (the unit configured for the scene).

// Set horizontal and vertical grid spacing in design units
engine.editor.setSettingFloat('grid/spacingX', 20);
engine.editor.setSettingFloat('grid/spacingY', 20);

Smaller spacing values produce a finer grid. The default spacing is 32 design units in both directions.

Configure Grid Color#

Change the grid line color using grid/color. The color supports an alpha channel, so you can make the grid more or less prominent.

// Set a custom grid color with transparency
engine.editor.setSettingColor('grid/color', {
r: 0.2,
g: 0.4,
b: 0.8,
a: 0.3
});

Enable Rulers#

Rulers are managed through the ly.img.rulers feature flag and the editor’s UI store. The Advanced Editor and Video Editor plugins enable rulers by default.

// Rulers are controlled through the editor's UI store.
// The AdvancedEditorConfig plugin enables the 'ly.img.rulers'
// feature flag, which makes rulers available in the UI.
// Rulers are visible by default when the feature flag is enabled.

Rulers display along the top and left edges of the canvas. They show tick marks and labels in the scene’s design unit, and they update as the user pans and zooms.

Editor Plugin Defaults#

Different editor plugins configure grid and rulers with different defaults:

PluginGrid VisibleSnap-to-GridRulers
Advanced EditorYesYesYes
Video EditorYesYesYes
Design EditorNoNoNo
Photo EditorNoNoNo

To add grid and ruler support to an editor that doesn’t enable them by default, set the settings and feature flag manually as shown in the examples above.

Per-Page Grid Overrides#

Each page in the scene can override the document-level grid configuration through the page/guides/* block properties. Setting page/guides/source to 'Custom' switches that page onto its own values; leaving it at 'Document' keeps the page on the engine-wide defaults. Ruler visibility remains document-level only — there is no per-page ruler override.

Per-page grids are session-only — they are not persisted when the scene is saved. Opening the scene again starts every page back on the document-level grid.

// Opt a specific page into its own grid configuration.
engine.block.setEnum(pageId, 'page/guides/source', 'Custom');
engine.block.setBool(pageId, 'page/guides/gridEnabled', true);
engine.block.setFloat(pageId, 'page/guides/gridSpacingX', 20);
engine.block.setFloat(pageId, 'page/guides/gridSpacingY', 20);
engine.block.setColor(pageId, 'page/guides/gridColor', {
colorSpace: 'sRGB',
r: 0.2,
g: 0.4,
b: 0.9,
a: 0.5
});
engine.block.setBool(pageId, 'page/guides/gridSnapEnabled', true);
// Revert the page to the document defaults.
engine.block.setEnum(pageId, 'page/guides/source', 'Document');

In the default Advanced Editor UI, grid controls live only in the Page Inspector — selecting a page shows a “Grid” section that writes to that page’s page/guides/* properties. The Document Inspector exposes only the “Show Rulers” toggle; the global grid/* settings are still used as the fallback for pages in Document mode, but have no UI of their own. When users add a new page, the editor seeds its grid from the immediately previous page when that page is in Custom mode, so the grid they were just working with carries over without re-entry. If the previous page is in Document mode, the new page also uses Document — new pages never revive older per-page overrides.

API Reference#

APITypeDefaultDescription
grid/enabledBoolfalseShow or hide the grid overlay
grid/snapEnabledBoolfalseEnable snapping to grid lines
grid/spacingXFloat32Horizontal spacing between grid lines (design units)
grid/spacingYFloat32Vertical spacing between grid lines (design units)
grid/colorColor{ r: 0, g: 0, b: 0, a: 0.12 }Grid line color with alpha
page/guides/sourceEnum ('Document' / 'Custom')'Document'Per-page resolution source; Document falls back to the grid/* settings
page/guides/gridEnabledBoolfalsePer-page override of grid/enabled (applied when source is Custom)
page/guides/gridSnapEnabledBoolfalsePer-page override of grid/snapEnabled
page/guides/gridSpacingXFloat10Per-page override of grid/spacingX
page/guides/gridSpacingYFloat10Per-page override of grid/spacingY
page/guides/gridColorColorneutral grayPer-page override of grid/color