PuzzleSDK
UIListViewTest_ScrollToItem类 参考abstract

#include <UIListViewTest.h>

+ 类 UIListViewTest_ScrollToItem 继承关系图:
+ UIListViewTest_ScrollToItem 的协作图:

Protected 成员函数

virtual bool init () override
 
virtual cocos2d::ui::ScrollView::Direction getListViewDirection () const =0
 

Protected 属性

cocos2d::ui::ListView * _listView
 
cocos2d::ui::Text * _titleLabel
 
int _nextIndex
 
- Protected 属性 继承自 UIScene
cocos2d::Layer * _uiLayer
 
cocos2d::ui::Layout * _widget
 
cocos2d::ui::Text * _sceneTitle
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 成员函数 继承自 UIScene
 UIScene ()
 
 ~UIScene ()
 
virtual void onEnter () override
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual std::string title () const
 
virtual std::string subtitle () const
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 

详细描述

在文件 UIListViewTest.h124 行定义.

成员函数说明

◆ getListViewDirection()

virtual cocos2d::ui::ScrollView::Direction UIListViewTest_ScrollToItem::getListViewDirection ( ) const
protectedpure virtual

UIListViewTest_ScrollToItemVertical , 以及 UIListViewTest_ScrollToItemHorizontal 内被实现.

被这些函数引用 init().

+ 这是这个函数的调用关系图:

◆ init()

bool UIListViewTest_ScrollToItem::init ( )
overrideprotectedvirtual

重载 UIScene .

在文件 UIListViewTest.cpp652 行定义.

653{
654 if(!UIScene::init())
655 {
656 return false;
657 }
658
659 Size layerSize = _uiLayer->getContentSize();
660
661 static int NUMBER_OF_ITEMS = 31;
662 _nextIndex = 0;
663 _titleLabel = Text::create("Scroll to item", "fonts/Marker Felt.ttf", 32);
664 _titleLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
665 _titleLabel->setPosition(Vec2(layerSize / 2) + Vec2(0.0f, _titleLabel->getContentSize().height * 3.15f));
666 _uiLayer->addChild(_titleLabel, 3);
667
668 // Create the list view
669 _listView = ListView::create();
670 _listView->setDirection(getListViewDirection());
671 _listView->setBounceEnabled(true);
672 _listView->setBackGroundImage("cocosui/green_edit.png");
673 _listView->setBackGroundImageScale9Enabled(true);
674 _listView->setContentSize(layerSize / 2);
675 _listView->setScrollBarPositionFromCorner(Vec2(7, 7));
676 _listView->setItemsMargin(2.0f);
677 _listView->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
678 _listView->setPosition(layerSize / 2);
679 _uiLayer->addChild(_listView);
680
681 // Guide line for center align
682 {
683 DrawNode* pNode = DrawNode::create();
684 Vec2 center = layerSize / 2;
685 if(getListViewDirection() == ScrollView::Direction::HORIZONTAL)
686 {
687 float halfY = 110;
688 pNode->drawLine(Vec2(center.x, center.y - halfY), Vec2(center.x, center.y + halfY), Color4F(0, 0, 0, 1));
689 }
690 else
691 {
692 float halfX = 150;
693 pNode->drawLine(Vec2(center.x - halfX, center.y), Vec2(center.x + halfX, center.y), Color4F(0, 0, 0, 1));
694 }
695 pNode->setLineWidth(2);
696 _uiLayer->addChild(pNode);
697 }
698
699 // Button
700 auto pButton = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png");
701 pButton->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
702 pButton->setScale(0.8f);
703 pButton->setPosition(Vec2(layerSize / 2) + Vec2(120.0f, -60.0f));
704 pButton->setTitleText(StringUtils::format("Go to '%d'", _nextIndex));
705 pButton->addClickEventListener([this, pButton](Ref*) {
706 _listView->scrollToItem(_nextIndex, Vec2::ANCHOR_MIDDLE, Vec2::ANCHOR_MIDDLE);
707 _nextIndex = (_nextIndex + (NUMBER_OF_ITEMS / 2)) % NUMBER_OF_ITEMS;
708 pButton->setTitleText(StringUtils::format("Go to '%d'", _nextIndex));
709 });
710 _uiLayer->addChild(pButton);
711
712 // Add list items
713 static const Size BUTTON_SIZE(50, 40);
714 for (int i = 0; i < NUMBER_OF_ITEMS; ++i)
715 {
716 auto pButton = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
717 pButton->setContentSize(BUTTON_SIZE);
718 pButton->setScale9Enabled(true);
719 pButton->setTitleText(StringUtils::format("Button-%d", i));
720 _listView->pushBackCustomItem(pButton);
721 }
722 return true;
723}
virtual cocos2d::ui::ScrollView::Direction getListViewDirection() const =0
cocos2d::ui::Text * _titleLabel
cocos2d::ui::ListView * _listView
cocos2d::Layer * _uiLayer
Definition: UIScene.h:44
virtual bool init() override
Definition: UIScene.cpp:46

引用了 _listView, _nextIndex, _titleLabel, UIScene::_uiLayer, getListViewDirection() , 以及 UIScene::init().

+ 函数调用图:

类成员变量说明

◆ _listView

cocos2d::ui::ListView* UIListViewTest_ScrollToItem::_listView
protected

在文件 UIListViewTest.h130 行定义.

被这些函数引用 init().

◆ _nextIndex

int UIListViewTest_ScrollToItem::_nextIndex
protected

在文件 UIListViewTest.h132 行定义.

被这些函数引用 init().

◆ _titleLabel

cocos2d::ui::Text* UIListViewTest_ScrollToItem::_titleLabel
protected

在文件 UIListViewTest.h131 行定义.

被这些函数引用 init().


该类的文档由以下文件生成: