TextInput

backend.TextInput (Class)
Implements: spec.TextInput

Clay backend implementation for system text input handling.

This class manages the platform-specific text input mechanisms, including:

  • IME (Input Method Editor) support for complex scripts
  • Virtual keyboard positioning on mobile platforms
  • Hardware keyboard input processing
  • Modifier key state tracking (Shift, Ctrl, Meta)

The implementation uses SDL's text input API on native platforms, which provides proper IME support and handles international text input correctly.

See: spec.TextInput The interface this class implements, ceramic.TextInput For the high-level text input API

Instance Members

clay
start(initialText: String, x: Float, y: Float, w: Float, h: Float): Void

Starts text input mode.

This activates the system's text input mechanisms including:

  • Virtual keyboard on mobile devices
  • IME composition window positioning
  • Text input event processing

The rectangle parameters help position IME windows and virtual keyboards near the text being edited.

Name Type Description
initialText String Initial text content (currently unused)
x Float X position of the text input area
y Float Y position of the text input area
w Float Width of the text input area (minimum 1 pixel)
h Float Height of the text input area (minimum 1 pixel)

clay
stop(): Void

Stops text input mode.

This deactivates text input, hiding virtual keyboards and closing any IME composition windows. The input area is reset to prevent any lingering visual artifacts.


clay
new(): Void

Private Members

clay
inputActive: Bool

Whether text input mode is currently active


clay
inputRectX: Int

X position of the text input area (for IME positioning)


clay
inputRectY: Int

Y position of the text input area (for IME positioning)


clay
inputRectW: Int

Width of the text input area


clay
inputRectH: Int

Height of the text input area


clay
handleTextInput(text: String): Void

Handles text input events from the system.

Processes Unicode text input, including composed characters from IME systems. Filters out spaces (handled separately) and forwards the text to the high-level text input system.

Name Type Description
text String The input text (may be multiple characters for IME)

clay
handleKeyDown(keyCode: Int, scanCode: Int): Void

Handles key press events for text editing.

Processes special keys like:

  • Navigation (arrows, home, end)
  • Editing (backspace, delete, enter)
  • Modifiers (shift, ctrl, meta/cmd)

Regular character input is handled by handleTextInput instead.

Name Type Description
keyCode Int Virtual key code
scanCode Int Physical key scan code

clay
handleKeyUp(keyCode: Int, scanCode: Int): Void

Handles key release events.

Only tracks modifier key releases (Shift, Ctrl, Meta) as these affect text input behavior and selection. Regular keys are processed on key down only.

Name Type Description
keyCode Int Virtual key code
scanCode Int Physical key scan code