33#define TABEL_LABEL_TAG 1024
63 table->initWithViewSize(size,
nullptr);
65 table->setDataSource(dataSource);
66 table->_updateCellPositions();
67 table->_updateContentSize();
74 if (!this->isVisible())
83 Rect bbox = label->getBoundingBox();
84 bbox.origin = _touchedCell->convertToWorldSpace(bbox.origin);
86 if (bbox.containsPoint(touch->getLocation()) && _tableViewDelegate !=
nullptr)
88 _tableViewDelegate->tableCellUnhighlight(
this, _touchedCell);
89 _tableViewDelegate->tableCellTouched(
this, _touchedCell);
92 _touchedCell =
nullptr;
95 ScrollView::onTouchEnded(touch, event);
100 auto mouseEvent =
static_cast<EventMouse*
>(event);
101 float moveY = mouseEvent->getScrollY() * 20;
103 auto minOffset = this->minContainerOffset();
104 auto maxOffset = this->maxContainerOffset();
106 auto offset = this->getContentOffset();
109 if (offset.y < minOffset.y)
111 offset.y = minOffset.y;
113 else if (offset.y > maxOffset.y)
115 offset.y = maxOffset.y;
117 this->setContentOffset(offset);
123 auto mouseListener = EventListenerMouse::create();
125 _eventDispatcher->addEventListenerWithSceneGraphPriority(mouseListener,
this);
137 if (!testName.empty())
147 auto director = Director::getInstance();
148 auto scene = Scene::create();
150 auto visibleSize = director->getVisibleSize();
151 auto origin = director->getVisibleOrigin();
154 tableView->setPosition(origin.x + (visibleSize.width - 400) / 2, origin.y);
155 tableView->setDirection(ScrollView::Direction::VERTICAL);
156 tableView->setVerticalFillOrder(TableView::VerticalFillOrder::TOP_DOWN);
157 tableView->setDelegate(
this);
158 scene->addChild(tableView);
159 tableView->reloadData();
169 TTFConfig ttfConfig(
"fonts/arial.ttf", 20);
170 auto label = Label::createWithTTF(ttfConfig,
"Back");
173 auto menu = Menu::create(menuItem,
nullptr);
175 menu->setPosition(Vec2::ZERO);
178 scene->addChild(menu, 1);
186 Director::getInstance()->end();
190 auto autoTestLabel = Label::createWithTTF(
"Start AutoTest",
"fonts/arial.ttf",16);
191 auto autoTestItem = MenuItemLabel::create(autoTestLabel, [&](Ref* sender){
196 auto menu = Menu::create(closeItem, autoTestItem,
nullptr);
197 menu->setPosition(Vec2::ZERO);
198 scene->addChild(menu, 1);
201 director->replaceScene(scene);
208 auto index = cell->getIdx();
212 if (test->getChildTestCount() > 0)
217 test->setTestParent(
this);
230 auto cell = table->dequeueCell();
233 cell = TableViewCell::create();
234 auto label = Label::createWithTTF(
_childTestNames[idx],
"fonts/arial.ttf", 20.0f);
236 label->setPosition(200, 15);
237 cell->addChild(label);
250 return Size(400, 30);
261 if (!testName.empty() && callback)
270 auto transitionScene =
dynamic_cast<TransitionScene*
>(scene);
274 testCase =
dynamic_cast<TestCase*
>(transitionScene->getInScene());
278 testCase =
dynamic_cast<TestCase*
>(scene);
293 testCase->setTestSuite(
this);
295 Director::getInstance()->replaceScene(scene);
303 testCase->setTestSuite(
this);
306 Director::getInstance()->replaceScene(scene);
315 testCase->setTestSuite(
this);
318 Director::getInstance()->replaceScene(scene);
334 testCase->setTestSuite(
this);
337 Director::getInstance()->replaceScene(scene);
342: _priorTestItem(nullptr)
343, _restartTestItem(nullptr)
344, _nextTestItem(nullptr)
345, _titleLabel(nullptr)
346, _subtitleLabel(nullptr)
350 Director::getInstance()->getTextureCache()->removeUnusedTextures();
351 SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
353 this->schedule([&](
float dt){
355 },
"AccumulatedTimeUse");
395 TTFConfig ttfConfig(
"fonts/arial.ttf", 26);
400 ttfConfig.fontSize = 16;
410 ttfConfig.fontSize = 20;
411 auto backLabel = Label::createWithTTF(ttfConfig,
"Back");
416 menu->setPosition(Vec2::ZERO);
422 addChild(menu, 9999);
static TestCase * getTestCase(Scene *scene)
ssize_t getChildTestCount()
virtual void runThisTest()
std::vector< std::string > _childTestNames
virtual std::string title() const
cocos2d::MenuItemImage * _restartTestItem
cocos2d::MenuItemImage * _priorTestItem
cocos2d::MenuItemImage * _nextTestItem
virtual Type getTestType() const
virtual std::string subtitle() const
virtual void onEnter() override
virtual float getDuration() const
virtual void restartTestCallback(cocos2d::Ref *sender)
cocos2d::Label * _subtitleLabel
void setTestSuite(TestSuite *testSuite)
virtual void onBackCallback(cocos2d::Ref *sender)
virtual void priorTestCallback(cocos2d::Ref *sender)
cocos2d::Label * _titleLabel
virtual void nextTestCallback(cocos2d::Ref *sender)
static void destroyInstance()
static TestController * getInstance()
void setCurrTestSuite(TestSuite *testSuite)
void onMouseScroll(Event *event)
virtual void onTouchEnded(Touch *touch, Event *event) override
static TestCustomTableView * create(TableViewDataSource *dataSource, Size size)
virtual void runThisTest() override
std::vector< std::function< TestBase *()> > _testCallbacks
virtual cocos2d::extension::TableViewCell * tableCellAtIndex(cocos2d::extension::TableView *table, ssize_t idx) override
cocos2d::Vec2 _tableOffset
virtual cocos2d::Size tableCellSizeForIndex(cocos2d::extension::TableView *table, ssize_t idx) override
virtual void tableCellTouched(cocos2d::extension::TableView *table, cocos2d::extension::TableViewCell *cell) override
virtual ssize_t numberOfCellsInTableView(cocos2d::extension::TableView *table) override
bool _shouldRestoreTableOffset
void addTest(const std::string &testName, std::function< TestBase *()> callback)
std::vector< std::function< cocos2d::Scene *()> > _testCallbacks
void addTestCase(const std::string &testName, std::function< cocos2d::Scene *()> callback)
virtual void runThisTest() override
virtual void restartCurrTest()
virtual void enterNextTest()
virtual void enterPreviousTest()
static cocos2d::Vec2 top()
static cocos2d::Rect getVisibleRect()
static cocos2d::Vec2 center()
static cocos2d::Vec2 bottom()
static cocos2d::Vec2 left()
static cocos2d::Vec2 right()
static const char s_pathClose[]
static const char s_pathB2[]
static const char s_pathB1[]
static const char s_pathF1[]
static const char s_pathR1[]
static const char s_pathR2[]
static const char s_pathF2[]