Derma GetPos

Ok, so I started Derma the other day, and it’s… really interesting me. It’s great! Quite flexible, easy to code, e.t.c. My only problem is… well, take this, for example:

[lua]menu1 = vgui.Create(“DButton”)
frame:SetPos(50,50)
frame:SetSize(300, 300)
frame:SetTitle( “Klesk’s Client Menu” )
frame:SetVisible( true )
frame:MakePopup()
menu1:SetParent( frame )
menu1:SetText( “Player” )
menu1:SetPos(100, 100)
menu1:SetSize( 100, 20 )
[/lua]

Getting a Vector on the first try. Whenever I code a simple button, I usually have to fiddle around with the Vectors for a little until I get it just right (sometimes ranging from 5-15 minutes). I eventually get it in the right place, but… I’d like to get the Vector of where I want to put the button, instead of guess/check. I was talking to a friend about this and he said there is a command/hook for it… GetPos or something like that; I’m not sure if he’s right or not, but… Is there a way I can get the Vector of where my cursor is? Doesn’t have to be -exactly- like that, but it would be lovely if it was that simple.

Thanks!

First thing: it’s not a vector, it’s an x-y position on your screen. :stuck_out_tongue:

Second: there is indeed a panel:GetPos(). It returns two values, so it would look like this:


local menux, menuy = menu1:GetPos()

Important to note is that it’s local to the parent (i.e. not where it is on the screen, but where it is in the frame).

Wait, why are you spending 15 minutes to position a button?
Just a helpful derma tip: it’s good to position things using the width/height of an object rather than with constants, as it is more precise and will stay formatted if you change the size of the parent. For example, this is a generic thing to center any object in its parent:


panel:SetPos(parent:GetWide()/2-panel:GetWide()/2,parent:GetTall()/2-panel:GetTall()/2)

Alright; Thank you!