DIconLayout Childeren Issues

So after messing around with one of my item display menus, I am unable to resize my main panel depending on the contents of a DIconLayout. There’s probably other ways to do this but…



function DLabelColoredList(listcontainer, list)
    for k, v in pairs( list ) do
        if (k%2==0) then
            local words = string.Explode( " ", v) or v
            for i, l in pairs( words ) do
                local word = vgui.Create("DLabel", listcontainer)
                word:SetColor(list[k-1]) 
                word:SetFont("sliminventory_bars")
                word:SetText(l)
                word:SizeToContents() 
                listcontainer:Add( word )
            end
        end
    end
end
--Put the function here to explain what it does, just adds dlabels to the iconlayout.



              
        self.descListPanel = vgui.Create( "DIconLayout", self)
        self.descListPanel:SetSize( self:GetWide()-12, 0) --setting the height is pointless as it rescales anyway.
        self.descListPanel:SetPos( 6, 58 )
        self.descListPanel:SetSpaceY( 0 )
        self.descListPanel:SetSpaceX( 4 )
        
        local fplist = {Color(255,255,255,255),"Alyx is a skilled hacker: she is able to operate and manipulate Combine-based objects such as turrets with the help of her gear."} --examplelist
        DLabelColoredList(self.descListPanel, fplist)

        local w,h = self.descListPanel:ChildrenSize() 
        self:SetHeight(self:GetTall()+h) --Adding the height onto parent panels


The ChildrenSize() method should be:

Meaning it should grab the lowest bound of the children inside the DIconLayout, but this does not seem to work as shown:

I’ve tried other various methods of getting the definite height of the panel but it doesn’t seem to work. Never usually come here for help but this is confusing me, so any replacement methods or fixes would be appreciated!

InvalidateLayout(true) on all of the children before doing ChildrenSize(), especially on labels.

Maybe on the panel/canvas itself too.

Thanks but, after trying it on all, it never seemed to change anything.

Below is another method I was going to try but:
Whilst I’m not entirely sure how DIconLayout works but grabbing positions of any of it’s children returns 0.



      self.descListPanel:InvalidateLayout( true )
        local w,h = self.descListPanel:ChildrenSize()
	
        self:SetHeight(self:GetTall()+h) --Adding the height onto parent panels

This does it for me.

Also you really shouldn’t be creating a DLabel for every word in the string, it will cause performance issues.

[editline]10th December 2016[/editline]

And DIconLayout is really not the panel for the job.

Oh, thanks a lot! Not entirely sure why it didn’t work previously, I assume I put the invalidate before adding the children.

I don’t really know what else I could use with auto formatting and allowing to change the colour of each word, this was the first thing that came to mind :smile:

That’s some nice looking stuff you got there.

Has it ever crossed your mind that stealing designs/ideas from people isn’t a good thing? Please don’t steal from my server.

[editline]10th December 2016[/editline]

If you’d like to keep using DLabel’s for every word, which I wouldn’t recommend, Rubat’s solution works. But you really should just create one panel and make a text wrapping function. That’s what I did at least.

I was gunna shoot you a PM - I liked the design, sorry I tried to recreate it :v:
I don’t plan to do anything with it, it’s more for learning purposes.

[editline]10th December 2016[/editline]

Could I perhaps add you to talk about this?