• How do you set positions of child elements in self-made VGUI element?
    1 replies, posted
Howdy, recently I've been thinking of most proficient way of setting child elements' positions in such situation: [CODE] local PANEL = {} function PANEL:Init() self.closeButton = vgui.Create("DButton") end function PANEL:Paint(w, h) draw.RoundedBox( 0, w-2, h-2, w, 2, self.bColor or Color(100,200,100, 150)) end vgui.Register("m_Frame", PANEL, "DFrame")[/CODE] The way I set [U]self.closeButton[/U]'s position is creating [U]function PANEL:Think()[/U] and setting [U]self.closeButton[/U]'s position in it, but as I think it's one of worst ways doing it so I want to know about other ways doing that :P Thanks.
[CODE]function PANEL:Init() self.closeButton = vgui.Create("DButton",self) --self = PANEL as parent so derma takes care of repositioning the button every frame self.closeButton:SetPos( x, y) --as child these positions are relative to its parent every frame end[/CODE] Else I'd take a look into the garrysmod\lua\vgui folder for code examples.
Sorry, you need to Log In to post a reply to this thread.