mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Have DecimalMobject use Text instead of Tex
This commit is contained in:
parent
73edeaa153
commit
c292046913
1 changed files with 14 additions and 16 deletions
|
@ -1,10 +1,12 @@
|
||||||
from manimlib.constants import *
|
from manimlib.constants import *
|
||||||
from manimlib.mobject.svg.tex_mobject import SingleStringTex
|
from manimlib.mobject.svg.tex_mobject import SingleStringTex
|
||||||
from manimlib.mobject.svg.tex_mobject import tex_string_to_mob_map
|
from manimlib.mobject.svg.text_mobject import Text
|
||||||
from manimlib.mobject.svg.tex_mobject import SCALE_FACTOR_PER_FONT_POINT
|
|
||||||
from manimlib.mobject.types.vectorized_mobject import VMobject
|
from manimlib.mobject.types.vectorized_mobject import VMobject
|
||||||
|
|
||||||
|
|
||||||
|
string_to_mob_map = {}
|
||||||
|
|
||||||
|
|
||||||
class DecimalNumber(VMobject):
|
class DecimalNumber(VMobject):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"stroke_width": 0,
|
"stroke_width": 0,
|
||||||
|
@ -34,7 +36,7 @@ class DecimalNumber(VMobject):
|
||||||
|
|
||||||
# Add non-numerical bits
|
# Add non-numerical bits
|
||||||
if self.show_ellipsis:
|
if self.show_ellipsis:
|
||||||
self.add(self.string_to_mob("\\dots"))
|
self.add(self.string_to_mob("\\dots", SingleStringTex))
|
||||||
|
|
||||||
if num_string.startswith("-"):
|
if num_string.startswith("-"):
|
||||||
minus = self.submobjects[0]
|
minus = self.submobjects[0]
|
||||||
|
@ -44,7 +46,7 @@ class DecimalNumber(VMobject):
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.unit is not None:
|
if self.unit is not None:
|
||||||
self.unit_sign = self.string_to_mob(self.unit)
|
self.unit_sign = self.string_to_mob(self.unit, SingleStringTex)
|
||||||
self.add(self.unit_sign)
|
self.add(self.unit_sign)
|
||||||
|
|
||||||
self.arrange(
|
self.arrange(
|
||||||
|
@ -55,7 +57,7 @@ class DecimalNumber(VMobject):
|
||||||
# Handle alignment of parts that should be aligned
|
# Handle alignment of parts that should be aligned
|
||||||
# to the bottom
|
# to the bottom
|
||||||
for i, c in enumerate(num_string):
|
for i, c in enumerate(num_string):
|
||||||
if c == "-" and len(num_string) > i + 1:
|
if c == "–" and len(num_string) > i + 1:
|
||||||
self[i].align_to(self[i + 1], UP)
|
self[i].align_to(self[i + 1], UP)
|
||||||
self[i].shift(self[i + 1].get_height() * DOWN / 2)
|
self[i].shift(self[i + 1].get_height() * DOWN / 2)
|
||||||
elif c == ",":
|
elif c == ",":
|
||||||
|
@ -79,6 +81,7 @@ class DecimalNumber(VMobject):
|
||||||
num_string = "+" + num_string[1:]
|
num_string = "+" + num_string[1:]
|
||||||
else:
|
else:
|
||||||
num_string = num_string[1:]
|
num_string = num_string[1:]
|
||||||
|
num_string = num_string.replace("-", "–")
|
||||||
return num_string
|
return num_string
|
||||||
|
|
||||||
def init_data(self):
|
def init_data(self):
|
||||||
|
@ -88,17 +91,12 @@ class DecimalNumber(VMobject):
|
||||||
def get_font_size(self):
|
def get_font_size(self):
|
||||||
return self.data["font_size"][0]
|
return self.data["font_size"][0]
|
||||||
|
|
||||||
def string_to_mob(self, tex_string):
|
def string_to_mob(self, string, mob_class=Text):
|
||||||
# Could just call SingleStringTex, and there is
|
if string not in string_to_mob_map:
|
||||||
# some code repetition here by looking to the same cache,
|
string_to_mob_map[string] = mob_class(string, font_size=1)
|
||||||
# but it keeps things from initializing a new object
|
mob = string_to_mob_map[string].copy()
|
||||||
# more than is necessary
|
mob.scale(self.get_font_size())
|
||||||
if tex_string in tex_string_to_mob_map:
|
return mob
|
||||||
result = tex_string_to_mob_map[tex_string].copy()
|
|
||||||
result.scale(self.get_font_size() * SCALE_FACTOR_PER_FONT_POINT)
|
|
||||||
return result
|
|
||||||
else:
|
|
||||||
return SingleStringTex(tex_string, font_size=self.get_font_size())
|
|
||||||
|
|
||||||
def get_formatter(self, **kwargs):
|
def get_formatter(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue