TextBox.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "UnitTest.h"
  2. #include "Gwen/Controls/TextBox.h"
  3. using namespace Gwen;
  4. class TextBox : public GUnit
  5. {
  6. public:
  7. GWEN_CONTROL_INLINE( TextBox, GUnit )
  8. {
  9. {
  10. Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox( this );
  11. label->SetText( "" );
  12. label->SetPos( 10, 10 );
  13. label->onTextChanged.Add( this, &ThisClass::OnEdit );
  14. label->onReturnPressed.Add( this, &ThisClass::OnSubmit );
  15. }
  16. {
  17. Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox( this );
  18. label->SetText( "Normal Everyday Label" );
  19. label->SetPos( 10, 10 + 25 );
  20. }
  21. {
  22. Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox( this );
  23. label->SetText( "Select All Text On Focus" );
  24. label->SetPos( 10, 10 + 25 * 2 );
  25. label->SetSelectAllOnFocus( true );
  26. }
  27. {
  28. Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox( this );
  29. label->SetText( L"Different Coloured Text, for some reason" );
  30. label->SetTextColor( Gwen::Color( 255, 0, 255, 255 ) );
  31. label->SetPos( 10, 10 + 25 * 3 );
  32. }
  33. {
  34. Gwen::Controls::TextBoxNumeric* label = new Gwen::Controls::TextBoxNumeric( this );
  35. label->SetText( L"2004" );
  36. label->SetTextColor( Gwen::Color( 255, 0, 255, 255 ) );
  37. label->SetPos( 10, 10 + 25 * 4 );
  38. }
  39. {
  40. m_Font.facename = L"Impact";
  41. m_Font.size = 50;
  42. Gwen::Controls::TextBox* label = new Gwen::Controls::TextBox( this );
  43. label->SetText( L"Different Font" );
  44. label->SetPos( 10, 10 + 25 * 5 );
  45. label->SetFont( &m_Font );
  46. label->SetSize( 200, 55 );
  47. }
  48. }
  49. void OnEdit( Gwen::Controls::Base* pControl )
  50. {
  51. Gwen::Controls::TextBox* textbox = (Gwen::Controls::TextBox*) (pControl);
  52. UnitPrint( Utility::Format( L"Textbox Edit: [%s]\n", textbox->GetText().c_str() ) );
  53. }
  54. void OnSubmit( Gwen::Controls::Base* pControl )
  55. {
  56. Gwen::Controls::TextBox* textbox = (Gwen::Controls::TextBox*) (pControl);
  57. UnitPrint( Utility::Format( L"Textbox Submit: [%s]\n", textbox->GetText().c_str() ) );
  58. }
  59. Gwen::Font m_Font;
  60. };
  61. DEFINE_UNIT_TEST( TextBox, L"TextBox" );