native.newTextBox()

Type Function
Library native.*
Return value TextBox
Revision Release 2024.3703
Keywords text box, text input, native text
See also native.newTextField()
native.setKeyboardFocus()
userInput

Overview

Creates a scrollable, multi-line TextBox object for text input. For single-line text input, see native.newTextField().

By default, the content of text boxes is not editable. Set the object.isEditable property to true to make the content editable.

Native text boxes can listen for userInput events (see example).

Gotchas

Syntax

native.newTextBox( x, y, width, height )
x (required)

Number. The x coordinate that corresponds to the center of the text box.

y (required)

Number. The y coordinate that corresponds to the center of the text box.

width (required)

Number. Width of the text box.

height (required)

Number. Height of the text box.

Properties / Methods

See the TextBox documentation for a list of functions and properties.

Events

See the userInput event documentation for properties related to various TextBox object events.

Example

local defaultBox

local function textListener( event )

    if ( event.phase == "began" ) then
        -- User begins editing "defaultBox"

    elseif ( event.phase == "ended" or event.phase == "submitted" ) then
        -- Output resulting text from "defaultBox"
        print( event.target.text )

    elseif ( event.phase == "editing" ) then
        print( event.newCharacters )
        print( event.oldText )
        print( event.startPosition )
        print( event.text )
    end
end

-- Create text box
defaultBox = native.newTextBox( 200, 200, 280, 140 )
defaultBox.text = "This is line 1.\nAnd this is line2"
defaultBox.isEditable = true
defaultBox:addEventListener( "userInput", textListener )