summaryrefslogtreecommitdiff
path: root/utils/vgui_panel_zoo/TextEntryDemo.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/vgui_panel_zoo/TextEntryDemo.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'utils/vgui_panel_zoo/TextEntryDemo.cpp')
-rw-r--r--utils/vgui_panel_zoo/TextEntryDemo.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/utils/vgui_panel_zoo/TextEntryDemo.cpp b/utils/vgui_panel_zoo/TextEntryDemo.cpp
new file mode 100644
index 0000000..499ecfc
--- /dev/null
+++ b/utils/vgui_panel_zoo/TextEntryDemo.cpp
@@ -0,0 +1,101 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+#include "DemoPage.h"
+
+#include <VGUI/IVGui.h>
+
+#include <vgui_controls/TextEntry.h>
+
+
+using namespace vgui;
+
+//-----------------------------------------------------------------------------
+// Text Entry controls are notepad-like windows that hold text.
+// They have a border around them and typically hold editable text information.
+// In this demo we create a very simple text entry window. It holds one
+// line of text and is editable. Typing more text will fill the window with
+// text and as you hit the end the text will scroll.
+// The cursor can be moved
+// around with arrow keys or positioned with the mouse. Clicking and dragging
+// will select text. Right clicking in
+// a text edit window will open a cut/copy/paste dropdown, and the windows
+// keyboard commands will work as well (ctrl-c/ctrl-v). Some other windows
+// keys work as well (home, delete, end).
+// When URL's are displayed in TextEntry windows they become clickable, and
+// will open a browser when clicked.
+//-----------------------------------------------------------------------------
+class TextEntryDemo: public DemoPage
+{
+ public:
+ TextEntryDemo(Panel *parent, const char *name);
+ ~TextEntryDemo();
+
+ private:
+ void SetVisible(bool status);
+
+ TextEntry *m_pTextEntry;
+};
+
+//-----------------------------------------------------------------------------
+// Purpose: Constructor
+//-----------------------------------------------------------------------------
+TextEntryDemo::TextEntryDemo(Panel *parent, const char *name) : DemoPage(parent, name)
+{
+ m_pTextEntry = new TextEntry(this, "ATextEntry");
+
+ // Get the size of the window
+ int wide, tall;
+ m_pTextEntry->GetSize(wide, tall);
+
+ // Position the window and make it nice and wide, but preserve the
+ // height to one line.
+ m_pTextEntry->SetBounds(100, 100, 200, tall);
+
+ // Insert text after you have set the starting
+ // size and position of the window
+ m_pTextEntry->InsertString("Some starting text");
+
+ // We want all the text in the window selected the
+ // first time the user clicks in the window.
+ m_pTextEntry->SelectAllOnFirstFocus(true);
+
+ // Note window has horizontal scrolling of text on by default.
+ // You can enforce a char limit by using setMaximumCharCount()
+
+
+ // A non editable textentry filled with text to test elipses:
+ TextEntry *m_pTextEntry2 = new TextEntry(this, "ATextEntry");
+ m_pTextEntry2->SetBounds(100, 130, 200, tall);
+ m_pTextEntry2->InsertString("Some starting text longer than before for an elipsis");
+ m_pTextEntry2->SetHorizontalScrolling(false);
+}
+
+void TextEntryDemo::SetVisible(bool status)
+{
+ // We want all the text in the window selected the
+ // first time the user clicks in the window.
+ if (status)
+ m_pTextEntry->SelectAllOnFirstFocus(true);;
+
+ DemoPage::SetVisible(status);
+
+}
+
+//-----------------------------------------------------------------------------
+// Purpose: Destructor
+//-----------------------------------------------------------------------------
+TextEntryDemo::~TextEntryDemo()
+{
+}
+
+
+Panel* TextEntryDemo_Create(Panel *parent)
+{
+ return new TextEntryDemo(parent, "TextEntryDemo");
+}
+
+