• DButton not working
    5 replies, posted
Hey, I'm currently working on a GUI for a shop, and I have this DButton's who text align got glitchy (Should be centered), The text (Buy) got cut off to B..., it doesn't change its look when I hover over it and its DoClick function doesn't run... Is anyone familiar with this issue and can help? This is what it looks like: [IMG]http://imgur.com/WHmoWBj.jpg[/IMG] The button itself is inside a panel which is inside a pane. Thanks
Show code of your button.
Tried to narrow it down as much as I could: [CODE] self.rightPane = vgui.Create("DPanelList", self); self.rightPane:EnableVerticalScrollbar(true); self.rightPane:SetSpacing(6); self.rightPane:StretchToParent(self.categoryList:GetWide()+8, 4, 4, 4); local gradient = surface.GetTextureID("VGUI/gradient_down"); local quadObj = { texture = gradient, color = Color(0, 0, 0, 200), x = 0, y = 0, w = ScrW() }; function self.rightPane:Paint() quadObj.h = self:GetTall(); draw.TexturedQuad(quadObj); end; local buttonPanel = vgui.Create("DPanel"); buttonPanel:SetTall(30); buttonPanel.useButton = vgui.Create("DButton", buttonPanel); buttonPanel.useButton:SetTextColor(Color(255, 255, 255)); buttonPanel.useButton:SetSize(self.rightPane:GetWide(), 30); buttonPanel.useButton:SetText("Buy"); buttonPanel.useButton:SetZPos(1000); buttonPanel.useButton.DoClick = function() print("Sending buy command") end; self.rightPane:AddItem(buttonPanel); [/CODE] I might have missed some things in the middle, connecting the parts, but I can't spot any currently
Here's a quick tip for less code: [code] local but = vgui.Create("DButton", buttonPanel) but:SetTextColor(Color(255, 255, 255)) but:SetSize(self.rightPane:GetWide(), 30) but:SetText("Buy") but:SetZPos(1000) but.DoClick = function() print("Sending buy command") end buttonPanel.useButton = but[/code] And what's up with all the semicolons? Lua doesn't need those. Sorry, I can't help you with the problem. Running that button code works just as fine, I you could try doing something like but:InvalidateLayout(true) after self.rightPane has it's width set up.
Thanks for the tips - it didn't work, but I found something else: The functions are nested the following way: PANEL:Layout() |-->other functions |-->Last thing ran before the function ends: function that draw button Now, I found out hat if I create an error after the last line that run, everything works again. But nothing is supposed to run after that, so I see no reason that should happen - is there some function being run when a panel finishes its layout?
[QUOTE=Megolas;44461578]Hey, I'm currently working on a GUI for a shop, and I have this DButton's who text align got glitchy (Should be centered), The text (Buy) got cut off to B..., it doesn't change its look when I hover over it and its DoClick function doesn't run... Is anyone familiar with this issue and can help? This is what it looks like: [IMG]http://imgur.com/WHmoWBj.jpg[/IMG] The button itself is inside a panel which is inside a pane. Thanks[/QUOTE] DButton consists of several vgui elements. The Button, a Label and sometimes an Image. Stretching it may only resize the Button, SizeToContents( ) stretches the Label to the length of text. Call SizeToContents( ) after setting the text, and after stretch to parent
Sorry, you need to Log In to post a reply to this thread.