# nodesnim/nodescontrol/edittext

Dark Mode

Search:
Group by:

It provides primitive text input.

# Imports

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

# Types

    EditTextObj = object of ControlRef
      blit_caret*: bool
      blit_speed*: float
      blit_time*: float
      caret_position*: int
      font*: pointer               ## Glut font data.
      spacing*: float              ## Font spacing.
      size*: float                 ## Font size.
      text*: string                ## EditText text.
      hint_text*: string
      color*: ColorRef             ## Text color.
      hint_color*: ColorRef        ## Hint color.
      caret_color*: ColorRef
      text_align*: AnchorRef       ## Text align.
      on_edit*: proc (pressed_key: string): void ## This called when user press any key.

    EditTextRef = ref EditTextObj

# Procs

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

  Creates a new EditText.

  Arguments:

  - `name` is a node name.

  Examples:

      var edit = EditText("EditText")

# Methods

    method getTextSize(self: EditTextRef): Vector2Ref {...}{.base, raises: [], tags: [].}

  Returns text size.

    method getLine(self: EditTextRef): int {...}{.base, raises: [], tags: [].}

  Returns current caret line.

    method getCharPositionUnderMouse(self: EditTextRef): int {...}{.base, raises: [], tags: [].}

  Returns char position under mouse.

    method getCharUnderMouse(self: EditTextRef): char {...}{.base, raises: [], tags: [].}

  Returns char under mouse

    method getWordPositionUnderMouse(self: EditTextRef): tuple[startpos, endpos: int] {...}{.
        base, raises: [], tags: [].}

  Returns words under mouse. Returns (-1, -1), if under mouse no founds words.

    method getWordUnderMouse(self: EditTextRef): string {...}{.base, raises: [], tags: [].}

  Returns words under mouse.

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

  This method uses in the `window.nim`

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

  Duplicates EditText object and create a new EditText.

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

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

    method setTextAlign(self: EditTextRef; align: AnchorRef) {...}{.base, raises: [], tags: [].}

  Changes text align.

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

  Changes text align.

    method setText(self: EditTextRef; value: string) {...}{.base, raises: [], tags: [].}

  Changes EditText text.