summaryrefslogtreecommitdiff
path: root/utils/vgui_panel_zoo/TextEntryDemo5.cpp
blob: e49272e116bc6788c6faf5d1c2683c044d048ada (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//
#include "DemoPage.h"

#include <VGUI/IVGui.h>

#include <vgui_controls/TextEntry.h>
#include <vgui/KeyCode.h>

using namespace vgui;

//-----------------------------------------------------------------------------
// Text Entry controls are notepad-like windows that hold text. 
// In this demo we create an editable text entry window that holds multiple lines
// of text. We initialize it with some starting text.
// We override the enter key to clear the text. To add a newline manually you can
// type ctrl-enter
//-----------------------------------------------------------------------------
class TextEntryDemo5: public DemoPage
{
	public:
		TextEntryDemo5(Panel *parent, const char *name);
		~TextEntryDemo5();	
	private:

		void OnKeyCodeTyped(KeyCode code);

		TextEntry *m_pTextEntry;
				
};

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
TextEntryDemo5::TextEntryDemo5(Panel *parent, const char *name) : DemoPage(parent, name)
{
	m_pTextEntry = new TextEntry(this, "AnotherTextEntry");

	// Position the window and make it nice and wide.
	// Make it tall enough to fit several lines of text.
	m_pTextEntry->SetBounds(100, 100, 200, 100);
	

	// Make this window hold multiple lines of text.
	// This will turn off horizontal scrolling, 
	// and wrap text from line to line.
	m_pTextEntry->SetMultiline(true);
	
	// Insert text after you have set the size and position of the window
	m_pTextEntry->InsertString("Some starting text and a pile of text. ");
	m_pTextEntry->InsertString("Some more text to make mutiple lines. ");
	m_pTextEntry->InsertString("Even more scrumptious, chocolatey delicious text. ");
	m_pTextEntry->InsertString("Enough text to get that scroll bar a-scrolling. ");
	m_pTextEntry->InsertString("That's it a nice number of chars.");
}

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

//-----------------------------------------------------------------------------
// Purpose: When the enter key is pressed we clear the textentry.
//  To add a newline use ctrl-return.
//-----------------------------------------------------------------------------
void TextEntryDemo5::OnKeyCodeTyped(KeyCode code)
{
	if (code == KEY_ENTER)
	{
		m_pTextEntry->SetText("");
	}

	DemoPage::OnKeyCodeTyped(code);
}

Panel* TextEntryDemo5_Create(Panel *parent)
{
	return new TextEntryDemo5(parent, "TextEntryDemo5");
}