Skip to content

Fix code window button animations#4698

Open
GniLudio wants to merge 1 commit intoManimCommunity:mainfrom
GniLudio:main
Open

Fix code window button animations#4698
GniLudio wants to merge 1 commit intoManimCommunity:mainfrom
GniLudio:main

Conversation

@GniLudio
Copy link
Copy Markdown

@GniLudio GniLudio commented Apr 17, 2026

Overview: What does this pull request change?

Fixes animations on the window buttons of a Code object.

The buttons are now a direct child of the Code object (before it was the child of the Code.background object).
Furthermore, the buttons can now be accessed through the Code.buttons field.

Old Behavior Current Behavior
FadeOutOld.mp4
FadeOutNew.mp4
ShiftOld.mp4
ShiftNew.mp4
ScaleInPlaceOld.mp4
ScaleInPlaceNew.mp4

Rendered using:

manim code_scenes.py FadeOutOld ShiftOld ScaleInPlaceOld
manim code_scenes.py FadeOutNew ShiftNew ScaleInPlaceNew

code_scenes.py

from manim import config
from manim.animation.fading import FadeOut
from manim.animation.transform import ScaleInPlace
from manim.constants import UP
from manim.mobject.text.code_mobject import Code
from manim.scene.scene import Scene

config.frame_width = config.frame_height = 8

code = Code(
    code_string="""\
def main() -> None:
print("Hello World!")
if __name__ == "__main__":
    main()\
""",
    background="window",
)

class FadeOutOld(Scene):
    def construct(self):
        buttons = code.background[1]
        self.add(code)
        self.play(FadeOut(buttons))

class FadeOutNew(Scene):
    def construct(self):
        buttons = code.buttons
        self.add(code)
        self.play(FadeOut(buttons))

class ShiftOld(Scene):
    def construct(self):
        buttons = code.background[1]
        self.add(code)
        self.play(buttons.animate.shift(UP))

class ShiftNew(Scene):
    def construct(self):
        buttons = code.buttons
        self.add(code)
        self.play(buttons.animate.shift(UP))

class ScaleInPlaceOld(Scene):
    def construct(self):
        buttons = code.background[1]
        self.add(code)
        self.play(ScaleInPlace(buttons, scale_factor=2))

class ScaleInPlaceNew(Scene):
    def construct(self):
        buttons = code.buttons
        self.add(code)
        self.play(ScaleInPlace(buttons, scale_factor=2))

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

Links to added or changed documentation pages

Further Information and Comments

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

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.

1 participant