# nodesnim/nodescontrol/control

Dark Mode

Search:
Group by:

The base of other Control nodes.

# Imports

../thirdparty/opengl, ../core/vector2, ../core/rect2, ../core/anchor, ../core/input, ../core/enums, ../core/color, ../nodes/node, ../nodes/canvas

# Types

    ControlObj = object of CanvasObj
      hovered*: bool
      pressed*: bool
      focused*: bool
      mousemode*: MouseMode
      background_color*: ColorRef
      on_mouse_enter*: proc (self: ControlRef; x, y: float): void ## This called when the mouse enters the Control node.
      on_mouse_exit*: proc (self: ControlRef; x, y: float): void ## This called when the mouse exit from the Control node.
      on_click*: proc (self: ControlRef; x, y: float): void ## This called when the user clicks on the Control node.
      on_press*: proc (self: ControlRef; x, y: float): void ## This called when the user holds on the mouse on the Control node.
      on_release*: proc (self: ControlRef; x, y: float): void ## This called when the user no more holds on the mouse.
      on_focus*: proc (self: ControlRef): void ## This called when the Control node gets focus.
      on_unfocus*: proc (self: ControlRef): void ## This called when the Control node loses focus.

    ControlRef = ref ControlObj

# Procs

    proc Control(name: string = "Control"): ControlRef {...}{.raises: [], tags: [].}

  Creates a new Control.

  Arguments:

  - `name` is a node name.

  Examples:

      var ctrl = Control("Control")

# Methods

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

  Calculates node position. This uses in the `scene.nim`.

    method draw(self: ControlRef; w, h: GLfloat) {...}{.raises: [GLerror, Exception],
        tags: [RootEffect].}

  this method uses in the `window.nim`.

    method duplicate(self: ControlRef): ControlRef {...}{.base, raises: [], tags: [].}

  Duplicates Control object and create a new Control.

    method getGlobalMousePosition(self: ControlRef): Vector2Ref {...}{.base, inline,
        raises: [], tags: [].}

  Returns mouse position.

    method handle(self: ControlRef; event: InputEvent; mouse_on: var NodeRef) {...}{.
        raises: [Exception], tags: [RootEffect].}

  Handles user input. This uses in the `window.nim`.

    method setBackgroundColor(self: ControlRef; color: ColorRef) {...}{.base, raises: [],
        tags: [].}

  Changes Control background color.

# Templates

    template controlpattern(): untyped