WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Create a Button (https://www.wowinterface.com/forums/showthread.php?t=28736)

kenuvis 11-26-09 03:30 PM

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.

kenuvis 11-28-09 07:37 AM

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 !

Xrystal 11-28-09 09:01 AM

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)


kenuvis 11-28-09 10:04 AM

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)


Xrystal 11-28-09 10:16 AM

Cool, glad you got it all sorted.


All times are GMT -6. The time now is 06:39 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI