Skip to content

Commit fd8ab62

Browse files
henrikmidtibypre-commit-ci[bot]chopan050
authored
Fix BraceLabel.change_label() and document BraceText (#4347)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Francisco Manríquez Novoa <[email protected]>
1 parent 047db45 commit fd8ab62

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

manim/mobject/svg/brace.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,10 @@ def shift_brace(self, obj: Mobject, **kwargs: Any) -> Self:
273273
return self
274274

275275
def change_label(self, *text: str, **kwargs: Any) -> Self:
276+
self.remove(self.label)
276277
self.label = self.label_constructor(*text, **kwargs) # type: ignore[arg-type]
277278
self.brace.put_at_tip(self.label)
279+
self.add(self.label)
278280
return self
279281

280282
def change_brace_label(self, obj: Mobject, *text: str, **kwargs: Any) -> Self:
@@ -284,6 +286,50 @@ def change_brace_label(self, obj: Mobject, *text: str, **kwargs: Any) -> Self:
284286

285287

286288
class BraceText(BraceLabel):
289+
"""Create a brace with a text label attached.
290+
291+
Parameters
292+
----------
293+
obj
294+
The mobject adjacent to which the brace is placed.
295+
text
296+
The label text.
297+
brace_direction
298+
The direction of the brace. By default ``DOWN``.
299+
label_constructor
300+
A class or function used to construct a mobject representing
301+
the label. By default :class:`~.Text`.
302+
font_size
303+
The font size of the label, passed to the ``label_constructor``.
304+
buff
305+
The buffer between the mobject and the brace.
306+
brace_config
307+
Arguments to be passed to :class:`.Brace`.
308+
kwargs
309+
Additional arguments to be passed to :class:`~.VMobject`.
310+
311+
312+
Examples
313+
--------
314+
.. manim:: BraceTextExample
315+
:save_last_frame:
316+
317+
class BraceTextExample(Scene):
318+
def construct(self):
319+
s1 = Square().move_to(2*LEFT)
320+
self.add(s1)
321+
br1 = BraceText(s1, "Label")
322+
self.add(br1)
323+
324+
s2 = Square().move_to(2*RIGHT)
325+
self.add(s2)
326+
br2 = BraceText(s2, "Label")
327+
328+
br2.change_label("new")
329+
self.add(br2)
330+
self.wait(0.1)
331+
"""
332+
287333
def __init__(
288334
self,
289335
obj: Mobject,

0 commit comments

Comments
 (0)