ListBox.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "UnitTest.h"
  2. #include "Gwen/Controls/ListBox.h"
  3. using namespace Gwen;
  4. class ListBox : public GUnit
  5. {
  6. public:
  7. GWEN_CONTROL_INLINE( ListBox, GUnit )
  8. {
  9. {
  10. Gwen::Controls::ListBox* ctrl = new Gwen::Controls::ListBox( this );
  11. ctrl->SetBounds( 10, 10, 100, 200 );
  12. ctrl->AddItem( L"First" );
  13. ctrl->AddItem( L"Blue" );
  14. ctrl->AddItem( L"Yellow" );
  15. ctrl->AddItem( L"Orange" );
  16. ctrl->AddItem( L"Brown" );
  17. ctrl->AddItem( L"Green" );
  18. ctrl->AddItem( L"Dog" );
  19. ctrl->AddItem( L"Cat" );
  20. ctrl->AddItem( L"Shoes" );
  21. ctrl->AddItem( L"Chair" );
  22. ctrl->AddItem( L"Last" );
  23. ctrl->onRowSelected.Add( this, &ThisClass::RowSelected );
  24. }
  25. {
  26. Gwen::Controls::ListBox* ctrl = new Gwen::Controls::ListBox( this );
  27. ctrl->SetBounds( 120, 10, 200, 200 );
  28. ctrl->SetColumnCount( 3 );
  29. ctrl->SetAllowMultiSelect( true );
  30. ctrl->onRowSelected.Add( this, &ThisClass::RowSelected );
  31. {
  32. Gwen::Controls::Layout::TableRow* pRow = ctrl->AddItem( L"Baked Beans" );
  33. pRow->SetCellText( 1, L"Heinz" );
  34. pRow->SetCellText( 2, L"£3.50" );
  35. }
  36. {
  37. Gwen::Controls::Layout::TableRow* pRow = ctrl->AddItem( L"Bananas" );
  38. pRow->SetCellText( 1, L"Trees" );
  39. pRow->SetCellText( 2, L"£1.27" );
  40. }
  41. {
  42. Gwen::Controls::Layout::TableRow* pRow = ctrl->AddItem( L"Chicken" );
  43. pRow->SetCellText( 1, L"\u5355\u5143\u6D4B\u8BD5" );
  44. pRow->SetCellText( 2, L"£8.95" );
  45. }
  46. }
  47. }
  48. void RowSelected( Gwen::Controls::Base* pControl )
  49. {
  50. Gwen::Controls::ListBox* ctrl = (Gwen::Controls::ListBox*)pControl;
  51. UnitPrint( Utility::Format( L"Listbox Item Selected: %s", ctrl->GetSelectedRow()->GetText( 0 ).c_str() ) );
  52. }
  53. Gwen::Font m_Font;
  54. };
  55. DEFINE_UNIT_TEST( ListBox, L"ListBox" );