Editor model · class

SceneTree

class SceneTree
import { SceneTree } from '@driftengine/editor';

Properties

NameTypeDescription
selectedSceneNode | nullWhat is selected, or null. Assigning is fine; nothing here caches it.

Accessors

NameTypeDescription
rowsgetreadonly TreeRow[]The rows the last rebuild produced, in the order they draw.

Methods

name

name(node: SceneNode): string

What a node is called. Nodes are node until something names them.

ParameterTypeDescription
nodeSceneNode

setName

setName(node: SceneNode, name: string): void
ParameterTypeDescription
nodeSceneNode
namestring

expanded

expanded(node: SceneNode): boolean

Whether a node's children are showing. Everything starts expanded.

ParameterTypeDescription
nodeSceneNode

setExpanded

setExpanded(node: SceneNode, expanded: boolean): void
ParameterTypeDescription
nodeSceneNode
expandedboolean

toggle

toggle(node: SceneNode): void
ParameterTypeDescription
nodeSceneNode

rebuild

rebuild(root: SceneNode): void

Walk the hierarchy into rows, honouring collapse.

ParameterTypeDescription
rootSceneNode
More

A collapsed node contributes its own row and nothing beneath it, which is what collapsing is; its children keep whatever expansion state they had, so expanding a branch again shows what was showing before rather than a flattened one.

Cheap enough to call every frame, and it allocates nothing once the deepest tree it has seen has been seen.

rowOf

rowOf(node: SceneNode): number

Where a node sits in the last rebuild's rows, or -1.

ParameterTypeDescription
nodeSceneNode

reparent

reparent(child: SceneNode, parent: SceneNode): boolean

Move a node under a new parent. false where the hierarchy refuses.

ParameterTypeDescription
childSceneNode
parentSceneNode
More

The refusal is SceneNode's and is not re-implemented here, which was checked rather than assumed: attachChild already rejects a node as its own child and any ancestor as its own descendant. What this adds is answering rather than throwing, because the caller is a drag in a frame and an exception there takes down the frame somebody is dragging in.

forget

forget(node: SceneNode): void

Forget a node's name and expansion, for a node that has left the tree.

ParameterTypeDescription
nodeSceneNode