Feat/smart snap tweaks#52
Conversation
…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.
There was a problem hiding this comment.
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.
- 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.
|
/gemini review |
There was a problem hiding this comment.
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.
- 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.
|
/gemini review |
There was a problem hiding this comment.
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.
No description provided.