# nodesnim/nodes/node

Dark Mode

Search:
Group by:

Node is the root type of all other nodes.

# Imports

../thirdparty/opengl, ../core/vector2, ../core/enums, ../core/anchor, ../core/input

# Types

    NodeObj = object of RootObj
      kind*: NodeKind
      visible*: bool
      is_ready*: bool
      can_use_anchor*: bool
      can_use_size_anchor*: bool
      relative_z_index*: bool      ## Uses in the Node2D
      z_index*, z_index_global*: float ## Uses in the Node2D
      pausemode*: PauseMode        ## Pause mode, by default is INHERIT.
      name*: string                ## Node name.
      position*: Vector2Ref        ## Node position, by default is Vector2(0, 0).
      global_position*: Vector2Ref ## Node global position.
      rect_size*: Vector2Ref       ## Node size.
      size_anchor*: Vector2Ref     ## Node size anchor.
      anchor*: AnchorRef           ## Node anchor.
      parent*: NodeRef             ## Node parent.
      children*: seq[NodeRef]      ## Node children.
      on_enter*: proc (self: NodeRef) ## This called when scene changed.
      on_exit*: proc (self: NodeRef) ## This called when exit from the scene.
      on_input*: proc (self: NodeRef; event: InputEvent) ## This called on user input.
      on_ready*: proc (self: NodeRef) ## This called when the scene changed and the `enter` was called.
      on_process*: proc (self: NodeRef) ## This called every frame.

    NodeRef = ref NodeObj

# 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.

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

  Adds new child in current node.

  Arguments:

  - `child`: other node.

    method calcGlobalPosition(self: NodeRef) {...}{.base, raises: [], tags: [].}

  Returns global node position.

    method calcPositionAnchor(self: NodeRef) {...}{.base, raises: [], tags: [].}

  Calculates node position with anchor. This used in the Window object.

    method draw(self: NodeRef; w, h: GLfloat) {...}{.base, raises: [], tags: [].}

  Draws node. This used in the Window object.

    method draw2stage(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.

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

  Returns child count.

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

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

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

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

    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 isCollide(self: NodeRef; x, y: float): bool {...}{.base, raises: [], tags: [].}

    method isCollide(self: NodeRef; vec2: Vector2Ref): bool {...}{.base, raises: [], tags: [].}

    method isCollide(self, other: NodeRef): bool {...}{.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, raises: [], tags: [].}

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

  Arguments:

  - `name`: node name.

    method hasNode(self: NodeRef; other: NodeRef): bool {...}{.base, 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 move(self: NodeRef; x, y: float) {...}{.base, inline, raises: [], tags: [].}

  Adds `x` and` y` to the node position.

  Arguments:

  - `x`: how much to add to the position on the X axis.
  - `y`: how much to add to the position on the Y axis.

    method move(self: NodeRef; vec2: Vector2Ref) {...}{.base, inline, raises: [], tags: [].}

  Adds `vec2` to the node position.

  Arguments:

  - `vec2`: how much to add to the position on the X,Y axes.

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

  Removes node child at a specific position.

  Arguments:

  - `index`: child index.

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

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

  Arguments:

  - `other`: other node.

    method setAnchor(self: NodeRef; anchor: AnchorRef) {...}{.base, raises: [], tags: [].}

  Changes node anchor.

  Arguments:

  - `anchor` - AnchorRef object.

    method setAnchor(self: NodeRef; x1, y1, x2, y2: float) {...}{.base, raises: [], tags: [].}

  Changes node anchor.

  Arguments:

  - `x1` and `y1` - anchor relative to the parent node.
  - `x2` and `y2` - anchor relative to this node.

    method setSizeAnchor(self: NodeRef; anchor: Vector2Ref) {...}{.base, raises: [], tags: [].}

    method setSizeAnchor(self: NodeRef; x, y: float) {...}{.base, raises: [], tags: [].}

    method show(self: NodeRef) {...}{.base, raises: [], tags: [].}

    method delete(self: NodeRef) {...}{.base, raises: [], tags: [].}

  Deletes current node.

# 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@ready:
        echo "node is ready!"

      smth_node@input(event):
        if event.isInputEventMouseButton():
          echo event

# Templates

    template nodepattern(nodetype: untyped): untyped

  This used in childs of the NodeObj.