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