Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TextBox

An editable text box UI element

Hierarchy

Index

Properties

onTextChanged

onTextChanged: MulticastDelegate<(textBox: this, player: Player, text: string) => void>

Called when the edited text changes.

param

The text box where the text changed

param

The player that changed the text. undefined if the text was changed through setText.

param

The new text

onTextCommitted

onTextCommitted: MulticastDelegate<(textBox: this, player: Player, text: string, usingEnter: boolean) => void>

Called when the edited text is committed (by pressing Enter or deselecting the widget).

param

The text box where the text was committed

param

The player that committed the text. undefined if the text was committed through setText.

param

The new text

param

True if the user committed the text using the enter key, false if it was committed for another reason (usually because the text field lost focus)

Methods

getFontFileName

  • getFontFileName(): string

getFontPackageId

  • getFontPackageId(): string
  • Return the id of the package that contains the TrueType font file name used for the text. Empty if no custom font is used or no package is specified (and the package containing the script is used).

    Returns string

getFontSize

  • getFontSize(): number

getInputType

  • getInputType(): number
  • Return the type of input this text box accepts. 0 - Any string 1 - Real numbers, positive or negative 2 - Real numbers, positive only 3 - Whole numbers, positive or negative 4 - Whole numbers, positive only

    Returns number

getMaxLength

  • getMaxLength(): number
  • Return the maximum number of characters allowed for this text box

    Returns number

getOwningObject

getParent

  • getParent(): Widget | undefined
  • Return the widget that contains this widget, for example a border that wraps a check box. Returns undefined if this object has no parent.

    Returns Widget | undefined

getText

  • getText(): string
  • Return the currently displayed text.

    Returns string

getTextColor

isBackgroundTransparent

  • isBackgroundTransparent(): boolean
  • Return if the background is transparent

    Returns boolean

isBold

  • isBold(): boolean

isEnabled

  • isEnabled(): boolean

isItalic

  • isItalic(): boolean

isSelectTextOnFocus

  • isSelectTextOnFocus(): boolean
  • Return whether the whole text should be selected when the TextBox receives focus

    Returns boolean

isVisible

  • isVisible(): boolean

setBackgroundTransparent

  • setBackgroundTransparent(transparent: boolean): TextBox
  • Set whether the background is transparent. Can be used to show a custom text box style using an ImageWidget behind the TextBox on a Canvas, for example.

    Parameters

    • transparent: boolean

      Set to true to remove the text box background and only show the text

    Returns TextBox

setBold

  • setBold(bold: boolean): this

setEnabled

  • setEnabled(enabled: boolean): this
  • Set whether the widget is enabled. When a widget is disabled, users can't interact with it and it is greyed out. When a widget that contains other widgets (like VerticalBox) is disabled, all its children behave as if disabled, too. By default, widgets are enabled.

    Parameters

    • enabled: boolean

      Whether to enable the widget.

    Returns this

setFont

  • setFont(fontFilename: string, packageId?: string): this
  • Set the TrueType font file used for the text. If a custom font is used, the bold and italic settings don't have an effect. Place your font files in the "Fonts" folder of your package.

    Parameters

    • fontFilename: string

      The filename of the TTF file to load. Set to empty string to use the standard font (and enable bold and italic settings).

    • Optional packageId: string

      The id of the package that contains the TTF file (in the Fonts folder). Can usually be empty when used from scripts to use the same package that contains the script file, but you need to explicitly pass refPackageId for the current package or a package id when you use it in a callback. You can find package ids in the manifest.json file in package folders. Usually you won't use this parameter, unless you have a specific reason to load a font from a different package than where the script is located.

    Returns this

setFontSize

  • setFontSize(size: number): this

setInputType

  • setInputType(type: number): TextBox
  • Set the type of input this text box accepts. 0 - Any string 1 - Real numbers, positive or negative 2 - Real numbers, positive only 3 - Whole numbers, positive or negative 4 - Whole numbers, positive only

    Parameters

    • type: number

      The new input type

    Returns TextBox

setItalic

  • setItalic(italic: boolean): this

setMaxLength

  • setMaxLength(length: number): TextBox
  • Set the maximum number of characters allowed for this text box

    Parameters

    • length: number

      Maximum number of characters. Must be between 1 and 1023. Default: 100

    Returns TextBox

setSelectTextOnFocus

  • setSelectTextOnFocus(selectAll: boolean): TextBox
  • Set whether the whole text should be selected when the TextBox receives focus

    Parameters

    • selectAll: boolean

    Returns TextBox

setText

setTextColor

  • setTextColor(color: Color | [r: number, g: number, b: number, a: number]): this

setVisible

  • setVisible(visible: boolean): Widget
  • Set whether the widget is visible. When a widget that contains other widgets (like VerticalBox) is invisible, all its children are invisible, too. The layout of widgets is updated when visibility changes, and invisible widgets are treated as if they don't exist.

    Parameters

    • visible: boolean

      Whether the widget is visible.

    Returns Widget