nodesnim/nodes/node

Node is the root type of all other nodes.

Types

NodeHandler = proc (self: NodeRef)
NodeEvHandler = proc (self: NodeRef; event: InputEvent)
NodeObj = object of RootObj
  kind*: NodeKind
  type_of_node*: NodeTypes   ## default, gui, 2d or 3d.
  visibility*: Visibility    ## visible, invisible or gone.
  is_ready*: bool            ## true, when scene is ready.
  pausemode*: PauseMode      ## Pause mode, by default is INHERIT.
  name*: string              ## Node name.
  parent*: NodeRef           ## Node parent.
  children*: seq[NodeRef]    ## Node children.
  on_enter*: NodeHandler     ## This called when scene changed.
  on_exit*: NodeHandler      ## This called when exit from the scene.
  on_input*: NodeEvHandler   ## This called on user input.
  on_ready*: NodeHandler     ## This called when the scene changed and the `enter` was called.
  on_process*: NodeHandler   ## This called every frame.
  on_theme_changed*: NodeHandler ## This called when current theme changed.
  
NodeRef = ref NodeObj

Lets

handler_default = proc (self: NodeRef) = discard
event_handler_default = proc (self: NodeRef; event: InputEvent) = discard

Procs

proc Node(name: string = "Node"): NodeRef {...}{.raises: [], tags: [].}
Creates a new Node.

Methods

method addChild(self: NodeRef; child: NodeRef) {...}{.base, raises: [], tags: [].}

Adds new child in current node.

Arguments:

  • child: other node.

See also:

method addChildren(self: NodeRef; childs: varargs[NodeRef]) {...}{.base, raises: [],
    tags: [].}

Adds new child in current node.

Arguments:

  • child: other node.

See also:

method draw(self: NodeRef; w, h: GLfloat) {...}{.base, raises: [], tags: [].}
Draws node. This used in the Window object.
method duplicate(self: NodeRef): NodeRef {...}{.base, raises: [], tags: [].}
Duplicates Node object and create a new Node.
method getChild(self: NodeRef; index: int): NodeRef {...}{.base, raises: [], tags: [].}

Returns child at index position, if available.

Arguments:

  • index: child index.

See also:

method getChildCount(self: NodeRef): int {...}{.base, inline, raises: [], tags: [].}

Returns child count.

See also:

method getChildIndex(self: NodeRef; name: string): int {...}{.base, raises: [],
    tags: [].}

Returns child index or -1, if another node is not the child.

See also:

method getChildIndex(self: NodeRef; child: NodeRef): int {...}{.base, raises: [],
    tags: [].}

Returns child index or -1, if another node is not the child.

See also:

method getChildIter(self: NodeRef): seq[NodeRef] {...}{.base, raises: [Exception],
    tags: [RootEffect].}
Returns all children iter.
method getNode(self: NodeRef; path: string): NodeRef {...}{.base, raises: [],
    tags: [].}
Returns child by path
method getPath(self: NodeRef): string {...}{.base, raises: [], tags: [].}
Returns node path.
method getParent(self: NodeRef): NodeRef {...}{.base, raises: [], tags: [].}
Returns node parent.
method getPauseMode(self: NodeRef): PauseMode {...}{.base, raises: [], tags: [].}
Calculates pause mode
method getRootNode(self: NodeRef): NodeRef {...}{.base, raises: [], tags: [].}
Gets root node.
method insertChild(self: NodeRef; index: int; node: NodeRef) {...}{.base, raises: [],
    tags: [].}
method isParentOf(self, other: NodeRef): bool {...}{.base, inline, raises: [],
    tags: [].}
method handle(self: NodeRef; event: InputEvent; mouse_on: var NodeRef) {...}{.base,
    raises: [], tags: [].}
Handles user input. This used in the Window object.
method hasNode(self: NodeRef; name: string): bool {...}{.base, inline, raises: [],
    tags: [].}

Returns true, if a node with name name in children.

Arguments:

  • name: node name.
method hasNode(self: NodeRef; other: NodeRef): bool {...}{.base, inline, raises: [],
    tags: [].}

Returns true, if other in self children.

Arguments:

  • other: other node.
method hasParent(self: NodeRef): bool {...}{.base, inline, raises: [], tags: [].}
Returns true, when node has parent.
method hide(self: NodeRef) {...}{.base, raises: [], tags: [].}
method postdraw(self: NodeRef; w, h: GLfloat) {...}{.base, raises: [], tags: [].}
Draws node. This used in the Window object.
method rename(self: NodeRef; new_name: string) {...}{.base, raises: [], tags: [].}
method removeChild(self: NodeRef; index: int) {...}{.base, raises: [], tags: [].}

Removes node child at a specific position.

Arguments:

  • index: child index.

See also:

method removeChild(self: NodeRef; other: NodeRef) {...}{.base, raises: [], tags: [].}

Removes another node from self, if other in self children.

Arguments:

  • other: other node.
method removeChildren(self: NodeRef) {...}{.base, raises: [], tags: [].}
method show(self: NodeRef) {...}{.base, raises: [], tags: [].}
method delete(self: NodeRef) {...}{.base, raises: [], tags: [].}
Deletes current node.
method `[]`(self: NodeRef; index: int): NodeRef {...}{.base, inline, raises: [],
    tags: [].}
method `[]`(self: NodeRef; index: string): NodeRef {...}{.base, inline, raises: [],
    tags: [].}
method `~`(self: NodeRef; path: string): NodeRef {...}{.base, inline, raises: [],
    tags: [].}

Macros

macro `@`(node: NodeRef; event_name, code: untyped): untyped

It provides a convenient wrapper for the event handler.

Arguments:

  • node is an any node pointer.
  • event_name is an event name, e.g.: process.
  • code is the proc code.

Examples

var
  smth_node = Node("Simple node")

smth_node@on_ready(self):
  echo "node is ready!"

smth_node@on_input(self, event):
  if event.isInputEventMouseButton():
    echo event