--[[------------------------------------------------------------ -- Method: AddButton -- -- data - A table local to YOUR addon that will contain all the -- data for your addon. -- text - The button's text. -- onclick - The function that the button will call when clicked. -- onshow - (Optional) The function that the button will call when shown. -- onhide - (Optional) The function that the button will call when hidden. -- pt - (Optional) Override the default anchor setting. -- ox - (Optional) Override the default offset setting in pixels for x. -- oy - (Optional) Override the default offset setting in pixels for y. -- rp - (Optional) Override the default relative parent. -- rpt - (Optional) Override the default relative point. -- -- This is mostly a copy of OptionsButtonTemplate, -- going down the inheritance chain. --------------------------------------------------------------]] function lib:AddButton(data,text,onclick,onshow,onhide,pt,ox,oy,rp,rpt) if data and text and onclick then local f local tab = data[ data["_t"] ] local tcol = tab[ tab["_nc"] ] if tab["_nc"] == 1 then table.insert( tcol, CreateFrame("Button",nil, data["_f"] ) ) else table.insert( tcol, CreateFrame("Button",nil, tab[1][1] ) ) end tcol["_size"] = tcol["_size"] + 1 f = tcol[ tcol["_size"] ] f:SetTextFontObject( getglobal("GameFontNormal") ) f:SetDisabledFontObject( getglobal("GameFontDisable") ) f:SetHighlightFontObject( getglobal("GameFontHighlight") ) f:SetNormalTexture("Interface\\Buttons\\UI-Panel-Button-Up") f:SetPushedTexture("Interface\\Buttons\\UI-Panel-Button-Down") f:SetDisabledTexture("Interface\\Buttons\\UI-Panel-Button-Disabled" ) f:SetHighlightTexture("Interface\\Buttons\\UI-Panel-Button-Highlight" ) self:ReadjustPoint(data,f,pt,ox,oy,rp,rpt) f:SetText(text) local fs = f:CreateFontString() fs:SetPoint("BOTTOMLEFT", f, "LEFT", f:GetTextWidth() / 7, 0.5) f:SetFontString( fs ) f:SetText(text) f:SetWidth( f:GetTextWidth() * 2 + 6 ) f:SetHeight( 32 ) self:ReadjustSize(data, f:GetWidth(), f:GetHeight() ) f:SetScript("OnClick", onclick) if onshow then f:SetScript("OnShow", onshow) end if onhide then f:SetScript("OnHide", onhide) end elseif not data then self:Print("In AddButton() - Invalid data table given.") elseif not text then self:Print("In AddButton() - No text given.") elseif not onclick then self:Print("In AddButton() - No OnClick function given.") end end