Using a table to display messages in custom chat box

I put together a variety of DPanel’s parented to a DFrame, with a DEntryText to draw a chat window with an input box. When a player (the author) types a message and presses enter I send a network message to the server which then scans for all player entities in a radius of 3500 units, stores them as recipients, then networks to all recipients client-sided telling them they’ve received a new message.

All received messages get stored in a client-sided table containing a chat channel, author entity, and message text. This seems to work just fine, however I’m having a lot of trouble wrapping my head around the vgui library. I took a look at cl_scoreboard.lua in the base gamemode but wasn’t able to decipher how it works.

I’m curious if somebody here could help me out. Here’s a screenshot of my chatbox:
http://cloud-4.steampowered.com/ugc/50991810494421513/75B6050EA2D6052D636C20923F04252439A82D14/

This is my message table structure:



[1]
	[author] 	= Player [123][Jake][STEAM_0:0:9462385] 
	[channel] 	= general
	[message] 	= yo
[2]
	[author] 	= Player [123][Jake][STEAM_0:0:9462385] 
	[channel] 	= general
	[message] 	= yo123
[3]
	[author] 	= Player [123][Jake][STEAM_0:0:9462385] 
	[channel] 	= general
	[message] 	= testi message
[4]
	[author] 	= Player [123][Jake][STEAM_0:0:9462385] 
	[channel] 	= general
	[message] 	= yea


What I’m trying to do is iterate through the messages and list them out in a scrollbar panel inside the dialog box as efficiently as possible. Hopefully there’s a way to do it with customization in mind, I’d like to be able to modify colors & fonts later on

Replace your DPanel with a DScrollPanel then register a VGUI that is basically going to be a panel displaying the chat text, add these VGUIs to the DScrollPanel.

Do I need to iterate through my messages table and create a separate panel for each message? Is it possible to stack panels on top of each other inside the DScrollPanel without manually settings their Y position?

If you just set the DScrollPanel as the parent they should just stack up.

Ah, the solution is a bit less complex then I thought. I tend to overthink sometimes =\

Here’s what I have
http://cloud-4.steampowered.com/ugc/50991810509921290/3976310FC43688F66A890E72437378D107AAAFCF/



local _p = vgui.Create("DPanel", g_DialogBox)
_p:SetBackgroundColor(Color(25, 25, 25))
_p:Dock(TOP)
	
local _text = vgui.Create("DLabel", _p)
_text:SetText(author:Name() .. " : 
" .. message)
_text:SizeToContents()


Looks like it’s working. Is it possible to adjust the height of the DPanel so the text doesn’t overflow horizontally? And hopefully my last question, is it possible to have the scrollbar scrolled all the way down by default? At the moment it’s scrolled all the way up by default every time the chat box is opened

edit: Finally got it all figured out. Here’s how it looks now
http://cloud-4.steampowered.com/ugc/50991810515374852/BB93A8CD0A04DDB3860BB3A02B726B1123BF84C1/