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. No starter kit turns the grid on, so it stays hidden until you set grid/enabled yourself.

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. Snapping requires the grid to be enabled: elements snap only when the page’s effective grid and snap values are both on — the grid/enabled and grid/snapEnabled settings for pages in Document mode, or the page’s own page/guides/gridEnabled and page/guides/gridSnapEnabled for pages in Custom mode. Like the grid, no starter kit turns snapping on.

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#

Ruler availability is controlled by the ly.img.rulers feature flag. When the flag is enabled, the ruler overlay becomes available and the Document Inspector shows a “Show Rulers” toggle. The same flag also gates the per-page Grid section in the Page Inspector.

Enabling the feature does not turn rulers on. Rulers appear only after the user checks “Show Rulers” in the Document Inspector. Ruler visibility is session-only UI state: there is no public API to toggle it programmatically, and it is not saved with the scene.

CE.SDK enables the flag by default. Starter kits reset every feature when they initialize and then re-enable their own set, so only the Design Editor (Advanced) and Video Editor (Advanced) starter kits keep the rulers control. In every other starter kit, call cesdk.feature.enable('ly.img.rulers') after you add the starter kit plugin.

// Make the rulers control available in the panel.
// Rulers stay hidden until the user checks "Show Rulers".
cesdk.feature.enable('ly.img.rulers');

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.

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 Design Editor (Advanced) and Video Editor (Advanced) starter kits, grid controls live in the Grids & Guides panel, opened from a row in the Document and 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.

Safety Margin#

The safety margin is an inward inset drawn on each page, marking the area a print process may trim. Each page carries its own values in page/safetyInset/*, with page/safetyEnabled turning it on.

// Turn the safety margin on for a page and set an inset per side.
engine.block.setBool(pageId, 'page/safetyEnabled', true);
engine.block.setFloat(pageId, 'page/safetyInset/top', 10);
engine.block.setFloat(pageId, 'page/safetyInset/bottom', 10);
engine.block.setFloat(pageId, 'page/safetyInset/left', 10);
engine.block.setFloat(pageId, 'page/safetyInset/right', 10);

Set page/safetyRevealDuringTransform to show the margin only while a block is moved or resized near it, instead of drawing it on every page all the time.

// Draw the safety margin only when a block comes close.
engine.editor.setSetting('page/safetyRevealDuringTransform', true);

The ly.img.page.printMarks.safetyMargin feature key controls the section in the panel. See Disable or Enable Features.

API Reference#

API Type Default Description
grid/enabled Bool false Show or hide the grid overlay
grid/snapEnabled Bool false Enable snapping to grid lines
grid/spacingX Float 32 Horizontal spacing between grid lines (design units)
grid/spacingY Float 32 Vertical spacing between grid lines (design units)
grid/color Color neutral gray ({ r: 0.52, g: 0.52, b: 0.52, a: 0.3 }) Grid line color with alpha
page/safetyEnabled Bool false Show or hide the safety margin on a page
page/safetyInset/top, /bottom, /left, /right Float 0 Inward inset per side (design units)
page/safetyRevealDuringTransform Bool true Draw the safety margin only while a block is moved or resized near it
page/guides/source Enum ('Document' / 'Custom') 'Document' Per-page resolution source; Document falls back to the grid/* settings
page/guides/gridEnabled Bool false Per-page override of grid/enabled (applied when source is Custom)
page/guides/gridSnapEnabled Bool false Per-page override of grid/snapEnabled
page/guides/gridSpacingX Float 10 Per-page override of grid/spacingX
page/guides/gridSpacingY Float 10 Per-page override of grid/spacingY
page/guides/gridColor Color neutral gray Per-page override of grid/color