mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Clean up special_tex contents, make each class use MTexText instead of TexText
This commit is contained in:
parent
3293f72adc
commit
0d525baf29
1 changed files with 27 additions and 41 deletions
|
@ -1,61 +1,48 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from manimlib.constants import WHITE, GREY_C
|
||||
from manimlib.constants import MED_SMALL_BUFF, WHITE, GREY_C
|
||||
from manimlib.constants import DOWN, LEFT, RIGHT, UP
|
||||
from manimlib.constants import FRAME_WIDTH
|
||||
from manimlib.constants import MED_LARGE_BUFF, SMALL_BUFF
|
||||
from manimlib.mobject.geometry import Line
|
||||
from manimlib.mobject.svg.tex_mobject import Tex, TexText
|
||||
from manimlib.mobject.svg.mtex_mobject import MTex, MTexText
|
||||
from manimlib.mobject.types.vectorized_mobject import VGroup
|
||||
from manimlib.mobject.svg.mtex_mobject import MTexText
|
||||
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from manimlib.typing import ManimColor
|
||||
from manimlib.typing import ManimColor, Vect3
|
||||
|
||||
|
||||
|
||||
class BulletedList(TexText):
|
||||
class BulletedList(VGroup):
|
||||
def __init__(
|
||||
self,
|
||||
*items: str,
|
||||
buff: float = MED_LARGE_BUFF,
|
||||
dot_scale_factor: float = 2.0,
|
||||
alignment: str = "",
|
||||
aligned_edge: Vect3 = LEFT,
|
||||
**kwargs
|
||||
):
|
||||
super().__init__(
|
||||
*(s + R"\\" for s in items),
|
||||
alignment=alignment,
|
||||
**kwargs
|
||||
)
|
||||
for part in self:
|
||||
dot = Tex(R"\cdot").scale(dot_scale_factor)
|
||||
dot.next_to(part[0], LEFT, SMALL_BUFF)
|
||||
part.add_to_back(dot)
|
||||
self.arrange(
|
||||
DOWN,
|
||||
aligned_edge=LEFT,
|
||||
buff=buff
|
||||
)
|
||||
labelled_content = [R"\item " + item for item in items]
|
||||
tex_string = "\n".join([
|
||||
R"\begin{itemize}",
|
||||
*labelled_content,
|
||||
R"\end{itemize}"
|
||||
])
|
||||
tex_text = MTexText(tex_string, isolate=labelled_content, **kwargs)
|
||||
lines = (tex_text.select_part(part) for part in labelled_content)
|
||||
|
||||
def fade_all_but(self, index_or_string: int | str, opacity: float = 0.5) -> None:
|
||||
arg = index_or_string
|
||||
if isinstance(arg, str):
|
||||
part = self.get_part_by_tex(arg)
|
||||
elif isinstance(arg, int):
|
||||
part = self.submobjects[arg]
|
||||
else:
|
||||
raise Exception("Expected int or string, got {0}".format(arg))
|
||||
for other_part in self.submobjects:
|
||||
if other_part is part:
|
||||
other_part.set_fill(opacity=1)
|
||||
else:
|
||||
other_part.set_fill(opacity=opacity)
|
||||
super().__init__(*lines)
|
||||
|
||||
self.arrange(DOWN, buff=buff, aligned_edge=aligned_edge)
|
||||
|
||||
def fade_all_but(self, index: int, opacity: float = 0.25) -> None:
|
||||
for i, part in enumerate(self.submobjects):
|
||||
part.set_fill(opacity=(1.0 if i == index else opacity))
|
||||
|
||||
|
||||
class TexTextFromPresetString(TexText):
|
||||
class TexTextFromPresetString(MTexText):
|
||||
tex: str = ""
|
||||
default_color: ManimColor = WHITE
|
||||
|
||||
|
@ -67,11 +54,11 @@ class TexTextFromPresetString(TexText):
|
|||
)
|
||||
|
||||
|
||||
class Title(TexText):
|
||||
class Title(MTexText):
|
||||
def __init__(
|
||||
self,
|
||||
*text_parts: str,
|
||||
scale_factor: float = 1.0,
|
||||
font_size: int = 72,
|
||||
include_underline: bool = True,
|
||||
underline_width: float = FRAME_WIDTH - 2,
|
||||
# This will override underline_width
|
||||
|
@ -80,9 +67,8 @@ class Title(TexText):
|
|||
underline_style: dict = dict(stroke_width=2, stroke_color=GREY_C),
|
||||
**kwargs
|
||||
):
|
||||
super().__init__(*text_parts, **kwargs)
|
||||
self.scale(scale_factor)
|
||||
self.to_edge(UP)
|
||||
super().__init__(*text_parts, font_size=font_size, **kwargs)
|
||||
self.to_edge(UP, buff=MED_SMALL_BUFF)
|
||||
if include_underline:
|
||||
underline = Line(LEFT, RIGHT, **underline_style)
|
||||
underline.next_to(self, DOWN, buff=underline_buff)
|
||||
|
|
Loading…
Add table
Reference in a new issue