UIOBJECT EditBox

From Wowpedia
Jump to: navigation, search

For summary of EditBox properties/methods see UISUMMARY EditBox

Edit Box

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 showing multi line edit box with a scroll bar

Every line of the sample is required for the text to show up but also no additional lines is needed

local s = CreateFrame("ScrollFrame", nil, UIParent, "UIPanelScrollFrameTemplate") -- or you actual parent instead
s:SetSize(300,200)
s:SetPoint("CENTER")
local e = CreateFrame("EditBox", nil, s)
e:SetMultiLine(true)
e:SetFontObject(ChatFontNormal)
e:SetWidth(300)
s:SetScrollChild(e)
--- demo multi line text
e:SetText("line 1\nline 2\nline 3\nmore...\n\n\n\n\n\nanother one\n"
.."some very long...dsf v asdf a sdf asd df as df asdf a sdfd as ddf as df asd f asd fd asd f asdf LONG LINE\n\n\nsome more.\nlast!")
e:HighlightText() -- select all (if to be used for copy paste)
-- optional/just to close that frame
e:SetScript("OnEscapePressed", function()
  s:Hide()
end)