feat: add aligned_to parameter to Mobject.arrange()#4652
Open
coder999999999 wants to merge 2 commits intoManimCommunity:mainfrom
Open
feat: add aligned_to parameter to Mobject.arrange()#4652coder999999999 wants to merge 2 commits intoManimCommunity:mainfrom
coder999999999 wants to merge 2 commits intoManimCommunity:mainfrom
Conversation
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
for more information, see https://pre-commit.ci
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.
Overview: What does this pull request change?
Adds an optional
aligned_toparameter toMobject.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:
aligned_to-th submobject before arrangingaligned_to-th submobject returns to its original positionWhen
aligned_tois set,centeris ignored since the group position is determined by the anchor mobject. Supports negative indexing (e.g.,aligned_to=-1for the last element).Further Information and Comments