• Derma panels are not resizing their internal contents in the cPanel
    4 replies, posted
I am trying to create a panel that can contain a bunch of buttons on top and a slider on the bottom for controlling a console variable inside a "TOOL.BuildCPanel(cPanel)". I am having the following problems: 1) When the panel is stretched in the X coordinate the internally created panel elements are not resized. 2) When the map is loaded, the "cPanel" does not have a valid width, which results in squashing buttons to zero 3) When I invalidate the cPanel and pPanel it loads the X coordinate with a small 2 digit umber like 64 and the panel looks like this. 4) I want to avoid setting a predefined hard-coded value for "cPanel" to make it appear normal, bit it is not resizable 5) When I recreate the "cPanel" using my gmod_language callback, all panels have normal width derived from cPanel:GetWide() You can find the "test" version in question. I've created this branch to be able to experiment with different panels. I have a definition parameters for my button-sliders like these. For example for adjusting the pitch:   asmlib.SetButtonSlider(CPanel,"nextpic","FLT",-gnMaxOffRot, gnMaxOffRot,7,     {{Text="+5"  , Click=function(sNam, vV) RunConsoleCommand(sNam,snapInc(vV, 5)) end},      {Text="-5"  , Click=function(sNam, vV) RunConsoleCommand(sNam,snapInc(vV,-5)) end},      {Text="+/-" , Click=function(sNam, vV) RunConsoleCommand(sNam,-vV) end},      {Text="@180", Click=function(sNam, vV) RunConsoleCommand(sNam,asmlib.GetSign(vV)*180) end},      {Text="@0"  , Click=function(sNam, vV) RunConsoleCommand(sNam, 0) end}}) I tried "DSizeToContents" instead of a regular panel, where the position and size are inherited and the result is like this: all_options_no_resize.jpg The object is still not resizable when you drag the TOOL menu around. I am expecting the "DNumSLider" and the five "DButton"-s to be able to be squashed/expanded when I interact wit he control panel width. The new handler is like follows: function SetButtonSlider(cPanel,sVar,sTyp,nMin,nMax,nDec,tBtn) local pPanel = vguiCreate("DSizeToContents"); if(not IsValid(pPanel)) then LogInstance("Panel invalid"); return nil end local sY, pY, dX, dY, mX = 45, 0, 2, 2, 10 local sX = (cPanel:GetWide() - 2*mX) local sNam = GetOpVar("TOOLNAME_PL")..sVar local sTag = "tool."..GetOpVar("TOOLNAME_NL").."."..sVar pPanel:SetParent(cPanel) pPanel:SetSize(sX, sY); pY = dY pPanel:SetVisible(true) pPanel:InvalidateLayout() pPanel:SizeToContents() LogInstance("Width ["..sX.."]") if(IsTable(tBtn) and tBtn[1]) then local nBtn, iCnt = #tBtn, 1 local wB, hB = ((sX - ((nBtn + 1) * dX)) / nBtn), 20 local bX, bY = dX, pY while(tBtn[iCnt]) do local vBtn = tBtn[iCnt] local pButton = vguiCreate("DButton"); if(not IsValid(pButton)) then LogInstance("Button["..iCnt.."] invalid"); return nil end pButton:SetParent(pPanel) pButton:InvalidateLayout() pButton:SizeToContents() pButton:SetText(tostring(vBtn.Text)) if(vBtn.Tip) then pButton:SetTooltip(tostring(vBtn.Tip)) end pButton:SetPos(bX, bY) pButton:SetSize(wB, hB) pButton.DoClick = function() vBtn.Click(sNam, GetAsmVar(sVar, sTyp)) end pButton:SetVisible(true) bX, iCnt = (bX + (wB + dX)), (iCnt + 1) end; pY = pY + (dY + hB) end local pSlider = vguiCreate("DNumSlider"); if(not IsValid(pSlider)) then LogInstance("Slider invalid"); return nil end pSlider:SetParent(pPanel) pSlider:InvalidateLayout() pSlider:SizeToContents() pSlider:SetPos(0, pY) pSlider:SetSize(sX-2*dX, sY-pY-dY) pSlider:SetText(GetPhrase(sTag.."_con")) pSlider:SetTooltip(GetPhrase(sTag)) pSlider:SetMin(nMin) pSlider:SetMax(nMax) pSlider:SetDecimals(nDec) pSlider:SetDark(true) pSlider:SetConVar(sNam) pSlider:SetVisible(true) pPanel:InvalidateChildren() pPanel:SetSizeX(false) cPanel:AddItem(pPanel) return pPanel end What am I missing ?? Why the internal "pPanel" elements are not resizable when I drag the panel ?
Hello, is there anyone I made it static. It does not resize itself but oh well it works
As I know, every object inside needs to resolve by PerformLayout or InvalidateLayout inside cPanel PerformLayout
Yeah and that is indeed true, buttons are not resizable.. Anyway.. I noticed that the side panel is created with width of 281 pixels and I used that to align the size of my buttons. Although the buttons created are not resizable, they work correctly, so I suppose resizing is a minor detail.
Found something maybe will help. About SizeToContents() You must call this function AFTER setting text/font, adjusting child panels or otherwise altering the panel.
Sorry, you need to Log In to post a reply to this thread.