ManimCommunity / ManimCommunity/manim

`Text` Mobject does not recursively propagation to submodules key `kwargs` arguments

Open
#4,667 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
40.9k
Forks
3.1k
Avg merge
3d 12h
Merged PRs (30d)
25

Description

## Description of bug / unexpected behavior

Some kwargs parameters for `Text` do not get propagated to it's children in construction, making it so that things like `z_order` does not work as intended and only the top level `Text` object has the proper `z_order` but the actual letters do not have the `z_order` that is properly set. This is also true with the `opacity` parameter.

The issue was found in following Discord help-forum thread https://discord.com/channels/1453870851807117363/1485929006254657557

## Expected behavior

```python
def construct(self):
self.play(FadeIn(Dot(ORIGIN, radius=0.2, color=BLUE, z_index=1)), FadeIn(Text("A", font_size=18, color=WHITE, weight=BOLD, z_index=3)))
```

We should always be able to see the label; however, as you can see the label goes behind the dot. As such this is because the `z_order` is not being applied.

So there's a class of mobjects which should probably propagate their style to their submobjects, but there are also classes which shouldn't (Axes comes to mind).

## How to reproduce the issue

Code for reproducing the problem

The problems:

```python
def construct(self):
self.play(FadeIn(Dot(ORIGIN, radius=0.2, color=BLUE, z_index=1)), FadeIn(Text("A", font_size=18, color=WHITE, weight=BOLD, z_index=3)))
```

Seems like setting z index in the constructor doesn't work, but setting it explicitly with a method does:
```py
def construct(self):
dot = Dot(ORIGIN, radius=0.2, color=BLUE).set_z_index(1)
label = Text("A", font_size=18, color=WHITE, weight=BOLD).set_z_index(3)
self.play(FadeIn(dot), FadeIn(label))
self.wait()
```

If I had to guess, it might be because setting z index in the constructor doesn't set it recursively, and so the submobjects of the Text object may not have their z index updated at creation?
(and since the circle has z index 1, it is rendered above the text submobjects which probably have z index 0)

providing z_index in the kwargs of a mobject constructor only affects the top-level mobject. When we explicitly make the label one layer deep, it works:

```python
def construct(self):
dot = Dot(ORIGIN, radius=0.5, color=BLUE, z_index=1)
label = Text("A", font_size=36, fill_color=WHITE, weight=BOLD, z_index=3)
label.set_points(label[0].points).remove(label[0]) # flatten
self.play(FadeIn(dot), FadeIn(label))
self.wait()
```

there was a similar bug for setting opacity from the kwargs
```python
def construct(self):
self.play(FadeIn(Text("A", font_size=18, color=WHITE, weight=BOLD, opacity=0)))
```

Which can get fixed by doing it in the following manner:

```python
def construct(self):
self.play(FadeIn(Text("A", font_size=18, color=WHITE, weight=BOLD).set_opacity(0)))
```

## Additional media files

Images/GIFs

https://github.com/user-attachments/assets/124ed03b-542b-4294-bac2-a7664dc090ef

## System specifications

System Details

- OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): Discord Manim renderer any OS
- Python version (`python/py/python3 --version`): Unknown for Discord Manim renderer
- Installed modules (provide output from `pip list`): Unknown for Discord Manim renderer

## Additional comments

Contributor guide

Open the contributing guide

Research direction

Start with the Text construction path and how constructor kwargs are applied to its submobjects. Reproduce the z_index and opacity examples from the issue, then identify which style kwargs should propagate for Text without applying the same behavior to classes such as Axes. Done means the reported Text examples behave like their explicit setter equivalents and are covered by regression tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.