Thread Tools Display Modes
11-26-09, 03:30 PM   #1
kenuvis
A Defias Bandit
Join Date: Nov 2009
Posts: 3
Create a Button

Its so simple, but i am to silly.

i want simply create a button in lua using that:

Code:
        local button = CreateFrame("Button", "only_for_testing", mainframe)
        button:SetPoint("CENTER", mainframe, "CENTER", 0, 0)
        button:SetWidth(200)
        button:SetHeight(50)
        
        button:SetText("My Test")
        button:SetNormalFontObject("GameFontNormalSmall")
        
        button:SetNormalTexture("Interface/Buttons/UI-Panel-Button-Up")
        button:SetHighlightTexture("Interface/Buttons/UI-Panel-Button-Highlight")
        button:SetPushedTexture("Interface/Buttons/UI-Panel-Button-Down")
I see the button but the text is set to the bottomleft of the button and it seems so, i can do, whatever i want, i dont get it to the center of the button.

Last edited by kenuvis : 11-26-09 at 04:24 PM.
  Reply With Quote
11-28-09, 07:37 AM   #2
kenuvis
A Defias Bandit
Join Date: Nov 2009
Posts: 3
here is my quick'n'dirty solution, but......its not realy fine.

Code:
	local fo = button:CreateFontString()
	fo:SetFont("Fonts/FRIZQT__.TTF",12)
	fo:SetPoint("TOPLEFT", button, "TOPLEFT", 200/6,-50/4)
	fo:SetText("test")
	button:SetFontString(fo)
Commands like fo:SetJustifyH will have no effekt and so, I must move it this stupid way. Hopefully, you have a better solution.

PS: I see, the button has not the size (200x50) it should have, so the text is in the middle, but the button is not right, wtf !

Last edited by kenuvis : 11-28-09 at 08:14 AM.
  Reply With Quote
11-28-09, 09:01 AM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
I don't recall ever having font alignment problems on my buttons but what I always did was use a pre-defined font type on it which may have been set up correctly.

After creating the button and setting the buttons features I would then do the following:

Code:
button:SetDisabledFontObject(GameFontDisable)
button:SetHighlightFontObject(GameFontHighlight)
button:SetNormalFontObject(GameFontNormal)
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
11-28-09, 10:04 AM   #4
kenuvis
A Defias Bandit
Join Date: Nov 2009
Posts: 3
So, i have it all right, I must scale the texture of the Button.

here is the working script for all other having this problem:

Code:
	local button = CreateFrame("Button", nil, mainframe)
	button:SetPoint("CENTER", mainframe, "CENTER", 0, 0)
	button:SetWidth(200)
	button:SetHeight(50)
	
	button:SetText("test")
	button:SetNormalFontObject("GameFontNormal")
	
	local ntex = button:CreateTexture()
	ntex:SetTexture("Interface/Buttons/UI-Panel-Button-Up")
	ntex:SetTexCoord(0, 0.625, 0, 0.6875)
	ntex:SetAllPoints()	
	button:SetNormalTexture(ntex)
	
	local htex = button:CreateTexture()
	htex:SetTexture("Interface/Buttons/UI-Panel-Button-Highlight")
	htex:SetTexCoord(0, 0.625, 0, 0.6875)
	htex:SetAllPoints()
	button:SetHighlightTexture(htex)
	
	local ptex = button:CreateTexture()
	ptex:SetTexture("Interface/Buttons/UI-Panel-Button-Down")
	ptex:SetTexCoord(0, 0.625, 0, 0.6875)
	ptex:SetAllPoints()
	button:SetPushedTexture(ptex)
  Reply With Quote
11-28-09, 10:16 AM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
Cool, glad you got it all sorted.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Create a Button

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off