Allow Mobject.remove to remove any family member, not just immediate submobjects

This commit is contained in:
Grant Sanderson 2023-01-27 15:15:16 -08:00
parent 1f6363821b
commit d5b1a1725d

View file

@ -408,14 +408,15 @@ class Mobject(object):
self.assemble_family() self.assemble_family()
return self return self
def remove(self, *mobjects: Mobject, reassemble: bool = True): def remove(self, *to_remove: Mobject, reassemble: bool = True):
for mobject in mobjects: for parent in self.get_family():
if mobject in self.submobjects: for child in to_remove:
self.submobjects.remove(mobject) if child in parent.submobjects:
if self in mobject.parents: parent.submobjects.remove(child)
mobject.parents.remove(self) if parent in child.parents:
if reassemble: child.parents.remove(parent)
self.assemble_family() if reassemble:
parent.assemble_family()
return self return self
def add_to_back(self, *mobjects: Mobject): def add_to_back(self, *mobjects: Mobject):