Skip to content

Feat/smart snap tweaks#52

Merged
u8array merged 4 commits into
mainfrom
feat/smart-snap-tweaks
May 10, 2026
Merged

Feat/smart snap tweaks#52
u8array merged 4 commits into
mainfrom
feat/smart-snap-tweaks

Conversation

@u8array
Copy link
Copy Markdown
Owner

@u8array u8array commented May 10, 2026

No description provided.

u8array added 2 commits May 10, 2026 23:06
…t-zone

Barcodes used to pad their Konva Group's bbox out to the full ZPL
footprint via an invisible Rect at (w, h). That made the Transformer's
selection border, the smart-align centring, and drag-time object-snap
all latch onto the padded edges. For EAN/UPC the gap was a firmware-
reserved text zone (rendered as empty space), so selection appeared
disconnected from the visible bars even with HRI off.

Two changes that route every consumer through the *same* bbox via
plain getClientRect:

- Drop the three padding Rects from BarcodeObject (default, default-
  no-HRI, EAN/UPC rotated branches). The HRI Text already has
  getSelfRect=0; without the padding the Group's bbox naturally
  collapses to the bar image.
- EAN/UPC HRI digits are rendered as multiple <Text> nodes — these
  *do* contribute to the bbox by default. Wrap them in a Group whose
  getClientRect is overridden to {0,0,0,0}, applying the same 'bars-
  only' rule to the multi-text variant without threading refs through
  10+ individual Text components.

Smart-align, drag-snap and the Transformer selection border all now
target the bar rect without any external helper or per-shape special
case in LabelCanvas.
Line endpoint snap previously routed through computeSnap with a
zero-size SnapRect, which still emitted the *centre* of every neighbour
as a candidate (sensible for whole-object alignment, surprising for
endpoints — dragging a line endpoint toward another shape could latch
onto the midpoint of that shape and produce a guide at '50 %' rather
than at an actual edge).

New computePointSnap helper considers only edges of others + the label
rect. LineObject's snapEndpoint now calls it instead.

Adds 5 unit tests pinning the no-centre rule, label-edge support,
threshold honour and tie-break between competing edges.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a computePointSnap utility to implement edge-only snapping for line endpoints, addressing a bug where endpoints would snap to the centers of other objects. Additionally, BarcodeObject is refactored to exclude human-readable text from the bounding box calculation by wrapping text nodes in a Group with a zeroed getClientRect and removing legacy footprint rectangles. The review feedback recommends updating computePointSnap to support multiple simultaneous alignment guides and optimizing the rendering logic in BarcodeObject to check for array length instead of truthiness.

Comment thread src/lib/snapGuides.ts
Comment thread src/lib/snapGuides.ts Outdated
Comment thread src/components/Canvas/BarcodeObject.tsx Outdated
- computePointSnap now accumulates all guides at the same best
  distance, mirroring computeSnap's behaviour: when two neighbour
  objects share an edge with the dragged endpoint, both guide
  lines render instead of only the first-encountered one.
- BarcodeObject's text-group wrapper guards on .length > 0 instead
  of truthy. textNodes / textElements are arrays initialised to []
  / undefined respectively; an empty array is truthy and would
  otherwise spawn an empty <Group> + ref callback every render.
@u8array
Copy link
Copy Markdown
Owner Author

u8array commented May 10, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors BarcodeObject to exclude human-readable text from bounding box calculations and introduces computePointSnap to resolve '50% snap' artifacts during line endpoint manipulation. Reviewers noted that the array check for textElements could break rendering for certain barcode types and recommended restoring center-snapping specifically for the label area, as users typically expect this behavior despite the fix for other objects.

Comment thread src/components/Canvas/BarcodeObject.tsx Outdated
Comment thread src/lib/snapGuides.ts
- BarcodeObject: revert textElements guard from Array.isArray to truthy
  check. Non-EAN rotated barcodes assign a single ReactNode (not an
  array), which the stricter check incorrectly filtered out, killing
  HRI text rendering.
- snapGuides.computePointSnap: allow snapping to the label rect's
  centre in addition to its edges. Neighbour objects stay edge-only so
  the original 50%-snap regression remains fixed.
@u8array
Copy link
Copy Markdown
Owner Author

u8array commented May 10, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors barcode bounding box logic and introduces a specialized point-snapping utility. In BarcodeObject.tsx, HRI text is now excluded from the group's bounding box by overriding getClientRect, and redundant invisible footprint rectangles are removed to focus selection on the bars. Additionally, a new computePointSnap function is implemented in snapGuides.ts to provide edge-only snapping for line endpoints, resolving a bug where endpoints would incorrectly snap to the midpoints of neighboring objects. Comprehensive tests for the new snapping logic were also added. I have no feedback to provide.

@u8array u8array merged commit 5d7a96b into main May 10, 2026
2 checks passed
@u8array u8array deleted the feat/smart-snap-tweaks branch May 11, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant