Skip to content

Feat/align object to label#41

Merged
u8array merged 6 commits into
mainfrom
feat/align-object-to-label
May 9, 2026
Merged

Feat/align object to label#41
u8array merged 6 commits into
mainfrom
feat/align-object-to-label

Conversation

@u8array
Copy link
Copy Markdown
Owner

@u8array u8array commented May 9, 2026

No description provided.

u8array added 5 commits May 9, 2026 23:09
Three icon buttons (centre-H, centre-V, centre-both) in the Properties
panel emit an alignment intent through the store; the canvas effect
measures the rendered group bbox via Konva clientRect and dispatches the
corresponding x/y delta. Stage measurement is the source of truth so
text/barcode/etc. footprints match what the user sees.

Multi-select centres the union bbox of all selected objects, preserving
their relative positions (matches Figma's group-align-to-canvas).
Decorative SVGs inside aria-labeled buttons should not be announced
separately; matches the DragHandleIcon precedent.
…-bus

The previous implementation routed PropertiesPanel button clicks through a
serial-bumping flag on the store and a useEffect in LabelCanvas. Two smells:
the field wasn't real state (just messaging), and the effect needed an
`exhaustive-deps` disable to avoid re-firing on every pan/zoom.

Replace with the React-idiomatic pattern: LabelCanvas exposes an imperative
handle via forwardRef + useImperativeHandle, AppShell holds the ref, passes
it to PropertiesPanel which calls `alignSelectionToLabel` directly. Action
is co-located with the data it reads (Konva clientRect). AlignButtons
becomes pure presentation with an `onAlign` callback prop.
Optional+default-{} let a missing ref silently no-op the align buttons.
Required prop forces AppShell to wire it; the inner `.current?` guard
is enough — it only covers the pre-mount window.
Splits the three centre-axis SVG icons out of AlignButtons.tsx so the
button-row file stays focused on layout/dispatch. Matches the pattern
of ui/DragHandleIcon.tsx for single-purpose inline icons.
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 feature to align selected objects to the center of the label horizontally, vertically, or both. It adds a new AlignButtons component to the PropertiesPanel, exposes an imperative alignSelectionToLabel method in LabelCanvas via forwardRef, and includes a dedicated alignment utility with unit tests. Localization support for these new actions has been added across all supported languages. A review comment recommends rounding the final object coordinates to the nearest integer to ensure compatibility with ZPL's dot-based coordinate system and prevent floating-point precision issues in the state.

Comment thread src/components/Canvas/LabelCanvas.tsx
PropertiesPanel inputs and `mmToDots` already round dots, so the store
invariant is integer x/y. The alignment delta was emitted as a float
(layoutDx / pxPerDot) and could leak fractional coordinates into ZPL
emit. Match the convention by rounding the delta.
@u8array u8array merged commit 9e55a15 into main May 9, 2026
2 checks passed
@u8array u8array deleted the feat/align-object-to-label branch May 10, 2026 20:06
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