Generic tree node with parent/child relationships and hierarchy change signals.

The type parameter represents the concrete node type stored in the hierarchy. This is the base structural container used by higher-level scene and markup objects in the engine.

The class is intentionally small: - it manages parent and child ownership - it provides tag-based lookup helpers - it emits hierarchy change signals

It does not define transform, rendering, or update behavior on its own.

Constructor

new()

Creates an empty node with no parent and no children.

Variables

@:value(new s.shortcut.signals.Signal([]))read onlychildAdded:Signal<(child:T) ‑> Void> = new s.shortcut.signals.Signal([])

Fired when a direct child is added.

@:value(new s.shortcut.signals.Signal([]))read onlychildRemoved:Signal<(child:T) ‑> Void> = new s.shortcut.signals.Signal([])

Fired when a direct child is removed.

read onlychildren:ObjectList<T>

Direct child nodes.

The list manages ownership: adding a node here updates its parent, and removing it detaches it.

@:value(new s.shortcut.signals.Signal([]))read onlydescendantAdded:Signal<(descendant:T) ‑> Void> = new s.shortcut.signals.Signal([])

Fired when any descendant is added anywhere below this node.

@:value(new s.shortcut.signals.Signal([]))read onlydescendantRemoved:Signal<(descendant:T) ‑> Void> = new s.shortcut.signals.Signal([])

Fired when any descendant is removed anywhere below this node.

parent:T

Parent node or null if this node is detached.

Assigning this field re-parents the node. Most code should use setParent, removeParent, addChild, or removeChild instead of mutating internal storage directly.

@:value(new s.shortcut.signals.Signal([]))read onlyparentChanged:Signal<(previous:T) ‑> Void> = new s.shortcut.signals.Signal([])

Fired when the parent changes.

tag:String

Optional application-defined tag used for lookup.

Tags are not required to be unique. Methods such as getChild, getChildren, and findChild use this field for simple structural queries.

Methods

addChild(value:T):T

Adds a direct child.

If the child already belongs to another parent, it is re-parented.

Parameters:

value

Child node to add.

Returns:

The added child or null if it is already present.

findChild(tag:String):T

Searches the full descendant tree for the first node with the given tag.

Search order is depth-first in child order.

Parameters:

tag

Tag to match.

Returns:

The found descendant or null.

getChild(tag:String):T

Returns the first direct child with the given tag.

This only checks direct children and does not recurse into descendants.

Parameters:

tag

Tag to match.

Returns:

The found child or null.

getChildren(tag:String):Array<T>

Returns all direct children with the given tag.

This only checks direct children and does not recurse into descendants.

Parameters:

tag

Tag to match.

Returns:

Matching direct children.

iterator():ArrayIterator<T>

Returns an iterator over direct children.

offChildAdded(slot:(child:T) ‑> Void):Bool

offChildRemoved(slot:(child:T) ‑> Void):Bool

offDescendantAdded(slot:(descendant:T) ‑> Void):Bool

offDescendantRemoved(slot:(descendant:T) ‑> Void):Bool

offParentChanged(slot:(previous:T) ‑> Void):Bool

onChildAdded(slot:(child:T) ‑> Void):(child:T) ‑> Void

onChildRemoved(slot:(child:T) ‑> Void):(child:T) ‑> Void

onDescendantAdded(slot:(descendant:T) ‑> Void):(descendant:T) ‑> Void

onDescendantRemoved(slot:(descendant:T) ‑> Void):(descendant:T) ‑> Void

onParentChanged(slot:(previous:T) ‑> Void):(previous:T) ‑> Void

removeChild(value:T):Bool

Removes a direct child.

Parameters:

value

Child node to remove.

Returns:

true if the child was removed.

removeParent():Void

Detaches this node from its parent.

setParent(value:T):Void

Sets the parent node.

This is equivalent to adding the node to value.children.

Parameters:

value

New parent node.

toString():String

Returns a debug-friendly string containing the class name and tag.

traverse(f:T ‑> Void):T

Traverses all descendants depth-first and applies a callback.

The callback receives each descendant, not the root node itself.

Parameters:

f

Callback invoked for each descendant.

Returns:

This node.