Class WritableTextBoxObject


public class WritableTextBoxObject extends TextBoxObject
A writable text box GUI component that supports user input, cursor movement, multi-line editing, and different editing modes.

Extends TextBoxObject by adding keyboard and mouse interaction, cursor rendering, and text-editing logic (insert, backspace, newline, etc.).

Supported Modes

  • CONSOLE_MODE - Appends text at the end, typical console input behavior.
  • FREE_MODE - Allows free multi-line editing.
  • TEXT_EDITOR_MODE - Full text editor behavior with insert, newline, and merge logic.

Line Limit

You may set a line limit using setLineLimit(int). If set to NO_LINE_LIMIT, unlimited lines are allowed.

Cursor

A TextObject cursor is maintained internally and updated during editing.

Usage

Example:
 WritableTextBoxObject textBox = new WritableTextBoxObject(
     "chatBox", 1, gui,
     50, 50, 400, 300,
     false, true, 4,
     mySubWindow, myFont, Color.WHITE, new Color(0,0,0,0), true
 );
 textBox.setMode(WritableTextBoxObject.TEXT_EDITOR_MODE);
 
  • Field Details

    • focused

      public boolean focused
      Whether this text box is currently focused for input.
    • cursor

      public TextObject cursor
      Cursor object rendered as a text glyph (e.g., "|").
    • CONSOLE_MODE

      public static int CONSOLE_MODE
      Console mode: appends text at the end.
    • FREE_MODE

      public static int FREE_MODE
      Free mode: allows arbitrary line navigation and editing.
    • TEXT_EDITOR_MODE

      public static int TEXT_EDITOR_MODE
      Text editor mode: supports full editing logic (newlines, merging lines, etc.).
    • NO_LINE_LIMIT

      public static int NO_LINE_LIMIT
      Text editor mode: supports full editing logic (newlines, merging lines, etc.).
  • Constructor Details

    • WritableTextBoxObject

      public WritableTextBoxObject(String name, int layer, GUI gui, int x, int y, int sizeX, int sizeY, boolean nearestFilter, boolean rgba, int lineSpacing, SubWindowObject window, Font font, Color textColor, Color backgroundColor, boolean antiAliasing)
      Creates a writable text box object.
      Parameters:
      name - object name
      layer - rendering layer
      gui - GUI manager
      x - x position
      y - y position
      sizeX - width
      sizeY - height
      nearestFilter - true to use nearest-neighbor scaling
      rgba - whether RGBA is enabled
      lineSpacing - line spacing in pixels
      window - parent sub-window object (optional, can be null)
      font - font for rendering text
      textColor - foreground text color
      backgroundColor - background color
      antiAliasing - whether to enable anti-aliasing
  • Method Details

    • setLineLimit

      public void setLineLimit(int l)
      Sets the maximum line count for this text box.
      Parameters:
      l - line limit, or NO_LINE_LIMIT for unlimited lines
    • getLineLimit

      public int getLineLimit()
      Returns:
      the maximum line count, or NO_LINE_LIMIT if unlimited
    • setMode

      public void setMode(int mode)
      Sets the editing mode for this text box.
      Parameters:
      mode - one of CONSOLE_MODE, FREE_MODE, TEXT_EDITOR_MODE
    • getMode

      public int getMode()
      Returns:
      the current editing mode
    • appendLine

      public void appendLine(String text)
      Appends a new line of text to the text box.
      Parameters:
      text - line text to append
    • sendKey

      public void sendKey(int key, int action)
      Handles a keyboard key event.
      Overrides:
      sendKey in class TextBoxObject
      Parameters:
      key - GLFW key code
      action - GLFW action (press, release, repeat)
    • destroyObject

      public void destroyObject()
      Description copied from class: TextBoxObject
      Destroys this object, releasing GPU resources and unregistering it.

      If preserveTextureIDOverride is true, the OpenGL texture ID will not be deleted. See GUIObject.setPreserveTextureIDOverride(boolean).

      Overrides:
      destroyObject in class TextBoxObject
    • update

      public void update(boolean showFrame)
      Updates the text box state (cursor position, pending writes, etc.).
      Overrides:
      update in class TextBoxObject
      Parameters:
      showFrame - true if the GUI should be refreshed
    • sendMousePos

      public void sendMousePos(long window, double xPos, double yPos)
      Description copied from class: GUIObject
      Handles mouse position updates.
      Overrides:
      sendMousePos in class TextBoxObject
    • setLayer

      public void setLayer(int layer)
      Description copied from class: TextBoxObject
      Sets the rendering layer and updates parent GUI ordering.
      Overrides:
      setLayer in class TextBoxObject
    • sendMouseButton

      public void sendMouseButton(long window, int button, int action, int mods)
      Description copied from class: GUIObject
      Handles mouse button input.
      Overrides:
      sendMouseButton in class TextBoxObject
    • setX

      public void setX(int x)
      Description copied from class: TextBoxObject
      Sets the X position in pixels.
      Overrides:
      setX in class TextBoxObject
    • setY

      public void setY(int y)
      Description copied from class: TextBoxObject
      Sets the Y position in pixels.
      Overrides:
      setY in class TextBoxObject
    • getLines

      public TreeMap<Integer, TextObject> getLines()
      Overrides:
      getLines in class TextBoxObject
      Returns:
      the lines in this text box