Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::components::TreeComponent Class Reference

Stores the tree structure for an XML element, such as the parent, children, and siblings. More...

#include "donner/base/xml/components/TreeComponent.h"

Public Member Functions

 TreeComponent (const xml::XMLQualifiedNameRef &tagName)
 Construct a new tree component with the given type and tagName.
 
void insertBefore (Registry &registry, Entity newNode, Entity referenceNode)
 Insert newNode as a child, before referenceNode.
 
void appendChild (Registry &registry, Entity child)
 Append child as a child of the current node.
 
void replaceChild (Registry &registry, Entity newChild, Entity oldChild)
 Replace oldChild with newChild in the tree, removing oldChild and inserting newChild in its place.
 
void removeChild (Registry &registry, Entity child)
 Remove child from this node.
 
void remove (Registry &registry)
 Remove this node from its parent, if it has one.
 
xml::XMLQualifiedNameRef tagName () const
 Get the qualified tag name of the element, e.g. "svg".
 
Entity parent () const
 Get the parent of this node, if it has one. Returns entt::null if this is the root.
 
Entity firstChild () const
 Get the first child of this node, if it has one. Returns entt::null if this has no children.
 
Entity lastChild () const
 Get the last child of this node, if it has one. Returns entt::null if this has no children.
 
Entity previousSibling () const
 Get the previous sibling of this node, if it has one. Returns entt::null if this is the first child.
 
Entity nextSibling () const
 Get the next sibling of this node, if it has one. Returns entt::null if this is the last child.
 

Detailed Description

Stores the tree structure for an XML element, such as the parent, children, and siblings.

This component is added to all entities that are part of the SVG tree, and is used to navigate the tree structure.

Constructor & Destructor Documentation

◆ TreeComponent()

donner::components::TreeComponent::TreeComponent ( const xml::XMLQualifiedNameRef & tagName)
inlineexplicit

Construct a new tree component with the given type and tagName.

Parameters
tagNameThe qualified tag name of the element, which may include a namespace. (e.g. "svg")

Member Function Documentation

◆ appendChild()

void donner::components::TreeComponent::appendChild ( Registry & registry,
Entity child )

Append child as a child of the current node.

If child is already in the tree, it is first removed from its parent. However, if inserting the child will create a cycle, the behavior is undefined.

Parameters
registryEntity registry.
childNode to append.

◆ insertBefore()

void donner::components::TreeComponent::insertBefore ( Registry & registry,
Entity newNode,
Entity referenceNode )

Insert newNode as a child, before referenceNode.

If referenceNode is entt::null, append the child.

If newNode is already in the tree, it is first removed from its parent. However, if inserting the child will create a cycle, the behavior is undefined.

Parameters
registryEntity registry.
newNodeNew node to insert.
referenceNodeNullable, a child of this node to insert newNode before. Must be a child of the current node.

◆ remove()

void donner::components::TreeComponent::remove ( Registry & registry)

Remove this node from its parent, if it has one.

Has no effect if this has no parent.

Parameters
registryEntity registry.

◆ removeChild()

void donner::components::TreeComponent::removeChild ( Registry & registry,
Entity child )

Remove child from this node.

Parameters
registryEntity registry.
childChild to remove, must be a child of the current node.

◆ replaceChild()

void donner::components::TreeComponent::replaceChild ( Registry & registry,
Entity newChild,
Entity oldChild )

Replace oldChild with newChild in the tree, removing oldChild and inserting newChild in its place.

If newChild is already in the tree, it is first removed from its parent. However, if inserting the child will create a cycle, the behavior is undefined.

Parameters
registryEntity registry.
newChildNew child to insert.
oldChildOld child to remove, must be a child of the current node.

The documentation for this class was generated from the following files: