openpencil/packages/core/src/canvas/page-guides.ts
Danila Poyarkov 91e759d7fd feat(editor): add configurable snapping and guides
- Snap vector points, moved layers, and resized edges to geometry, objects, guides, and pixels
- Add persistent snapping preferences with browser and native menu controls
- Normalize canvas and layout guides across Scene Graph and .fig conversion
- Clear transient snapping feedback across interrupted interactions
2026-08-18 19:11:48 +03:00

26 lines
884 B
TypeScript

import type { Canvas } from 'canvaskit-wasm'
import type { SceneGraph } from '@open-pencil/scene-graph'
import { SELECTION_COLOR } from '#core/constants'
import type { SkiaRenderer } from './renderer'
export function drawPageGuides(r: SkiaRenderer, canvas: Canvas, graph: SceneGraph): void {
const page = graph.getNode(r.pageId ?? graph.rootId)
if (!page || page.guides.length === 0) return
r.auxStroke.setStrokeWidth(1)
r.auxStroke.setColor(r.ck.Color4f(SELECTION_COLOR.r, SELECTION_COLOR.g, SELECTION_COLOR.b, 0.65))
for (const guide of page.guides) {
if (guide.axis === 'x') {
const x = guide.position * r.zoom + r.panX
canvas.drawRect(r.ck.LTRBRect(x, 0, x + 1, r.viewportHeight), r.auxStroke)
} else {
const y = guide.position * r.zoom + r.panY
canvas.drawRect(r.ck.LTRBRect(0, y, r.viewportWidth, y + 1), r.auxStroke)
}
}
}