feat: implement relative-layout-mode <constraint /> between groups with centerX/centerY#1980
Open
769066112-ops wants to merge 2 commits intotscircuit:mainfrom
Open
feat: implement relative-layout-mode <constraint /> between groups with centerX/centerY#1980769066112-ops wants to merge 2 commits intotscircuit:mainfrom
769066112-ops wants to merge 2 commits intotscircuit:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
3 tasks
Comment on lines
293
to
298
| if (hasCenterX || hasCenterY) { | ||
| info.absoluteCenter = { | ||
| x: hasCenterX ? constraintCenterX : 0, | ||
| y: hasCenterY ? constraintCenterY : 0, | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Logic error with partial absolute positioning. When only centerX is specified (without centerY), this sets y: 0. Similarly, when only centerY is specified, it sets x: 0. This forces the unspecified axis to zero instead of using the packer's computed position.
If a user specifies only centerX={10}, they likely want to constrain only the x-axis while letting the packer determine the y-position. Instead, this will force y=0.
Fix:
if (hasCenterX || hasCenterY) {
info.absoluteCenter = {
x: hasCenterX ? constraintCenterX : undefined,
y: hasCenterY ? constraintCenterY : undefined,
}
}Then in applyPackOutput.ts, handle undefined values:
const effectiveCenter = {
x: cluster.absoluteCenter?.x ?? center.x,
y: cluster.absoluteCenter?.y ?? center.y,
}
Suggested change
| if (hasCenterX || hasCenterY) { | |
| info.absoluteCenter = { | |
| x: hasCenterX ? constraintCenterX : 0, | |
| y: hasCenterY ? constraintCenterY : 0, | |
| } | |
| } | |
| if (hasCenterX || hasCenterY) { | |
| info.absoluteCenter = { | |
| x: hasCenterX ? constraintCenterX : undefined, | |
| y: hasCenterY ? constraintCenterY : undefined, | |
| } | |
| } | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
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.
Summary
Implements
<constraint />component support for constraining the distance between groups (not just individual components), with optionalcenterX/centerYprops for absolute positioning.Closes #1391
Changes
Extended Constraint Props (
Constraint.ts)centerXandcenterYoptional props toPcbXDistConstraintandPcbYDistConstraintxdist/ydist(lowercase) toxDist/yDist(camelCase)Group Selector Support (
applyComponentConstraintClusters.ts)getIdFromSelector()to resolve group names (e.g..group1) to theirsource_group_id, in addition to componentpcb_component_idabsoluteCentertoClusterInfo— whencenterX/centerYis specified, the cluster is placed at that absolute position instead of wherever the packer places itGroup Transform Support (
applyPackOutput.ts)pcb_componentmembers andpcb_groupmembersabsoluteCenterwhen available for cluster positioningJSX Types (
intrinsic-jsx.ts)constraintelement type to includecenterXandcenterYpropsUsage
Tests
constraint between groups with xDist and centerX— verifies 20mm distance between groups and midpoint at x=0constraint between components with xDist and centerX— verifies 10mm distance between components and midpoint at x=0/claim #1391