Skip to content

feat: add aligned_to parameter to Mobject.arrange()#4652

Open
coder999999999 wants to merge 2 commits intoManimCommunity:mainfrom
coder999999999:feat/arrange-aligned-to-4183
Open

feat: add aligned_to parameter to Mobject.arrange()#4652
coder999999999 wants to merge 2 commits intoManimCommunity:mainfrom
coder999999999:feat/arrange-aligned-to-4183

Conversation

@coder999999999
Copy link
Copy Markdown

Overview: What does this pull request change?

Adds an optional aligned_to parameter to Mobject.arrange() that specifies the index of the submobject that should remain at its current position after arranging. All other submobjects are rearranged around it.

Motivation and Explanation: Why and how do your changes improve the library?

Closes #4183

Currently, arrange() always uses the first submobject as the implicit anchor and then optionally centers the result. This makes it difficult to arrange submobjects while keeping a specific one fixed in place (e.g., for reverse-arrange or anchoring to a middle element).

Following @behackl's suggestion, the implementation:

  1. Remembers the position of the aligned_to-th submobject before arranging
  2. Performs the normal arrange (m2.next_to(m1, ...))
  3. Shifts the entire group so the aligned_to-th submobject returns to its original position

When aligned_to is set, center is ignored since the group position is determined by the anchor mobject. Supports negative indexing (e.g., aligned_to=-1 for the last element).

Further Information and Comments

  • Added PARAMETERS section to the docstring
  • Added 4 unit tests covering: default behavior unchanged, aligned_to with last element, aligned_to with first element, negative indexing

coder999999999 and others added 2 commits March 23, 2026 18:36
Add an optional aligned_to parameter to Mobject.arrange() that
specifies the index of the submobject that should remain at its
current position after arranging. All other submobjects are
rearranged around it.

This allows keeping any submobject (not just the first) as the
fixed anchor point when arranging, which is useful for reverse-
arrange and other layout patterns.

Implementation follows the approach suggested by @behackl in ManimCommunity#4183:
remember the position of the aligned_to-th mobject, arrange normally,
then shift the group so the aligned_to-th mobject returns to its
original position.

When aligned_to is set, the center parameter is ignored since the
group position is determined by the anchor mobject.

Closes ManimCommunity#4183
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.

Select the last object of the group as the alignment target when using Mobject.arrange()

1 participant