A number input is a special kind of text input that only accepts numbers. The type of number it accepts is specified by its NumberInput.inputType.

NumberInput screenshot

See also:

Static variables

@:value(~/^[\-\+]?[0-9]+(\.[0-9]+)?$/)staticfinalread onlyREG_FLOAT:EReg = ~/^[\-\+]?[0-9]+(\.[0-9]+)?$/

The regular expression used to check whether a string is a valid signed floating point number. Note that the decimal separator is a decimal point(.) as it is common in the English language.

It also accepts strings beginning with a + or - sign.

See also:

@:value(~/^[\-\+]?[0-9]+$/)staticfinalread onlyREG_INT:EReg = ~/^[\-\+]?[0-9]+$/

The regular expression used to check whether a string is a valid signed integer number.

It also accepts strings beginning with a + or - sign.

See also:

@:value(~/^[\+?[0-9]+(\.[0-9]+)?$/)staticfinalread onlyREG_UNSIGNED_FLOAT:EReg = ~/^[\+?[0-9]+(\.[0-9]+)?$/

The regular expression used to check whether a string is a valid unsigned floating point number. Note that the decimal separator is a decimal point(.) as it is common in the English language.

It also accepts strings beginning with a + sign.

See also:

@:value(~/^\+?[0-9]+$/)staticfinalread onlyREG_UNSIGNED_INT:EReg = ~/^\+?[0-9]+$/

The regular expression used to check whether a string is a valid unsigned integer number.

It also accepts strings beginning with a + sign.

See also:

Constructor

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

Create a new NumberInput element.

Variables

@:value(NumberType.TypeFloat)inputType:NumberType = NumberType.TypeFloat

The number type that is accepted by this NumberInput.

Methods

getFloatValue():Float

Return the floating point value of this element. If the input is invalid, Math.NaN is returned. This function is equivalent to getFloatValueOrDefault(Math.NaN).

See also:

@:value({ defaultValue : 0.0 })getFloatValueOrDefault(defaultValue:Float = 0.0):Float

Return the floating point value of this element. If the input is invalid, the given default value is returned.

See also:

getIntValue():Null<Int>

Return the integer value of this element. If the input is invalid, null is returned (make sure to test this in your code!).

See also:

@:value({ defaultValue : 0 })getIntValueOrDefault(defaultValue:Int = 0):Int

Return the integer value of this element. If the input is invalid, the given default value is returned.

See also:

setFloatValue(value:Null<Float>):Void

Set the floating point value of this element. If this number input accepts integer vaues only, the decimal places of the given value are truncated towards zero. If the given value is not a finite number (Math.NaN, Math.POSIIVE_INIFINITY etc.) or null (possible on non-static targets only), nothing will happen.

setIntValue(value:Null<Int>):Void

Set the integer value of this element. If the given value is null (possible on non-static targets only), nothing will happen.

Parameters:

value

The new value

Inherited Variables

Defined by TextInput

private@:value(0)cursorIndex:Int = 0

private@:value(0)cursorTimer:Int = 0

private@:value(false)draggingEnabled:Bool = false

private@:value(false)isClicked:Bool = false

private@:value(false)isFocused:Bool = false

private@:value(false)isHovered:Bool = false

@: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:

private@:value("")origText:String = ""

private@:value(0)scrollBoundL:Int = 0

private@:value(0)scrollBoundR:Int = 0

private@:value(-1)selectionStartIndex:Int = -1

@: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:

Defined by Element

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

The anchor of this element. Used for the layout.

See also:

private@:value(true)autoRenderChildren:Bool = true

Whether the children of the element are automatically drawn after the element, or whether element must render its children by its own. The latter can be useful if the children need to be drawn in a specified order.

private@:value([])children:Array<Element> = []

The children of this element.

private@:value("")read onlyctxElement:String = ""

Current context element

@: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.

privateread onlydrawHeight:Int

The height of this element, used for drawing and event handling.

privateread onlydrawWidth:Int

The width of this element, used for drawing and event handling.

privateread onlydrawX:Int

The x position of this element, used for drawing and event handling.

privateread onlydrawY:Int

The y position of this element, used for drawing and event handling.

private@:value(new Map())eventListeners:Map<String, Array<EventListener<Event>>> = new Map()

@:value(0)height:Int = 0

The height of this element.

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

The layout this element belongs to.

privatelayoutHeight:Int

The height of this element, used for the layout.

privatelayoutWidth:Int

The width of this element, used for the layout.

privatelayoutX:Int

The x position of this element, used for the layout.

privatelayoutY:Int

The y position of this element, used for the layout.

@: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.

private@:value("default")read onlystate:String = "default"

Current context state

private@:value(["" => ["default", "disabled"]])read onlystates:Map<String, Array<String>> = ["" => ["default", "disabled"]]

States for each context element: ctxElement => states

privateread onlystyle:Style

Style of the current context

private@:value(false)styleInitialized:Bool = false

Whether this element already initialized its style.

privateread onlystylesCache:Map<String, Style>

ctxElement!state => style

private@:value("_root")tID:String = "_root"

The theme ID of this object. Use this to select which theme settings to apply.

@: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 TextInput

private_onClick(event:MouseClickEvent):Void

private_onFocus(event:FocusEvent):Void

private_onHover(event:MouseHoverEvent):Void

privatebeginEdit():Void

deleteSelectedText():Void

Delete the currently selected text.

privatedrawCursor(g:Graphics):Void

getSelectedText():String

Return the selected text.

privategetTextIndexBeforePosition(?searchText:String, ?relPositionX:Null<FastFloat>):Int

Calculates the rightmost text index which position in searchText is smaller than relPositionX with binary search.

If searchText is not given, this.text is used instead.

If relPositionX is not given, the relative mouse position is used instead.

Parameters:

searchText

The text to be searched

relPositionX

The position in "text coordinates"

Returns:

Int

privateinlinegetTextPositionAtIndex(index:Int):FastFloat

privateinlinegetVisibleText():String

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.

privateonCopy():String

privateonCut():String

privateonPaste(content:String):Void

private@:value({ recalcRight : true })recalcScrollBounds(recalcRight:Bool = true):Void

Recalculates one of both scrollBound[L/R] variables based on the value of the other variable.

The recalculated variable is determined based on whether recalcRight is true or false. If it is true, scrollBoundR is calculated based on the value in scrollBoundL. If it is false, it is calculated the other way around.

Parameters:

recalcRight

If true, calculate scrollBoundR based on scrollBoundL. If false, it is the other way around.

privateresetScroll():Void

privatescrollText(offset:Int):Void

selectAll():Void

Select all the text in this text input.

setText(text:String):Void

Set the text of this text input.

privateinlineset_label(value:String):String

private@:value({ reset : false })stopEdit(reset:Bool = false):Void

privateinlinetruncateMaxLength():Void

privateupdateDragging():Void

Scroll the text input if the mouse is dragged outside of the bounds.

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

private@:value({ ctxElement : "" })cacheStates(states:Array<String>, ctxElement:String = ""):Void

privatedrawOverlay(g:KGraphics):Void

privateinlinegetAnchorResolved():Anchor

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

privateinlinegetContextState():String

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

getLayoutOffset():Vector<Int>

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

inlinegetTID():String

privateinlineinvalidateElem():Void

Notify the parent layout on the next frame that this element has changed its size or position. Use the next frame to make sure we don't waste calculations when more than one value changes during one frame.

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.

privateloadStyle():Void

Sets the style variable to point to the current context.

privateonBuild():Void

privateonResize():Void

inlineremoveChild(child:Element):Void

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

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

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

privateinlinerequireContextElement(ctxElement:String):Void

private@:value({ ctxElement : "" })inlinerequireStates(states:Array<String>, ctxElement:String = ""):Void

privateinlineresetContext():Void

privateinlineresetContextState():Void

private@:value({ recursive : true, ctxElement : "" })inlinesetContext(state:String, ctxElement:String = "", recursive:Bool = true):Void

Set the current style context used for drawing. Calling this function is equivalent to calling setContextState and setContextElement. If the given element name is "", the element's tID is used.

Parameters:

state
ctxElement

See also:

  • setContextElement

  • setContextState

  • resetContext

private@:value({ ctxElement : "" })inlinesetContextElement(ctxElement:String = ""):Void

Set the drawing context element but keep the current state. If the given element name is "", the element's tID is used.

See also:

  • setContextState

  • setContext

  • resetContext

private@:value({ recursive : true })inlinesetContextState(state:String, recursive:Bool = true):Void

Set the drawing context state but keep the current element.

See also:

  • setContextElement

  • setContext

  • resetContext

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.

privateset_height(value:Int):Int

privateinlineset_layout(value:Null<Layout>):Layout

privateset_layoutHeight(value:Int):Int

privateset_layoutWidth(value:Int):Int

privateset_layoutX(value:Int):Int

privateset_layoutY(value:Int):Int

privateset_posX(value:Int):Int

privateset_posY(value:Int):Int

privateset_tID(value:String):String

tID setter. Caches all styles required by this element.

privateset_width(value:Int):Int

toString():String

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