Skip to content
Aaron H edited this page Dec 10, 2016 · 3 revisions

Information

The text input object receives text from the user via keyboard. The text input object supports both single-line and multi-line input.

Example Use

local frame = loveframes.Create("frame")
frame:SetName("Text Input")
frame:SetSize(500, 90)
frame:CenterWithinArea(unpack(demo.centerarea))
     
local textinput = loveframes.Create("textinput", frame)
textinput:SetPos(5, 30)
textinput:SetWidth(490)
textinput.OnEnter = function(object)
    if not textinput.multiline then
        object:Clear()
    end
end
textinput:SetFont(love.graphics.newFont(12))
         
local togglebutton = loveframes.Create("button", frame)
togglebutton:SetPos(5, 60)
togglebutton:SetWidth(490)
togglebutton:SetText("Toggle Multiline")
togglebutton.OnClick = function(object)
    if textinput.multiline then
        frame:SetHeight(90)
        frame:Center()
        togglebutton:SetPos(5, 60)
        textinput:SetMultiline(false)
        textinput:SetHeight(25)
        textinput:SetText("")
        frame:CenterWithinArea(unpack(demo.centerarea))
    else
        frame:SetHeight(365)
        frame:Center()
        togglebutton:SetPos(5, 335)
        textinput:SetMultiline(true)
        textinput:SetHeight(300)
        textinput:SetText("")
        frame:CenterWithinArea(unpack(demo.centerarea))
    end
end

Event Callbacks

OnEnter

Called when enter/return is pressed when the object has focus.

Arguments passed: self [object], self text [string]

local textinput = loveframes.Create("textinput")
textinput.OnEnter = function(object, text)
    print(text)
end

OnTextChanged

Called when the object's text is changed.

Arguments passed: self [object], text entered [string] or modifier key [string]

local textinput = loveframes.Create("textinput")
textinput.OnTextChanged = function(object, text)
    print(text)
end

OnFocusGained

Called when the object gains focus.

Arguments passed: self [object]

local textinput = loveframes.Create("textinput")
textinput.OnFocusGained = function(object)
    print("The object has gained focus.")
end

OnFocusLost

Called when the object loses focus.

Arguments passed: self [object]

local textinput = loveframes.Create("textinput")
textinput.OnFocusLost = function(object)
    print("The object has lost focus.")
end

Methods

SetTextOffsetX

Sets the object's text x offset

object:SetTextOffsetX(xoffset[number])

SetTextOffsetY

Sets the object's text y offset

object:SetTextOffsetY(yoffset[number])

SetFont

Sets the object's font

object:SetFont(font[font])

GetFont

Gets the object's font

Returns 1 value: font [font]

local font = object:GetFont()

SetFocus

Sets the object's focus

object:SetFocus(focus[true])

GetFocus

Gets the object's focus

Returns 1 value: focus [boolean]

local focus = object:GetFocus()

GetIndicatorVisibility

Gets the object's indicator visibility

Returns 1 value: visibility [boolean]

local indicatorvisibility = object:GetIndicatorVisibility()

SetLimit

Sets the maximum number of characters the object's text can have

object:SetLimit(limit[number])

SetUsable

Sets what characters can be used in the object's text

object:SetUsable(usable[table])

GetUsable

Gets what characters can be used in the object's text

Returns 1 value: usable [table]

local usable = object:GetUsable()

SetUnsable

Sets what characters can not be used in the object's text

object:SetUnusable(unusable[table])

GetUnsable

Gets what characters can not be used in the object's text

Returns 1 value: unusable [table]

local unusable = object:GetUnsable()

Clear

Clears the object's text

object:Clear()

SetText

Sets the object's text

object:SetText(text[string])

GetText

Gets the object's text

local text = object:GetText()

SetMultiline

Enables or disables multiline input mode

object:SetMultiline(multiline[bool])

GetMultiline

Gets whether or not the object is using multiline input

Returns 1 value: multiline [bool]

local multiline = object:GetMultiline()

GetTextX

Gets the x position of the object's text

Returns 1 value: textx [number]

local textx = object:GetTextX()

GetTextY

Gets the y position of the object's text

Returns 1 value: texty [number]

local texty = object:GetTextY()

IsAllTextSelected

Gets whether or not all of the object's text is selected

Returns 1 value: alltextselected [bool]

local alltextselected = object:IsAllTextSelected()

GetLines

Gets the object's line data

Returns 1 value: lines [table]

local lines = object:GetLines()

GetOffsetX

Gets object's x offset

Returns 1 value: offsetx [number]

local offsetx = object:GetOffsetX()

GetOffsetY

Gets object's y offset

Returns 1 value: offsety [number]

local offsety = object:GetOffsetY()

GetIndicatorX

Gets object's indcator x position

Returns 1 value: indicatorx [number]

local indicatorx = object:GetIndicatorX()

GetIndicatorY

Gets object's indcator y position

Returns 1 value: indicatory [number]

local indicatory = object:GetIndicatorY()

ShowLineNumbers

Toggles the line numbers panel

object:ShowLineNumbers(show_line_numbers[bool])

SetTabReplacement

Sets what characters should be used to replace tab characters

object:SetTabReplacement(tabreplacement[string])

GetTabReplacement

Gets object's tab replacement

Returns 1 value: tab replacement [string]

local tabreplacement = object:GetTabReplacement()

SetEditable

Sets whether the object is editable or not

object:SetEditable(editable[bool])

GetEditable

Gets whether the object is editable or not

Returns 1 value: editable [bool]

local editable = object:GetEditable()

SetButtonScrollAmount

Sets the amount that the object's scroll buttons will scroll the object's list items by

object:SetButtonScrollAmount(scrollamount[number])

GetButtonScrollAmount

Gets the object's scroll button scroll amount

Returns 1 value: scrollamount [number]

local scrollamount = object:GetButtonScrollAmount()

SetMouseWheelScrollAmount

Sets the amount that the mouse wheel will scroll the object's list items by

object:SetMouseWheelScrollAmount(scrollamount[number])

GetMouseWheelScrollAmount

Gets the mouse wheel's scroll amount

Returns 1 value: scroll amount [number]

local scrollamount = object:GetMouseWheelScrollAmount()

SetAutoScroll

Sets whether or not the object should autoscroll when in multiline mode

object:SetAutoScroll(autoscroll[bool])

GetAutoScroll

Gets whether or not the object should autoscroll when in multiline mode

Returns 1 value: autoscroll [boolean]

local autoscroll = object:GetAutoScroll()

SetRepeatDelay

Sets the delay before the object begins to repeat the key that is being held down

object:SetRepeatDelay(delay[number])

GetRepeatDelay

Gets the object's repeat delay

Returns 1 value: delay [number]

local delay = object:GetRepeatDelay()

SetValue

Sets the object's value

Note: This method is an alias of SetText(text)

object:SetValue(value)

GetValue

Gets the object's value

Returns 1 value: value [string]

Note: This method is an alias of GetText()

local value = object:GetValue()

Internal Methods

These methods are used by the object internally. You should not use them unless you know what you are doing.

RunKey

Called when a key is pressed and needs to be processed into text.

object:RunKey(key[string], unicode[number])

MoveIndicator

Moves the object's indicator

object:MoveIndicator(num[number], exact[boolean])

UpdateIndicator

Updates the object's indicator

object:UpdateIndicator()

AddIntoText

Adds text into the object's text at a specific location

object:AddIntoText(text[string], position[number])

RemoveFromText

Removes a chracter from the object's text

object:AddIntoText(position[number])

GetTextCollisions

Gets collisions with the object's text and the mouse cursor

object:GetTextCollisions(x[number], y[number])`

PositionText

Positions the object's text

object:PositionText()

GetVerticalScrollBody

Gets the object's vertical scroll body

Returns 1 value: vscrollbody [object]

local vscrollbody = object:GetVerticalScrollBody()

GetHorizontalScrollBody

Gets the object's horizontal scroll body

Returns 1 value: hscrollbody [object]

local hscrollbody = object:GetHorizontalScrollBody()

HasVerticalScrollBody

Checks if the object has a vertical scroll body

Returns 1 value: hasvscrollbody [bool]

local hasvscrollbody = object:HasVerticalScrollBody()

HasHorizontalScrollBody

Checks if the object has a horizontal scroll body

Returns 1 value: hashscrollbody [bool]

local hashscrollbody = object:HasHorizontalScrollBody()

GetLineNumbersPanel

Gets the object's line numbers panel

Returns 1 value: panel [object]

local panel = object:GetLineNumbersPanel()

GetItemWidth

Gets object's item width

Returns 1 value: itemwidth [number]

local itemwidth = object:GetItemWidth()

GetItemHeight

Gets object's item height

Returns 1 value: itemheight [number]

local itemheight = object:GetItemHeight()
Clone this wiki locally