GeezerVison is showing github.com — feat: ruler guides drag out of the rulers, and objects snap to them · u8array/ZPLab@177e3ae
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: e2e/rulerGuides.spec.ts +381Lines changed: 381 additions & 0 deletions Large diffs are not rendered by default. Collapse file Copy file name to clipboardExpand all lines: src/components/Canvas/LabelCanvas.tsx +71-6Lines changed: 71 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,7 +19,7 @@ import { isGroup, getAllLeaves, exportableLeaves, expandSelection, selectionTarg | 19 | 19 | import { pxToDots, dotsToPx, mmToDots, SCREEN_PX_PER_MM } from "@zplab/core/lib/coordinates"; | 20 | 20 | import { effectiveDpmm } from "@zplab/core/types/LabelConfig"; | 21 | 21 | import { loadImage } from "@zplab/core/lib/loadImage"; | 22 | | -import { SNAP_OPTIONS } from "@zplab/core/lib/units"; | | 22 | +import { SNAP_OPTIONS, dotsToUnit, unitLabel, unitToMm } from "@zplab/core/lib/units"; | 23 | 23 | import type { Unit } from "@zplab/core/lib/units"; | 24 | 24 | import { Select } from "../ui/Select"; | 25 | 25 | import type { SnapGuide } from "../../lib/snapGuides"; | @@ -74,6 +74,11 @@ import { useAltClickCycle } from "./hooks/useAltClickCycle"; | 74 | 74 | import { useSelectionActionBar, actionBarPosition } from "./hooks/useSelectionActionBar"; | 75 | 75 | import type { Bounds } from "./nodeRect"; | 76 | 76 | import { useSelectionGuides } from "./hooks/useSelectionGuides"; | | 77 | +import { useRulerGuideGestures } from "./hooks/useRulerGuideGestures"; | | 78 | +import { RulerGuideInput } from "./RulerGuideInput"; | | 79 | +import { RulerGuideLines, RulerGuideMarks, RulerStrips } from "./RulerGuides"; | | 80 | +import { guideAtStage, guideSnapLinesStage, guideToStage, stageRulerGuides, type RulerGuideView, type StageRulerGuide } from "../../lib/rulerGuides"; | | 81 | +import { guideLineAtReading, guideReadingDots } from "./rulerGuideLayout"; | 77 | 82 | import { FloatingCanvasButton, RADIUS as BUTTON_RADIUS, type ButtonTone } from "./FloatingCanvasButton"; | 78 | 83 | import { ROTATE_ICON, TRASH_ICON, LOCK_ICON, UNLOCK_ICON, GROUP_ICON, UNGROUP_ICON, LINE_ICON, BOX_ICON } from "./canvasIcons"; | 79 | 84 | import { isShapeToggleable, canToggleShapeMode, oppositeShapeMode, toggleShapeMode } from "../../lib/lineBoxConvert"; | @@ -285,6 +290,7 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa | 285 | 290 | // Everything on canvas is drawn in the current page's dot scale; | 286 | 291 | // designLabel stays the MODEL's design scope for the whole-document emit. | 287 | 292 | const label = useLabelStore(selectRenderPageLabel); | | 293 | + const rulerGuides = useLabelStore((s) => s.rulerGuides); | 288 | 294 | const designLabel = useLabelStore((s) => s.label); | 289 | 295 | const objects = useLabelStore(selectRenderObjects); | 290 | 296 | const effDpmm = effectiveDpmm(label); | @@ -595,6 +601,9 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa | 595 | 601 | verticalReversed: rulerReversal.vertical, | 596 | 602 | }; | 597 | 603 |
| | 604 | + const guideView: RulerGuideView = { originX: objectsOffsetX, originY: labelOffsetY, centerX: labelCenterX, centerY: labelCenterY, scale, rotation: viewRotation }; | | 605 | + const guideSnapLines = guideSnapLinesStage(rulerGuides, guideView); | | 606 | + | 598 | 607 | // Safe-area guide rect in screen px (dots scaled, object-offset aligned). | 599 | 608 | const safeAreaDots = safeAreaRectDots(label); | 600 | 609 | const safeAreaPx = safeAreaDots && { | @@ -636,6 +645,27 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa | 636 | 645 | onMouseUp: onLassoMouseUp, | 637 | 646 | onStageMouseDown, | 638 | 647 | } = useCanvasLasso({ containerRef, stageRef, spaceDown, selectObjects }); | | 648 | + // The stage and the label paper, where no object takes a press. | | 649 | + const isBare = (target: Konva.Node) => target === target.getStage() || target === labelPaperRef.current; | | 650 | + const guideGestures = useRulerGuideGestures({ | | 651 | + containerRef, | | 652 | + guides: rulerGuides, | | 653 | + view: guideView, | | 654 | + dpmm: effDpmm, | | 655 | + canvasWidth: containerSize.width, | | 656 | + canvasHeight: containerSize.height, | | 657 | + isBare, | | 658 | + spaceDown, | | 659 | + editorFrozen, | | 660 | + }); | | 661 | + const stageGuides = stageRulerGuides(rulerGuides, guideView, guideGestures.draft?.moving); | | 662 | + // The draft shows on the dot it would land on. | | 663 | + const draftOnDot = guideGestures.draft && guideAtStage(guideGestures.draft, guideView, effDpmm); | | 664 | + const draftGuide = draftOnDot && guideToStage(draftOnDot, guideView); | | 665 | + const guideReading = (line: StageRulerGuide) => dotsToUnit(guideReadingDots(line, rulerProps, effDpmm), effDpmm, unit); | | 666 | + const badgeLine = draftGuide ?? (guideGestures.hovered && guideToStage(guideGestures.hovered, guideView)); | | 667 | + const guideBadge = badgeLine && { at: badgeLine, text: `${guideReading(badgeLine)} ${unitLabel(unit)}` }; | | 668 | + const editedLine = guideGestures.editing && guideToStage(guideGestures.editing, guideView); | 639 | 669 |
| 640 | 670 | // Snap math operates in stage-screen space, so the label rect must | 641 | 671 | // reflect the rotation-aware visual bounds, not layout coords. | @@ -970,6 +1000,7 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa | 970 | 1000 | updateObjects, | 971 | 1001 | multiResizeBboxDots, | 972 | 1002 | labelRect: transformerSnapLabelRect, | | 1003 | + snapLines: guideSnapLines, | 973 | 1004 | objectSnapEnabled: smartSnapActive, | 974 | 1005 | snapBypassRef, | 975 | 1006 | setGuides, | @@ -1143,7 +1174,8 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa | 1143 | 1174 | if (editorFrozen) return; | 1144 | 1175 | if (consumeDidPan()) return; | 1145 | 1176 | if (consumeDidLasso()) return; | 1146 | | - if (e.target === e.target.getStage()) selectObjects([]); | | 1177 | + if (guideGestures.consumeDidDrag()) return; | | 1178 | + if (isBare(e.target)) selectObjects([]); | 1147 | 1179 | }; | 1148 | 1180 |
| 1149 | 1181 | const handleMouseMove = (e: React.MouseEvent) => { | @@ -1349,7 +1381,7 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa | 1349 | 1381 | backgroundImage: `radial-gradient(circle, ${colors.canvasDot} 1px, transparent 1px)`, | 1350 | 1382 | backgroundSize: "24px 24px", | 1351 | 1383 | // Locus-of-attention feedback for the frozen editor. | 1352 | | - cursor: editorFrozen ? 'not-allowed' : pickingRfidPosition ? 'crosshair' : cursor, | | 1384 | + cursor: editorFrozen ? 'not-allowed' : pickingRfidPosition ? 'crosshair' : (cursor ?? guideGestures.cursor), | 1353 | 1385 | }} | 1354 | 1386 | onMouseDown={handleMouseDown} | 1355 | 1387 | onMouseMove={handleMouseMove} | @@ -1499,7 +1531,13 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa | 1499 | 1531 | height={containerSize.height} | 1500 | 1532 | onClick={handleStageClick} | 1501 | 1533 | onContextMenu={openContextMenu} | 1502 | | - onMouseDown={onStageMouseDown} | | 1534 | + onMouseDown={(e) => { | | 1535 | + if (guideGestures.onStageMouseDown(e)) return; | | 1536 | + onStageMouseDown(e); | | 1537 | + }} | | 1538 | + onMouseMove={guideGestures.onStageMouseMove} | | 1539 | + onMouseLeave={guideGestures.onStageMouseLeave} | | 1540 | + onDblClick={guideGestures.onStageDblClick} | 1503 | 1541 | onDragStart={(e) => { | 1504 | 1542 | cancelLasso(); | 1505 | 1543 | if (isPanningRef.current) { | @@ -1555,7 +1593,6 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa | 1555 | 1593 | } | 1556 | 1594 | shadowBlur={editorFrozen ? 28 : 12} | 1557 | 1595 | shadowOffsetY={editorFrozen ? 0 : 2} | 1558 | | - onClick={() => selectObjects([])} | 1559 | 1596 | /> | 1560 | 1597 |
| 1561 | 1598 | {/* Safe-area guide: non-interactive dashed inset, accent like the ^FB wrap-guide. */} | @@ -1655,6 +1692,7 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa | 1655 | 1692 | registerMover={dragController.registerMover} | 1656 | 1693 | getOthersSnapshot={smartSnapActive ? getOthersSnapshot : undefined} | 1657 | 1694 | labelRect={transformerSnapLabelRect} | | 1695 | + snapLines={guideSnapLines} | 1658 | 1696 | setGuides={setGuides} | 1659 | 1697 | snapBypassRef={snapBypassRef} | 1660 | 1698 | /> | @@ -1792,6 +1830,16 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa | 1792 | 1830 |
| 1793 | 1831 | {!editorFrozen && <GuideLines guides={guides} />} | 1794 | 1832 |
| | 1833 | + {!editorFrozen && ( | | 1834 | + <RulerGuideLines | | 1835 | + guides={stageGuides} | | 1836 | + draft={draftGuide} | | 1837 | + canvasWidth={containerSize.width} | | 1838 | + canvasHeight={containerSize.height} | | 1839 | + colors={colors} | | 1840 | + /> | | 1841 | + )} | | 1842 | + | 1795 | 1843 | {!editorFrozen && ( | 1796 | 1844 | <Transformer | 1797 | 1845 | ref={transformerRef} | @@ -1902,14 +1950,31 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa | 1902 | 1950 | </Layer> | 1903 | 1951 |
| 1904 | 1952 | {/* Ruler tracks visual edges; labels reverse when axis flips. */} | 1905 | | - <Layer listening={false}> | | 1953 | + <Layer> | 1906 | 1954 | <Ruler {...rulerProps} /> | | 1955 | + <RulerStrips canvasWidth={containerSize.width} canvasHeight={containerSize.height} /> | | 1956 | + {!editorFrozen && ( | | 1957 | + <RulerGuideMarks | | 1958 | + guides={stageGuides} | | 1959 | + badge={guideBadge} | | 1960 | + colors={colors} | | 1961 | + /> | | 1962 | + )} | 1907 | 1963 | {selectionGuidesEnabled && !editorFrozen && ( | 1908 | 1964 | <SelectionGuides ref={selectionGuidesRef} linesRef={selectionGuideLinesRef} {...rulerProps} dpmm={effDpmm} /> | 1909 | 1965 | )} | 1910 | 1966 | </Layer> | 1911 | 1967 | </Stage> | 1912 | 1968 | )} | | 1969 | + {editedLine && ( | | 1970 | + <RulerGuideInput | | 1971 | + at={editedLine} | | 1972 | + value={guideReading(editedLine)} | | 1973 | + unit={unitLabel(unit)} | | 1974 | + label={t.app.guidePosition} | | 1975 | + onEnd={(value) => guideGestures.endEdit(value === null ? null : guideLineAtReading(editedLine, unitToMm(value, unit), rulerProps))} | | 1976 | + /> | | 1977 | + )} | 1913 | 1978 | {ctxMenu.menu && ( | 1914 | 1979 | <CanvasContextMenu | 1915 | 1980 | sections={ctxMenu.menu.data} | |
Collapse file Copy file name to clipboardExpand all lines: src/components/Canvas/LineObject.tsx +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -80,6 +80,7 @@ export function LineObject({ | 80 | 80 | registerMover, | 81 | 81 | getOthersSnapshot, | 82 | 82 | labelRect, | | 83 | + snapLines, | 83 | 84 | setGuides, | 84 | 85 | snapBypassRef, | 85 | 86 | }: Props) { | @@ -180,6 +181,7 @@ export function LineObject({ | 180 | 181 | othersSnapshotRef.current, | 181 | 182 | undefined, | 182 | 183 | labelRect, | | 184 | + snapLines, | 183 | 185 | ); | 184 | 186 | setGuides(result.guides); | 185 | 187 | const back = transform.copy().invert().point({ x: result.x, y: result.y }); | @@ -254,6 +256,7 @@ export function LineObject({ | 254 | 256 | undefined, | 255 | 257 | labelRect, | 256 | 258 | labelRect, | | 259 | + snapLines, | 257 | 260 | ); | 258 | 261 | const snappedExtPx = isHorizontal ? result.height : result.width; | 259 | 262 | const cappedT = Math.min( | |
Collapse file Copy file name to clipboard +54Lines changed: 54 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { useRef, useState } from "react"; | | 2 | +import type { StageRulerGuide } from "../../lib/rulerGuides"; | | 3 | +import { guideBadgeOrigin } from "./rulerGuideLayout"; | | 4 | + | | 5 | +interface Props { | | 6 | + at: StageRulerGuide; | | 7 | + value: number; | | 8 | + unit: string; | | 9 | + label: string; | | 10 | + /** Called with the typed value, or null when the edit is dropped. */ | | 11 | + onEnd: (value: number | null) => void; | | 12 | +} | | 13 | + | | 14 | +/** The typed position of a guide, shown in place of its badge. */ | | 15 | +export function RulerGuideInput({ at, value, unit, label, onEnd }: Props) { | | 16 | + const shown = String(value); | | 17 | + const [draft, setDraft] = useState(shown); | | 18 | + // Escape and Enter unmount the field, and the browser may still fire a blur after that. | | 19 | + const endedRef = useRef(false); | | 20 | + | | 21 | + const end = (keep: boolean) => { | | 22 | + if (endedRef.current) return; | | 23 | + endedRef.current = true; | | 24 | + const typed = Number(draft); | | 25 | + // The shown value is rounded, so taking it back unchanged would move the guide. | | 26 | + onEnd(keep && draft !== shown && draft.trim() !== "" && Number.isFinite(typed) ? typed : null); | | 27 | + }; | | 28 | + | | 29 | + const { x, y } = guideBadgeOrigin(at); | | 30 | + return ( | | 31 | + <label | | 32 | + className="absolute z-20 flex items-center gap-1 rounded border border-accent bg-surface-2 px-1 font-mono text-[10px] text-muted" | | 33 | + style={{ left: x, top: y }} | | 34 | + onMouseDown={(e) => e.stopPropagation()} | | 35 | + > | | 36 | + <input | | 37 | + type="number" | | 38 | + step="any" | | 39 | + aria-label={`${label} (${unit})`} | | 40 | + autoFocus | | 41 | + className="w-14 bg-transparent py-0.5 text-text outline-none" | | 42 | + value={draft} | | 43 | + onFocus={(e) => e.target.select()} | | 44 | + onChange={(e) => setDraft(e.target.value)} | | 45 | + onBlur={() => end(true)} | | 46 | + onKeyDown={(e) => { | | 47 | + if (e.key === "Enter") end(true); | | 48 | + if (e.key === "Escape") end(false); | | 49 | + }} | | 50 | + /> | | 51 | + {unit} | | 52 | + </label> | | 53 | + ); | | 54 | +} |
Collapse file Copy file name to clipboard +88Lines changed: 88 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { Group, Label, Line, Rect, Tag, Text } from "react-konva"; | | 2 | +import type { CanvasColors } from "../../hooks/useColorScheme"; | | 3 | +import type { StageRulerGuide } from "../../lib/rulerGuides"; | | 4 | +import { RULER_FONT, RULER_SIZE } from "./Ruler"; | | 5 | +import { guideBadgeOrigin, RULER_STRIP_LEFT, RULER_STRIP_TOP } from "./rulerGuideLayout"; | | 6 | + | | 7 | +const MARK_PX = 5; | | 8 | + | | 9 | +interface LinesProps { | | 10 | + guides: readonly StageRulerGuide[]; | | 11 | + draft: StageRulerGuide | null; | | 12 | + canvasWidth: number; | | 13 | + canvasHeight: number; | | 14 | + colors: CanvasColors; | | 15 | +} | | 16 | + | | 17 | +// A 1 px stroke stays crisp on a half pixel. | | 18 | +const crisp = (px: number) => Math.floor(px) + 0.5; | | 19 | + | | 20 | +const points = ({ vertical, px }: StageRulerGuide, width: number, height: number) => | | 21 | + vertical ? [crisp(px), RULER_SIZE, crisp(px), height] : [RULER_SIZE, crisp(px), width, crisp(px)]; | | 22 | + | | 23 | +export function RulerGuideLines({ guides, draft, canvasWidth, canvasHeight, colors }: LinesProps) { | | 24 | + return ( | | 25 | + <Group listening={false}> | | 26 | + {guides.map((guide) => ( | | 27 | + <Line | | 28 | + key={`${guide.vertical}-${guide.px}`} | | 29 | + name="ruler-guide" | | 30 | + points={points(guide, canvasWidth, canvasHeight)} | | 31 | + stroke={colors.rulerGuide} | | 32 | + strokeWidth={1} | | 33 | + /> | | 34 | + ))} | | 35 | + {draft && draft.px >= RULER_SIZE && ( | | 36 | + <Line name="ruler-guide-draft" points={points(draft, canvasWidth, canvasHeight)} stroke={colors.rulerGuide} strokeWidth={1} dash={[4, 3]} /> | | 37 | + )} | | 38 | + </Group> | | 39 | + ); | | 40 | +} | | 41 | + | | 42 | +interface StripsProps { | | 43 | + canvasWidth: number; | | 44 | + canvasHeight: number; | | 45 | +} | | 46 | + | | 47 | +/** Hit areas over the rulers. Without them a press on a ruler reaches the object that lies under it. */ | | 48 | +export function RulerStrips({ canvasWidth, canvasHeight }: StripsProps) { | | 49 | + return ( | | 50 | + <> | | 51 | + <Rect name={RULER_STRIP_TOP} x={RULER_SIZE} y={0} width={canvasWidth - RULER_SIZE} height={RULER_SIZE} /> | | 52 | + <Rect name={RULER_STRIP_LEFT} x={0} y={RULER_SIZE} width={RULER_SIZE} height={canvasHeight - RULER_SIZE} /> | | 53 | + </> | | 54 | + ); | | 55 | +} | | 56 | + | | 57 | +interface MarksProps { | | 58 | + guides: readonly StageRulerGuide[]; | | 59 | + badge: { at: StageRulerGuide; text: string } | null; | | 60 | + colors: CanvasColors; | | 61 | +} | | 62 | + | | 63 | +export function RulerGuideMarks({ guides, badge, colors }: MarksProps) { | | 64 | + return ( | | 65 | + <Group listening={false}> | | 66 | + {guides | | 67 | + // A guide under the other ruler has no place on this one. | | 68 | + .filter(({ px }) => px >= RULER_SIZE) | | 69 | + .map(({ vertical, px }) => ( | | 70 | + <Rect | | 71 | + key={`${vertical}-${px}`} | | 72 | + name="ruler-guide-mark" | | 73 | + x={vertical ? crisp(px) - MARK_PX / 2 : RULER_SIZE - MARK_PX} | | 74 | + y={vertical ? RULER_SIZE - MARK_PX : crisp(px) - MARK_PX / 2} | | 75 | + width={MARK_PX} | | 76 | + height={MARK_PX} | | 77 | + fill={colors.rulerGuide} | | 78 | + /> | | 79 | + ))} | | 80 | + {badge && badge.at.px >= RULER_SIZE && ( | | 81 | + <Label name="ruler-guide-badge" {...guideBadgeOrigin(badge.at)}> | | 82 | + <Tag fill={colors.rulerGuide} cornerRadius={3} /> | | 83 | + <Text text={badge.text} fill="#ffffff" fontSize={9} fontFamily={RULER_FONT} padding={3} /> | | 84 | + </Label> | | 85 | + )} | | 86 | + </Group> | | 87 | + ); | | 88 | +} |
Collapse file Copy file name to clipboardExpand all lines: src/components/Canvas/dragGeometry.ts +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | // delta to apply to the whole drag, so the snap policy stays testable without a | 3 | 3 | // stage and the controller stays a thin imperative layer. | 4 | 4 |
| 5 | | -import { computeSnap, type SnapGuide, type SnapRect } from "../../lib/snapGuides"; | | 5 | +import { computeSnap, type SnapGuide, type SnapLines, type SnapRect } from "../../lib/snapGuides"; | 6 | 6 | import { barBoxDots, printableRectDots, type BoundingBoxDots, type ObjectBoundsCtx } from "@zplab/core/lib/objectBounds"; | 7 | 7 | import type { PageLabel } from "@zplab/core/types/LabelConfig"; | 8 | 8 | import { visibleLeaves, type LabelObject } from "@zplab/core/types/Group"; | @@ -38,8 +38,9 @@ export function smartSnapDelta( | 38 | 38 | others: SnapRect[], | 39 | 39 | labelRect: SnapRect | undefined, | 40 | 40 | threshold: number, | | 41 | + lines?: SnapLines, | 41 | 42 | ): { dx: number; dy: number; guides: SnapGuide[] } { | 42 | | - const r = computeSnap(box, others, threshold, labelRect, labelRect); | | 43 | + const r = computeSnap(box, others, threshold, labelRect, labelRect, lines); | 43 | 44 | return { dx: r.x - box.x, dy: r.y - box.y, guides: r.guides }; | 44 | 45 | } | 45 | 46 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/components/Canvas/hooks/useKonvaDragController.ts +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,8 @@ import type Konva from "konva"; | 3 | 3 | import { pxToDots, dotsToPx } from "@zplab/core/lib/coordinates"; | 4 | 4 | import { dragSnapTargets, gridSnapDelta, smartSnapDelta, labelSnapRectDots } from "../dragGeometry"; | 5 | 5 | import { SNAP_THRESHOLD_PX } from "../../../lib/snapGuides"; | 6 | | -import type { SnapGuide, SnapRect } from "../../../lib/snapGuides"; | | 6 | +import type { SnapGuide, SnapLines, SnapRect } from "../../../lib/snapGuides"; | | 7 | +import { guideSnapLinesDots } from "../../../lib/rulerGuides"; | 7 | 8 | import { | 8 | 9 | barBoxDots, | 9 | 10 | selectionUnionDots, | @@ -70,6 +71,8 @@ interface DragState { | 70 | 71 | others: SnapRect[]; | 71 | 72 | /** Printable label rect (dots) as a smart-snap target. */ | 72 | 73 | labelDots: SnapRect; | | 74 | + /** Ruler guides in dots, smart-snap targets. */ | | 75 | + guideDots: SnapLines; | 73 | 76 | /** Latest model-space delta (dots), applied to all on commit. */ | 74 | 77 | lastDelta: { x: number; y: number }; | 75 | 78 | } | @@ -170,6 +173,7 @@ export function useKonvaDragController(args: DragControllerArgs): DragHandlers { | 170 | 173 | startUnionDots, | 171 | 174 | others, | 172 | 175 | labelDots, | | 176 | + guideDots: guideSnapLinesDots(state.rulerGuides, args.dpmm), | 173 | 177 | lastDelta: { x: 0, y: 0 }, | 174 | 178 | }; | 175 | 179 | }; | @@ -216,7 +220,7 @@ export function useKonvaDragController(args: DragControllerArgs): DragHandlers { | 216 | 220 | height: drag.startUnionDots.height, | 217 | 221 | }; | 218 | 222 | const thresholdDots = pxToDots(SNAP_THRESHOLD_PX, args.scale, args.dpmm); | 219 | | - const { dx, dy, guides } = smartSnapDelta(cur, drag.others, drag.labelDots, thresholdDots); | | 223 | + const { dx, dy, guides } = smartSnapDelta(cur, drag.others, drag.labelDots, thresholdDots, drag.guideDots); | 220 | 224 | deltaDots = { x: rawDx + dx, y: rawDy + dy }; | 221 | 225 | setGuides(guides.map(toLocalGuide)); | 222 | 226 | } | |
|