what is the math behind panel:Center()

I’m making a simple menu with 4 buttons lined up vertically. If i use panel:Center(), it will just center all the buttons to my base DFrame, which is impractical because all the buttons stack on top of each other, and the last drawn button is the only one you can click.
Is there a function to center them width-wise or height-wise?
Or do I have to make a function where it does all the math behind it.
If there isn’t, could someone explain the math behind it? I couldn’t seem to find it anywhere on youtube/google/dev discussion forums.

(Screen’s/Container’s Width / 2) - (Panel’s Width / 2)


button:SetPos( ( ScrW() / 2 ) - ( baseFrame:GetWide() / 2 ) )

I have the button parented to the frame by the way, also if i do this for my button, it doesn’t show up on the DFrame. Added a chat.AddText to debug, and it’s returning 840 if that helps.
To clarify, this only works if you don’t parent the button to a panel or frame.

Panel:CenterHorizontal and

Panel:CenterVertical?

[editline]26th January 2016[/editline]

Also, perhaps the button isn’t showing up because the SetPos is local to the panel rather than the screen if you parent it… probably not though, but maybe worth a shot? Try removing the ScrW() / 2 bit

[editline]26th January 2016[/editline]

Also, try doing something like

Panel:InvalidateLayout on all your buttons cause they might be returning the wrong size

You’re supposed to use the frame’s width instead of the screen’s width, and then use the button’s width.
[lua]element:SetPos((parent:GetWide() / 2) - (element:GetWide() / 2), y)[/lua]
Replace the variable names. Replace y with whatever value you want for the y.

-snip

someone ninja replied above while i was posting