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

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

#include "donner/svg/components/TreeComponent.h"

Public Member Functions

 TreeComponent (ElementType type, const 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.
 
ElementType type () const
 Get the parsed element type as an enum.
 
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 SVG 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::svg::components::TreeComponent::TreeComponent ( ElementType type,
const XMLQualifiedNameRef & tagName )
inline

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

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

Member Function Documentation

◆ appendChild()

void donner::svg::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::svg::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::svg::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::svg::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::svg::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: