UIOBJECT EditBox

From Wowpedia
Jump to: navigation, search

For summary of EditBox properties/methods see UISUMMARY EditBox

EditBox

A user can input text into the edit box which can then be retrieved using the EditBox:GetText() function.

When declaring an edit box object make sure that you either set "font" attribute for <EditBox> element, or include a <FontString> element, thus declaring which font is to be used to display text input into your edit box. If you do not do so EditBox will not display any text, just a blinking cursor.

<EditBox name="TestEditBox">
      .. Size
      .. Anchors
      .. Layers
      .. etc.
      
      <FontString inherits="GameFontNormal"/>
</EditBox>

XML

See XML/EditBox.

Lua API

Methods


Event Handlers

On multi-line and EditBox:SetHeight()

Note that multi-line EditBoxes will ignore any attempts to set its height via :SetHeight() or via Dimension attributes in XML. They will start out the height of a single line of text, and keep expanding their area as needed. This effect becomes visible if the editbox has a backdrop set, or a texture anchored to its corners.

Explicitly setting the top and bottom anchors with :SetPoint() will however size it like expected.

Minimal Lua Sample

The sample given here demonstrates the creation of a multi-line EditBox widget wrapped inside of a UIOBJECT ScrollFrame.

local scrollFrame = CreateFrame("ScrollFrame", nil, UIParent, "UIPanelScrollFrameTemplate")
scrollFrame:SetSize(300, 200)
scrollFrame:SetPoint("CENTER")

local editbox = CreateFrame("EditBox", nil, scrollFrame)
editbox:SetMultiLine(true)
editbox:SetFontObject(ChatFontNormal)
editbox:SetWidth(300)
scrollFrame:SetScrollChild(editbox)

-- The below will place the 30 "test" lines into the editbox.
editbox:SetText(string.rep("test\n", 30))

-- The below will highlight all the text in the editbox. This is useful for
-- dialogs where you want the user to copy something, such as a URL.
editbox:HighlightText()

-- The below script added to the editbox will hide the parent scrollframe
-- when the user presses the escape key.
editbox:SetScript("OnEscapePressed", function() scrollFrame:Hide() end)