feat(helper-lines): custom snapping guides + edge snapping for text & paint (#833, #834)#841
Merged
Merged
Conversation
…#834) Custom guides (#834): - Add HelperGuideLine (axis + absolute/normalized position) and HelperLineConfigs.customGuides. Custom guides participate in layer snapping and are drawn (HelperLineStyle.customGuideColor) while a layer snaps to them, even when showLayerAlignLine is disabled. - Add a "Custom-Guide-Lines" example demonstrating thirds and safe-area guides. Text edge snapping (#833): - Text layers now expose their left, center and right edges as snap anchors; the edge closest to a guide (editor center, another layer or a custom guide) snaps to it. Other layer types keep their single anchor. Implementation: - Generalize the layer-align/center-line snapping in LayerInteractionManager to multi-anchor (text) and multi-target (layers + custom guides), reusing the existing release/threshold hysteresis. - Add Layer.renderSize to derive text edge anchors and pass editorBodySize into calculateMovement to resolve custom guide positions.
- Fix text "jumping straight to the center line": the editor center line again snaps by the layer center (single anchor), so onScaleStart and the center-line path stay consistent. Edge snapping now happens only via the layer-align / custom-guide path, which has proper per-target hysteresis. - Extend edge snapping to paint layers in addition to text. - Add top/center/bottom (vertical) edges for both text and paint, alongside left/center/right. - Fix wrong snap points after a resize: `renderSize` already reflects the on-screen (scaled) size, so it must not be multiplied by `scale` again - the double-count grew with `scale`, which changes on resize.
…r guide - The editor center lines snap by every edge of text/paint layers again (closest edge wins), not just the layer center. The earlier jump is fixed properly by initializing the snap hysteresis in onScaleStart from the same closest edge that calculateMovement evaluates. - Allow every edge to snap to the same layer/custom guide: the align snap helper de-duped by target only, which blocked the other edges once one had snapped. The hysteresis key now also encodes the snapping edge.
…itches With multi-anchor edge snapping, the edge closest to a center line switches at the midpoint between two edges (e.g. left -> center). The tracked position then flips sign discontinuously, which the crossing-based center-line snap misread as a real crossing and snapped to the center in one jump. Track the closest edge between move frames and suppress a *new* center-line snap on the frame the closest edge switches, so only a genuine crossing snaps. Dragging now stops smoothly at each edge instead of jumping.
Edge anchors used the unrotated half-size (center +/- width/2), so a rotated layer's snap lines no longer lined up with its actual extent. Derive the edges from the rotated axis-aligned bounding box (W*|cos| + H*|sin|), which collapses to the unrotated size when the layer is not rotated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #833 and #834.
#834 — App-defined custom snapping guide lines
Adds an API for apps to define their own snapping/helper guides (safe areas, thirds, columns, layout slots, …):
HelperGuideLine—axis(vertical snaps X, horizontal snaps Y),position, andpositionMode(absoluteeditor-body pixels ornormalized0.0–1.0).releaseThreshold) and are drawn with the newHelperLineStyle.customGuideColorwhile a layer snaps to them — even whenshowLayerAlignLineisfalse.#833 — Text & paint snap by their edges
Text and paint layers now expose their left / center / right and top / center / bottom edges as snap anchors (no dependence on
TextAlign). When aligning to another layer or a custom guide, whichever edge sits closest snaps to it, making it easy to align text/paint blocks by their visible edge. Other layer types keep their single configured anchor; the editor center line still snaps by the layer center.Implementation notes
LayerInteractionManager._updateAlignmentGuideswas generalized to multiple active-layer anchors (text/paint edges, both axes) and multiple targets (other layers' anchors + custom guides), keeping the existing snap/release hysteresis. AisVerticalGuideCustom/isHorizontalGuideCustomflag selects the draw color.Layer.renderSizeexposes the rendered (already-scaled) content size used to derive edge anchors;calculateMovementreceiveseditorBodySizeto resolve custom-guide positions into the editor's center-relative coordinate space.Tests
Added unit tests for
HelperGuideLine.resolvePosition(absolute/normalized) and equality. Full suite (436 tests) passes anddart analyzeis clean for both the package and the example.