Parent panel does not invalidate width correctly in the spawn menu
2 replies, posted
Hello, I was updating my Track assembly and I wanted to add some buttons for direct convar control.
The idea is to create 3 more buttons to each slider for controlling the sign, flip and reset of each value
asmlib.SetButtonSlider(CPanel,gsToolPrefL.."nextrol",-gnMaxOffRot, gnMaxOffRot,7,
asmlib.GetPhrase("tool."..gsToolNameL..".nextrol_con"), asmlib.GetPhrase("tool."..gsToolNameL..".nextrol"),
{{Text="+ | -", Click=function()
local nV = asmlib.GetAsmVar("nextrol", "FLT")
RunConsoleCommand(gsToolPrefL.."nextrol",-nV) end},
{Text="< | >", Click=function()
local nV = asmlib.GetAsmVar("nextrol", "FLT")
RunConsoleCommand(gsToolPrefL.."nextrol",asmlib.GetSign(nV)*180) end},
{Text="> 0 <", Click=function()
RunConsoleCommand(gsToolPrefL.."nextrol",0) end}})
This creates a child panel that is "cPanel:AddItem(pPanel)"-ED to the tool panel "cPanel":
function SetButtonSlider(cPanel,sVar,nMin,nMax,nDec,sDsc,sTip,tBtn)
local pPanel = vguiCreate("DPanel"); if(not IsValid(pPanel)) then
LogInstance("Panel invalid"); return nil end
pPanel:SetParent(cPanel)
pPanel:InvalidateLayout(true)
LogInstance("Panel OK")
local sX = pPanel:GetWide()
local vX, vY = pPanel:GetSize()
print("SetButtonSlider", vX, vY)
print("SetButtonSlider", pPanel:GetWide(), cPanel:GetWide())
local sY, pY, dX, dY, mX = 50, 0, 2, 2, 10
pPanel:SetSize(sX, sY); pY = dY
pPanel:SetVisible(true)
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
LogInstance("Button["..iCnt.."] OK")
pButton:SetParent(pPanel)
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 = vBtn.Click
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
LogInstance("Slider OK")
pSlider:SetParent(pPanel)
pSlider:SetPos(0, pY)
pSlider:SetSize(sX-2*dX, sY-pY-dY)
pSlider:SetText(tostring(sDsc))
if(sTip) then pSlider:SetTooltip(tostring(sTip)) end
pSlider:SetMin(nMin)
pSlider:SetMax(nMax)
pSlider:SetDecimals(nDec)
pSlider:SetDark(true)
pSlider:SetConVar(sVar)
pSlider:SetVisible(true)
cPanel:AddItem(pPanel)
return pPanel
end
When the game loads it outputs:
SetButtonSlider 64 24
SetButtonSlider 64 16
The log outputs:
155 [30-12-18 14:58:07] CLIENT > TRACKASSEMBLY [LUA] SetButtonSlider: Panel OK
156 [30-12-18 14:58:07] CLIENT > TRACKASSEMBLY [LUA] SetButtonSlider: Button[1] OK
157 [30-12-18 14:58:07] CLIENT > TRACKASSEMBLY [LUA] SetButtonSlider: Button[2] OK
158 [30-12-18 14:58:07] CLIENT > TRACKASSEMBLY [LUA] SetButtonSlider: Button[3] OK
159 [30-12-18 14:58:07] CLIENT > TRACKASSEMBLY [LUA] SetButtonSlider: Slider OK
This means that all panels are created correctly, however the spawn menu looks like this
how_it_behaves.jpg
As you see the buttons are squashed, because when the game loads, it reports to my script that the panel is 64 pixels
wide instead of about:
(5.8 centimeters) * (1900 resolution width) / (41 gmod window size in centimeters) = 268.780487805 pixels.
When hard-coding the value I got the following:
https://drive.google.com/file/d/1PtMlljNwbdqxF0vAvaKa_Zm5gs_HpR2G/view?usp=sharing
When I opened the context menu I saw a slight offset on the right ( BLUE ):
https://drive.google.com/file/d/1cjkL-9YNIJLOHjvjhLPsA4lZTSUjsrUC/view?usp=sharing
How can I take the actual width of the parent panel "pPanel" and make the three buttons look the same in the context
menu and the spawn menu without the offset in blue ?
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.
This is not in the right section you can delete it.
Sorry, you need to Log In to post a reply to this thread.