MCPcopy Create free account
hub / github.com/cogentcore/core / New

Function New

tree/admin.go:22–34  ·  view source on GitHub ↗

admin.go has infrastructure code outside of the [Node] interface. New returns a new node of the given type with the given optional parent. If the name is unspecified, it defaults to the ID (kebab-case) name of the type, plus the [Node.NumLifetimeChildren] of the parent.

(parent ...Node)

Source from the content-addressed store, hash-verified

20// If the name is unspecified, it defaults to the ID (kebab-case) name of
21// the type, plus the [Node.NumLifetimeChildren] of the parent.
22func New[T NodeValue](parent ...Node) *T { //yaegi:add
23 n := new(T)
24 ni := any(n).(Node)
25 InitNode(ni)
26 if len(parent) == 0 {
27 ni.AsTree().SetName(ni.AsTree().NodeType().IDName)
28 return n
29 }
30 p := parent[0]
31 p.AsTree().Children = append(p.AsTree().Children, ni)
32 SetParent(ni, p)
33 return n
34}
35
36// NewOfType returns a new node of the given [types.Type] with the given optional parent.
37// If the name is unspecified, it defaults to the ID (kebab-case) name of

Callers

nothing calls this directly

Calls 5

InitNodeFunction · 0.85
SetParentFunction · 0.85
NodeTypeMethod · 0.80
SetNameMethod · 0.65
AsTreeMethod · 0.65

Tested by

no test coverage detected