Skip to content

Instantly share code, notes, and snippets.

Created June 8, 2016 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/70ebaa4b38fd85f878ad5bbaa5cb04f2 to your computer and use it in GitHub Desktop.
Save anonymous/70ebaa4b38fd85f878ad5bbaa5cb04f2 to your computer and use it in GitHub Desktop.
function KethoEditBox_New()
if KethoEditBox then
KethoEditBox:Show()
else
local f = CreateFrame("Frame", "KethoEditBox", UIParent, "DialogBoxFrame")
f:SetPoint("CENTER"); f:SetSize(600, 500)
f:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\PVPFrame\\UI-Character-PVP-Highlight", -- this one is neat
edgeSize = 16,
insets = { left = 8, right = 6, top = 8, bottom = 8 },
})
f:SetBackdropBorderColor(0, .44, .87, 0.5)
---------------
--- Movable ---
---------------
f:EnableMouse(true) -- also seems to be automatically enabled when setting the OnMouseDown script
f:SetMovable(true); f:SetClampedToScreen(true)
f:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
self:StartMoving()
end
end)
f:SetScript("OnMouseUp", f.StopMovingOrSizing)
-------------------
--- ScrollFrame ---
-------------------
local sf = CreateFrame("ScrollFrame", "KethoEditBoxScrollFrame", KethoEditBox, "UIPanelScrollFrameTemplate")
sf:SetPoint("LEFT", 16, 0)
sf:SetPoint("RIGHT", -32, 0)
sf:SetPoint("TOP", 0, -16)
sf:SetPoint("BOTTOM", KethoEditBoxButton, "TOP", 0, 0)
---------------
--- EditBox ---
---------------
local eb = CreateFrame("EditBox", "KethoEditBoxEditBox", KethoEditBoxScrollFrame)
eb:SetSize(sf:GetSize()) -- seems inheriting the points won't automatically set the width/size
eb:SetMultiLine(true) -- will be laggy with thousands of lines/text
eb:GetRegions():SetNonSpaceWrap(false) -- fix lag?
eb:SetFontObject("ChatFontNormal")
eb:SetAutoFocus(false) -- make keyboard not automatically focused to this editbox
eb:SetScript("OnEscapePressed", function(self)
f:Hide() -- rather hide, since we only use it for copying to clipboard
end)
sf:SetScrollChild(eb)
-----------------
--- Resizable ---
-----------------
f:SetResizable(true)
f:SetMinResize(150, 100) -- at least show the "okay" button
local rb = CreateFrame("Button", "KethoEditBoxResizeButton", KethoEditBox)
rb:SetPoint("BOTTOMRIGHT", -6, 7); rb:SetSize(16, 16)
rb:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
rb:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
rb:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
rb:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
f:StartSizing("BOTTOMRIGHT")
self:GetHighlightTexture():Hide() -- we only want to see the PushedTexture now
end
end)
rb:SetScript("OnMouseUp", function(self, button)
f:StopMovingOrSizing()
self:GetHighlightTexture():Show()
eb:SetWidth(sf:GetWidth()) -- update editbox to the new scrollframe width
end)
f:Show()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment