# nodesnim/nodescontrol/switch

Dark Mode

Search:
Group by:

Displays colour rectangle.

# Imports

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

# Types

    SwitchObj = object of ControlRef
      value*: bool
      color_enable*, color_disable*: ColorRef
      back_enable*, back_disable*: ColorRef
      on_toggle*: proc (self: SwitchRef; toggled: bool): void ## This called when switch toggled.

    SwitchRef = ref SwitchObj

# Procs

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

  Creates a new Switch.

  Arguments:

  - `name` is a node name.

  Examples:

      var colorrect1 = Switch("Switch")

# Methods

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

  this method uses in the `window.nim`.

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

  Duplicates Switch object and create a new Switch.

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

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

    method toggle(self: SwitchRef) {...}{.base, raises: [], tags: [].}

  Toggles value.