VGUI PanelListPanel: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
Line 18: Line 18:
  {
  {
  BaseClass::ApplySchemeSettings( pScheme );
  BaseClass::ApplySchemeSettings( pScheme );
 
  vgui::Label* label = new Label( this, "label1", "Label1" );
  vgui::Label* label = new Label( this, "label1", "Label1" );
  label->SetText("Label1");
  label->SetText("Label1");
 
  for (int i = 0; i < 5; i++)
  for (int i = 0; i < 5; i++)
  {
  {

Revision as of 21:59, 6 June 2009

A PanelListPanel is a vgui2 element defined in the vgui_controls library, in the file PanelListPanel.cpp. PanelListPanels are available in all source games. PanelListPanels display a list of user specified label, control pairs.

This is a screenshot of a skeleton PanelListPanel.

Example Usage

Before creating anything, we first need to include the PanelListPanel header file.

#include <vgui_controls/PanelListPanel.h>

PanelListPanels can be created via the c++ keyword new with a simple call to PanelListPanel.

vgui::PanelListPanel* myPanel = new PanelListPanel(this, "myPanel");

Once we have our PanelListPanel created, we can add controls to it in our ApplySchemeSettings function. Heres the ApplySchemeSettings function for the skeleton PanelListPanel displayed in the image above:

void CItemMenu::ApplySchemeSettings( vgui::IScheme *pScheme )
{
	BaseClass::ApplySchemeSettings( pScheme );

	vgui::Label* label = new Label( this, "label1", "Label1" );
	label->SetText("Label1");

	for (int i = 0; i < 5; i++)
	{
		char buffer [40];

		Q_snprintf(buffer, sizeof(buffer), "image%i", i);
		vgui::ImagePanel* imagePanel = new ImagePanel( this, buffer );
		imagePanel->SetImage(scheme()->GetImage("materials/HUD/eye", false));

		Q_snprintf(buffer, sizeof(buffer), "label%i", i);
		vgui::Label* label = new Label( this, buffer, buffer );
		label->SetText(buffer);

		m_pList->AddItem(label, imagePanel);
	}

	m_pList->SetVisible( true );