Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "DemoPage.h"
  8. #include <VGUI/IVGui.h>
  9. #include <vgui_controls/TextEntry.h>
  10. using namespace vgui;
  11. //-----------------------------------------------------------------------------
  12. // Text Entry controls are notepad-like windows that hold text.
  13. // They have a border around them and typically hold editable text information.
  14. // In this demo we create a very simple text entry window. It holds one
  15. // line of text and is editable. Typing more text will fill the window with
  16. // text and as you hit the end the text will scroll.
  17. // The cursor can be moved
  18. // around with arrow keys or positioned with the mouse. Clicking and dragging
  19. // will select text. Right clicking in
  20. // a text edit window will open a cut/copy/paste dropdown, and the windows
  21. // keyboard commands will work as well (ctrl-c/ctrl-v). Some other windows
  22. // keys work as well (home, delete, end).
  23. // When URL's are displayed in TextEntry windows they become clickable, and
  24. // will open a browser when clicked.
  25. //-----------------------------------------------------------------------------
  26. class TextEntryDemo: public DemoPage
  27. {
  28. public:
  29. TextEntryDemo(Panel *parent, const char *name);
  30. ~TextEntryDemo();
  31. private:
  32. void SetVisible(bool status);
  33. TextEntry *m_pTextEntry;
  34. };
  35. //-----------------------------------------------------------------------------
  36. // Purpose: Constructor
  37. //-----------------------------------------------------------------------------
  38. TextEntryDemo::TextEntryDemo(Panel *parent, const char *name) : DemoPage(parent, name)
  39. {
  40. m_pTextEntry = new TextEntry(this, "ATextEntry");
  41. // Get the size of the window
  42. int wide, tall;
  43. m_pTextEntry->GetSize(wide, tall);
  44. // Position the window and make it nice and wide, but preserve the
  45. // height to one line.
  46. m_pTextEntry->SetBounds(100, 100, 200, tall);
  47. // Insert text after you have set the starting
  48. // size and position of the window
  49. m_pTextEntry->InsertString("Some starting text");
  50. // We want all the text in the window selected the
  51. // first time the user clicks in the window.
  52. m_pTextEntry->SelectAllOnFirstFocus(true);
  53. // Note window has horizontal scrolling of text on by default.
  54. // You can enforce a char limit by using setMaximumCharCount()
  55. // A non editable textentry filled with text to test elipses:
  56. TextEntry *m_pTextEntry2 = new TextEntry(this, "ATextEntry");
  57. m_pTextEntry2->SetBounds(100, 130, 200, tall);
  58. m_pTextEntry2->InsertString("Some starting text longer than before for an elipsis");
  59. m_pTextEntry2->SetHorizontalScrolling(false);
  60. }
  61. void TextEntryDemo::SetVisible(bool status)
  62. {
  63. // We want all the text in the window selected the
  64. // first time the user clicks in the window.
  65. if (status)
  66. m_pTextEntry->SelectAllOnFirstFocus(true);;
  67. DemoPage::SetVisible(status);
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose: Destructor
  71. //-----------------------------------------------------------------------------
  72. TextEntryDemo::~TextEntryDemo()
  73. {
  74. }
  75. Panel* TextEntryDemo_Create(Panel *parent)
  76. {
  77. return new TextEntryDemo(parent, "TextEntryDemo");
  78. }