Size of spawnmenu

I’m trying to make a page in spawnmenu with multiple elements in it. I’m using PANEL:Dock () to arrange them, like

loadoutm = vgui.Create ("DPanel", panel)
loadoutm:Dock (TOP)
weapm = vgui.Create ("DPanel", panel)
weapm:Dock (TOP)

But when I’m opening the menu for the first time I see this, on second time I open the spawn menu I do see this On second pic you can see how this script should work. I was experimenting with that for a while, and discovered some odds:

hook.Add ("SpawnMenuOpen", "blablabla", function () print (weapm:GetSize(), "< - >", weapm:GetParent():GetSize())

That script returns “1228 < - > 64 24” first time and “1260 < - > 1260 952” right after. Is there any other way I can arrange elements? Or how to deal with the “parent” size? I’ll appreciate any help, because for now it seems like not using :Dock () is the only right way.

Usually when I’m dealing with this sort of pain, I just use


Panel:InvalidateParent and

Panel:InvalidateChildren on everything until it works.

Hm, I used just InvalidateLayout and it didn’t work. I’ll try to use these, thanks :slight_smile:

Sometimes it works if you run them after running a 0 second

timer.Simple. The game has to update the dimensions of the panels but it does it in an annoying way and you have to compensate for that in an even more annoying way

I already tried with 0.1 simple timer, makes no sense. Seems like only second call of SpawnmenuOpen provides correct size of the panels. Probably I need only to replace “DIconLayout” (it is inside “loadoutm” panel, you can see contents on screenshots) with something else…

Since DIconLayout is a Derma element I’m surprised that didn’t work.

Just one last suggestion, did you do

Panel:InvalidateChildren with recursive set as true? It’s probably super slow as it goes through the entire spawnmenu, but maybe it’ll work with a timer?

Sorry for my uselessness so far

I haven’t used it yet, the first time I open the spawn menu, it has size like 60x60, but next frame it fills to 1260x900 or whatever; but custom script still thinks it is 60x60 (idk why, but all the timers return the same data). Panel :Dock() functions don’t react on that, but DIconLayout rebuilds properly. I mean on first frame the width is limited to 60, so iconlayout builds a vertical line of child panels and the vertical size of “loadoutm” panel extends. Next frame iconlayout rebuilds properly, although “loadoutm” doesn’t.
That’s how do I see it. Sorry if I told you something incorrectly, my English is not good enough :c