That code is actually producing a button... but you can't see it because you didn't give it any visible regions (such as a backdrop, textures, or font strings). You need to either inherit from a template that includes visible regions when you create the button:
Code:
local button = CreateFrame("Button", "MyReloadButton", UIParent, "UIPanelButtonTemplate")
button:SetPoint("CENTER")
button:SetSize(100, 30)
button:SetText("Reload UI")
button:SetMovable(true)
button:SetClampedToScreen(true)
button:RegisterForDrag("RightButton")
button:SetScript("OnDragStart", function(self)
if IsAltKeyDown() then
self:StartMoving()
end
end)
button:SetScript("OnDragStop", button.StopMovingOrSizing)
button:SetScript("OnHide", button.StopMovingOrSizing)
button:SetScript("OnClick", ReloadUI)
... or give the frame visible regions yourself:
Code:
local button = CreateFrame("Button", "MyReloadButton", UIParent)
button:SetPoint("CENTER")
button:SetSize(100, 30)
local texture = button:CreateTexture(nil, "BACKGROUND")
texture:SetAllPoints(true)
texture:SetTexture("Interface\\BUTTONS\\WHITE8X8")
texture:SetVertexColor(0.5, 0, 0)
button:SetNormalTexture(texture)
local text = button:CreateFontString(nil, "OVERLAY", "GameFontNormal")
text:SetAllPoints(true)
text:SetJustifyH("CENTER")
text:SetJustifyV("CENTER")
text:SetTexColor(1, 0.8, 0)
button:SetNormalFontObject(text)
button:SetText("Reload UI")
button:SetMovable(true)
button:SetClampedToScreen(true)
button:RegisterForDrag("RightButton")
button:SetScript("OnDragStart", function(self)
if IsAltKeyDown() then
self:StartMoving()
end
end)
button:SetScript("OnDragStop", button.StopMovingOrSizing)
button:SetScript("OnHide", button.StopMovingOrSizing)
button:SetScript("OnClick", ReloadUI)
I'm also not really sure what you were aiming for with all of the random variables and if/then conditions in your code... the only reason to include anything like that is if you are writing an in-game options UI and need to be able to apply changes on the fly.
Also:
- You don't need to call SetUserPlaced(true) explicitly. It's implied when you StartMoving. The only reason to ever call it directly would be if you want to turn it
off, and you'd need to call it
after StopMovingOrSizing.
- You don't need to ClearAllPoints before you StartMoving.
- You should generally enable SetClampedToScreen, not disable it. Otherwise, you can drag the button off the screen, and have no way to get it back outside of editing saved config files or running slash commands.