A text input element is used to enter a single line of text. It has a label that displays a prompt text when there is no text written to the text input.

TextInput screenshot

See also:

Constructor

@:value({ label : "" })new(label:String = "")

Create a new TextInput element.

Variables

@:value("")label:String = ""

The label of this element. It is displayed instead of the text if text equals "".

@:value(Config.textInputMaxLength)maxLength:Int = Config.textInputMaxLength

The maximum length of the text.

See also:

@:value("")read onlytext:String = ""

The current value of this element. To set the text, use setText().

@:value(true)valid:Bool = true

true if the text value of this TextInput is valid based on the regular expression set in validationReg. If this value is false, the text field is highlighted in a different color (theme property "color_invalid").

See also:

@:value(null)validationReg:EReg = null

A regular expression that checks whether the input text is a valid value for this text input. If null, no validation check is performed.

See also:

Methods

deleteSelectedText():Void

Delete the currently selected text.

getSelectedText():String

Return the selected text.

insertText(newText:String, position:Int):Void

Insert the given text at the given position. If the position is greater or equal than the length of the text, newText is inserted at the end of the element's current text. If the new text of this element is greater than maxLength, the text is truncated.

inlineisTextSelected():Bool

Return whether there is some text selected currently.

isTextValid():Bool

Return whether the text value of this element is valid according to the regular expression stored in TextInput.validationReg.

selectAll():Void

Select all the text in this text input.

setText(text:String):Void

Set the text of this text input.

Inherited Variables

Defined by Element

@:value(Anchor.FollowLayout)anchor:Anchor = Anchor.FollowLayout

The anchor of this element. Used for the layout.

See also:

@:value(false)disabled:Bool = false

true if the element is disabled and should not react to events. Also, elements might look different if disabled depending on the theme.

@:value(0)height:Int = 0

The height of this element.

@:value(null)layout:Null<Layout> = null

The layout this element belongs to.

@:value(null)read onlyparent:Null<Element> = null

The parent element of this element.

@:value(0)posX:Int = 0

The x position of this element.

@:value(0)posY:Int = 0

The y position of this element.

@:value(true)visible:Bool = true

If false, the element is not visible and will not react to any events.

@:value(0)width:Int = 0

The width of this element.

Inherited Methods

Defined by Element

inlineaddChild(child:Element):Void

finaladdEventListener<T>(eventClass:Class<T>, callback:T ‑> Void):Void

Register a callback to be called if the given event occurs on this element.

Example:

var button = new Button("Hello!");
button.addEventListener(MouseClickEvent, (event: MouseClickEvent) -> {
	if (event.mouseButton == Left && event.getState() == ClickStart) {
		trace("Clicked!");
	}
});

Parameters:

eventClass

The class of the event, must be a subclass of koui.events.Event

callback

The callback function to call if the event occurs

getChild<T>(matchBehaviour:ElementMatchBehaviour):Null<T>

getElementAtPosition(x:Int, y:Int):Null<Element>

getLayoutOffset():Vector<Int>

Return the offset of the element's position to the screen.

inlinegetTID():String

inlineisAtPosition(x:Int, y:Int):Bool

Return true if this element overlaps with the given position. Used internally for event handling most of the time. Elements may override this method to provide more detailed mouse interaction. If the element is invisible, false is returned.

finalinlinelistensTo<T>(eventClass:Class<T>):Bool

Returns whether this element has a registered event listener for the given event type.

finalinlinelistensToUID<T>(eventTypeUID:String):Bool

Returns whether this element has a registered event listener for the given event type.

inlineremoveChild(child:Element):Void

finalinlinerenderElement(g:KGraphics, element:Element):Void

Setup the given element for drawing and call its draw method afterwards.

inlinesetPosition(posX:Int, posY:Int):Void

Set the position of this element. You can also change the position per axis, see posX and posY.

inlinesetSize(width:Int, height:Int):Void

Set the size of this element. You can also change the size for each individual side, see width and height.

setTID(tID:String):Void

Set the theme ID of this element.

toString():String

Return a string representation of this element: "Element: <[ClassName]>"