2022-12-20 14:48:54 -08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-12-20 15:08:54 -08:00
|
|
|
from manimlib.constants import MED_SMALL_BUFF, WHITE, GREY_C
|
2022-12-20 14:48:54 -08:00
|
|
|
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
|
2022-12-20 15:08:54 -08:00
|
|
|
from manimlib.mobject.types.vectorized_mobject import VGroup
|
2022-12-21 13:18:20 -08:00
|
|
|
from manimlib.mobject.svg.tex_mobject import TexText
|
2022-12-20 14:48:54 -08:00
|
|
|
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
2022-12-20 15:08:54 -08:00
|
|
|
from manimlib.typing import ManimColor, Vect3
|
2022-12-20 14:48:54 -08:00
|
|
|
|
|
|
|
|
2022-12-20 15:08:54 -08:00
|
|
|
class BulletedList(VGroup):
|
2022-12-20 14:48:54 -08:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
*items: str,
|
|
|
|
buff: float = MED_LARGE_BUFF,
|
2022-12-20 15:08:54 -08:00
|
|
|
aligned_edge: Vect3 = LEFT,
|
2022-12-20 14:48:54 -08:00
|
|
|
**kwargs
|
2022-12-20 15:08:54 -08:00
|
|
|
):
|
|
|
|
labelled_content = [R"\item " + item for item in items]
|
|
|
|
tex_string = "\n".join([
|
|
|
|
R"\begin{itemize}",
|
|
|
|
*labelled_content,
|
|
|
|
R"\end{itemize}"
|
|
|
|
])
|
2022-12-21 13:18:20 -08:00
|
|
|
tex_text = TexText(tex_string, isolate=labelled_content, **kwargs)
|
2022-12-20 15:08:54 -08:00
|
|
|
lines = (tex_text.select_part(part) for part in labelled_content)
|
2022-12-20 14:48:54 -08:00
|
|
|
|
2022-12-20 15:08:54 -08:00
|
|
|
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))
|
2022-12-20 14:48:54 -08:00
|
|
|
|
|
|
|
|
2022-12-21 13:18:20 -08:00
|
|
|
class TexTextFromPresetString(TexText):
|
2022-12-20 14:48:54 -08:00
|
|
|
tex: str = ""
|
|
|
|
default_color: ManimColor = WHITE
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super().__init__(
|
|
|
|
self.tex,
|
|
|
|
color=kwargs.pop("color", self.default_color),
|
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-12-21 13:18:20 -08:00
|
|
|
class Title(TexText):
|
2022-12-20 14:48:54 -08:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
*text_parts: str,
|
2022-12-20 15:08:54 -08:00
|
|
|
font_size: int = 72,
|
2022-12-20 14:48:54 -08:00
|
|
|
include_underline: bool = True,
|
|
|
|
underline_width: float = FRAME_WIDTH - 2,
|
|
|
|
# This will override underline_width
|
|
|
|
match_underline_width_to_text: bool = False,
|
|
|
|
underline_buff: float = SMALL_BUFF,
|
|
|
|
underline_style: dict = dict(stroke_width=2, stroke_color=GREY_C),
|
|
|
|
**kwargs
|
|
|
|
):
|
2022-12-20 15:08:54 -08:00
|
|
|
super().__init__(*text_parts, font_size=font_size, **kwargs)
|
|
|
|
self.to_edge(UP, buff=MED_SMALL_BUFF)
|
2022-12-20 14:48:54 -08:00
|
|
|
if include_underline:
|
|
|
|
underline = Line(LEFT, RIGHT, **underline_style)
|
|
|
|
underline.next_to(self, DOWN, buff=underline_buff)
|
|
|
|
if match_underline_width_to_text:
|
|
|
|
underline.match_width(self)
|
|
|
|
else:
|
|
|
|
underline.set_width(underline_width)
|
|
|
|
self.add(underline)
|
|
|
|
self.underline = underline
|