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.

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