summaryrefslogtreecommitdiff
path: root/utils/vgui_panel_zoo/EditablePanelDemo.cpp
blob: fb7cfccb534217ccac711e31b545faacd9df0017 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#include "DemoPage.h"

#include "vgui/IVGui.h"
#include "vgui_controls/Controls.h"

#include "tier1/KeyValues.h"
#include <vgui_controls/EditablePanel.h>
#include <vgui_controls/Label.h>
#include <vgui_controls/ComboBox.h>

using namespace vgui;

// EditablePanels are panels that can create certain vgui controls 
// by using the function createControlByName()


class EditablePanelDemo: public DemoPage
{
	public:
		EditablePanelDemo(Panel *parent, const char *name);
		~EditablePanelDemo();
	
	private:
		EditablePanel *m_pEditablePanel;
		Label *m_pSpeedLabel;
		ComboBox *m_pInternetSpeed;

};

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
EditablePanelDemo::EditablePanelDemo(Panel *parent, const char *name) : DemoPage(parent, name)
{
	// Create an EditablePanel.
	m_pEditablePanel = new EditablePanel(this, "AnEditablePanel");

	
	// Set its position and size
	m_pEditablePanel->SetSize(400, 200);
	m_pEditablePanel->SetPos(0, 0);

	// Add a child Label panel to the EditablePanel
	m_pSpeedLabel = (Label *)(m_pEditablePanel->CreateControlByName("Label"));
	// Set its parent to our editable panel.
	m_pSpeedLabel->SetParent(m_pEditablePanel);
	// Set its Position
	m_pSpeedLabel->SetPos(20, 30);
	// Set its size
	m_pSpeedLabel->SetSize(96,20);
	// Set it not to resize with the window.
	m_pSpeedLabel->SetAutoResize(PIN_TOPLEFT, AUTORESIZE_NO, 0, 0, 0, 0 );
	// Set it visible
	m_pSpeedLabel->SetVisible(true);
	// Set it enabled
	m_pSpeedLabel->SetEnabled(true);
	// Set its tab position
	m_pSpeedLabel->SetTabPosition(0);
	// Set the text in the label
	m_pSpeedLabel->SetText("Internet &Speed");
	// Set its text alignment
	m_pSpeedLabel->SetContentAlignment(Label::a_east);
	
	// Add another child panel to the EditablePanel, this time a ComboBox.
	
	// This will be the menu items of our combo box menu.	
	// List of all the different internet speeds
	char *g_Speeds[] =
	{
		{ "Modem - 14.4k"},
		{ "Modem - 28.8k"},
		{ "Modem - 33.6k"},
		{ "Modem - 56k"},
		{ "ISDN - 112k"},
		{ "DSL > 256k"},
		{ "LAN/T1 > 1M"},		
	};

	// Create the combo box using the create function
	m_pInternetSpeed = (ComboBox *)(m_pEditablePanel->CreateControlByName("ComboBox"));
	// Set its parent to our editable panel.
	m_pInternetSpeed->SetParent(m_pEditablePanel);
	// Set its position next to the label.
	m_pInternetSpeed->SetPos(124, 30);
	// Set its size
	m_pInternetSpeed->SetSize(200, 20);
	// Set it not to resize with the window.
	m_pInternetSpeed->SetAutoResize(PIN_TOPLEFT, AUTORESIZE_NO, 0, 0, 0, 0 );
	// Set it visible
	m_pInternetSpeed->SetVisible(true);
	// Set it enabled
	m_pInternetSpeed->SetEnabled(true);
	// Set its tab position
	m_pInternetSpeed->SetTabPosition(0);
	// Set its text hidden attribute
	m_pInternetSpeed->SetTextHidden(false);
	// Set it not editable
	m_pInternetSpeed->SetEditable(false);
	// Set its maxchars to -1 since it is not editable
	//m_pInternetSpeed->SetMaximumCharCount(-1);
	// Set the number of items in the combo box menu
	m_pInternetSpeed->SetNumberOfEditLines(ARRAYSIZE(g_Speeds));
	// Set the drop down arrow button visible
	m_pInternetSpeed->SetDropdownButtonVisible(true);


	// Add menu items to this combo box.
	for (int i = 0; i < ARRAYSIZE(g_Speeds); i++)
	{
		m_pInternetSpeed->AddItem(g_Speeds[i], NULL );
	}

	// Associate our label with our combo box
	m_pSpeedLabel->SetAssociatedControl(m_pInternetSpeed);

	// Now you're saying... why bother using an EditablePanel class for this?
	// I could have just created a panel and just created each child panel on my own
	// using code like this: memberLabel =  new Label(NULL, NULL, "Label");
	// I could have even saved many lines of code by choosing nice constructor args.
	// Well the real power of editable panels lies in the use of Resource Files
	// as seen in the next example.
}

//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
EditablePanelDemo::~EditablePanelDemo()
{
}



Panel* EditablePanelDemo_Create(Panel *parent)
{
	return new EditablePanelDemo(parent, "EditablePanelDemo");
}