Skip to content

feat(shared): add Anchor utility for relative element positioning - #184

Open
zndxcvbn wants to merge 3 commits into
mainfrom
feat-anchor
Open

zndxcvbn wants to merge 3 commits into
mainfrom
feat-anchor

Conversation

@zndxcvbn

@zndxcvbn zndxcvbn commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

Another innovation in the field of dynamic layout: Anchor (Relative Positioning).

Sometimes globally positioning elements in ActionScript code can be inconvenient, requiring manual offset adjustments. Sometimes buttons like ComboBoxes with drop-down menus are easier to simply bind to the button. Or, for example, if you have a dynamic background width and need to attach an element to it, the element will be attached, eliminating the need to write any further logic for positioning it as the background width changes.

Example:

this.BlueBox.Anchor(this.RedBox, "TL", "C", 0, 0, false);
Frame 1223

Summary by CodeRabbit

  • New Features
    • Introduced anchor-based alignment functionality for positioning UI elements using anchor points
    • Supports custom offset adjustments for X/Y coordinate fine-tuning
    • Includes optional frame-deferred computation for coordinate calculation optimization

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@zndxcvbn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 51 minutes and 57 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f46aa8ee-e1d4-46c0-bb49-3f36d61c1d33

📥 Commits

Reviewing files that changed from the base of the PR and between 1836cdc and 2a63255.

📒 Files selected for processing (1)
  • source/actionscript/Vanilla/Shared/GlobalFunc.as
📝 Walkthrough

Walkthrough

Introduces anchor-based alignment functionality for Scaleform MovieClips. A new static method and injected prototype method enable repositioning a target MovieClip by aligning specified anchor points between source and target clips, with optional frame deferral and coordinate space conversions.

Changes

Cohort / File(s) Summary
Anchor Alignment Feature
source/actionscript/Vanilla/Shared/GlobalFunc.as
Adds AddAnchorFunction() static method that injects a MovieClip.prototype.Anchor() method, alongside a static Anchor() routine. Implements anchor parsing from string identifiers, frame deferral via temporary helper clip, and coordinate transformation logic to align source and target anchor points. Includes private helpers for anchor ID conversion and global/local anchor point extraction from clip bounds.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant TargetClip as Target MovieClip
    participant SourceClip as Source MovieClip
    participant ParentCoordSpace as Parent Coordinate Space
    
    Caller->>TargetClip: Anchor(source, targetAnchor, sourceAnchor, offsetX, offsetY, waitNextFrame)
    TargetClip->>TargetClip: Parse anchor strings to IDs
    alt waitNextFrame is true
        TargetClip->>TargetClip: Create temporary helper clip<br/>Schedule deferred execution
        TargetClip->>TargetClip: Execute on next frame
    end
    TargetClip->>SourceClip: Compute source anchor in global coordinates
    SourceClip->>SourceClip: Extract bounds & calculate anchor point
    SourceClip-->>TargetClip: Return global anchor position
    TargetClip->>TargetClip: Apply offsetX/offsetY adjustment
    TargetClip->>TargetClip: Compute target anchor in local bounds space
    TargetClip->>ParentCoordSpace: Convert points between coordinate spaces
    ParentCoordSpace-->>TargetClip: Return converted coordinates
    TargetClip->>TargetClip: Update _x/_y to align anchors
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(shared): add Anchor utility for relative element positioning' accurately describes the main change: introducing a new Anchor utility feature for positioning elements relative to each other.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
source/actionscript/Vanilla/Shared/GlobalFunc.as (1)

370-385: Make prototype injection idempotent.

If AddAnchorFunction() runs more than once, Line 384 redefines MovieClip.prototype.Anchor each time. Add a guard to avoid repeated mutation of the global prototype.

♻️ Proposed fix
 static function AddAnchorFunction() {
+    if (MovieClip.prototype.Anchor != undefined) return;
     if (Shared.GlobalFunc._deferCounter == undefined) Shared.GlobalFunc._deferCounter = 0;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@source/actionscript/Vanilla/Shared/GlobalFunc.as` around lines 370 - 385, Add
an idempotency guard in AddAnchorFunction so it doesn't reassign
MovieClip.prototype.Anchor on repeated calls: check a unique flag (e.g.,
Shared.GlobalFunc._anchorAdded) or test if MovieClip.prototype.Anchor already
exists at the start of AddAnchorFunction and return early if set; if you set the
flag, assign it after the first successful prototype injection. This ensures
MovieClip.prototype.Anchor (the Anchor method) is only defined once and prevents
repeated global prototype mutation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@source/actionscript/Vanilla/Shared/GlobalFunc.as`:
- Around line 430-438: The code currently only validates destPt.x before
applying offsets and transforming targetPt, which can allow destPt.y or
targetPt.x/targetPt.y to be NaN and later set _x/_y to invalid values; update
the logic around Shared.GlobalFunc._getAnchorPointGlobal and
Shared.GlobalFunc._getAnchorPointLocal to validate destPt and targetPt fully:
check destPt exists and that neither destPt.x nor destPt.y is NaN (after
applying offsetX/offsetY) and call target.localToGlobal(targetPt) only if
targetPt exists and its x and y are finite (use isNaN or similar), and bail out
early if any coordinate is invalid before assigning to _x/_y. Ensure you
reference destPt, targetPt, _getAnchorPointGlobal, _getAnchorPointLocal, and
target.localToGlobal in your changes so the validation surrounds the transform
and assignment steps.

---

Nitpick comments:
In `@source/actionscript/Vanilla/Shared/GlobalFunc.as`:
- Around line 370-385: Add an idempotency guard in AddAnchorFunction so it
doesn't reassign MovieClip.prototype.Anchor on repeated calls: check a unique
flag (e.g., Shared.GlobalFunc._anchorAdded) or test if
MovieClip.prototype.Anchor already exists at the start of AddAnchorFunction and
return early if set; if you set the flag, assign it after the first successful
prototype injection. This ensures MovieClip.prototype.Anchor (the Anchor method)
is only defined once and prevents repeated global prototype mutation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8b59a5f7-78a6-495c-8938-1c8d9051eda9

📥 Commits

Reviewing files that changed from the base of the PR and between 1523d12 and 1836cdc.

📒 Files selected for processing (1)
  • source/actionscript/Vanilla/Shared/GlobalFunc.as

Comment thread source/actionscript/Vanilla/Shared/GlobalFunc.as
@zndxcvbn zndxcvbn added deferred Will be considered at a later date labels May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deferred Will be considered at a later date

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant