PuzzleSDK
UIScrollViewStopScrollingTest类 参考

#include <UIScrollViewTest.h>

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

Public 成员函数

 CREATE_FUNC (UIScrollViewStopScrollingTest)
 
 UIScrollViewStopScrollingTest ()
 
virtual bool init () override
 
virtual void update (float dt) override
 
- 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
 

Protected 属性

cocos2d::ui::Text * _displayValueLabel
 
cocos2d::ui::ScrollView * _scrollView
 
float _remainingTime
 
- 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 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 

详细描述

在文件 UIScrollViewTest.h172 行定义.

构造及析构函数说明

◆ UIScrollViewStopScrollingTest()

UIScrollViewStopScrollingTest::UIScrollViewStopScrollingTest ( )

在文件 UIScrollViewTest.cpp794 行定义.

795 : _displayValueLabel(nullptr)
796 , _scrollView(nullptr)
797 , _remainingTime(0.0f)
798{
799
800}
cocos2d::ui::ScrollView * _scrollView
cocos2d::ui::Text * _displayValueLabel

成员函数说明

◆ CREATE_FUNC()

UIScrollViewStopScrollingTest::CREATE_FUNC ( UIScrollViewStopScrollingTest  )

◆ init()

bool UIScrollViewStopScrollingTest::init ( )
overridevirtual

重载 UIScene .

在文件 UIScrollViewTest.cpp802 行定义.

803{
804 if (UIScene::init())
805 {
806 Size widgetSize = _widget->getContentSize();
807
808 // Add a label in which the time remaining till scrolling stop will be displayed.
809 _displayValueLabel = Text::create("Scrolling stop isn't scheduled", "fonts/Marker Felt.ttf", 32);
810 _displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
811 _displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + _displayValueLabel->getContentSize().height * 1.5f));
812 _uiLayer->addChild(_displayValueLabel);
813
814 // Add the alert
815 Text* alert = Text::create("Click the button and start to scroll", "fonts/Marker Felt.ttf", 30);
816 alert->setColor(Color3B(159, 168, 176));
817 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
818 _uiLayer->addChild(alert);
819
820 Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
821
822 Layout* background = static_cast<Layout*>(root->getChildByName("background_Panel"));
823
824 // Create the dragpanel
825 _scrollView = ui::ScrollView::create();
826 _scrollView->setDirection(ui::ScrollView::Direction::BOTH);
827 _scrollView->setTouchEnabled(true);
828 _scrollView->setBounceEnabled(true);
829 _scrollView->setBackGroundImageScale9Enabled(true);
830 _scrollView->setBackGroundImage("cocosui/green_edit.png");
831 _scrollView->setContentSize(Size(210, 122.5));
832 _scrollView->setScrollBarWidth(4);
833 _scrollView->setScrollBarPositionFromCorner(Vec2(6, 6));
834 Size backgroundSize = background->getContentSize();
835 _scrollView->setPosition(Vec2((widgetSize.width - backgroundSize.width) / 2.0f +
836 (backgroundSize.width - _scrollView->getContentSize().width) / 2.0f,
837 (widgetSize.height - backgroundSize.height) / 2.0f +
838 (backgroundSize.height - _scrollView->getContentSize().height) / 2.0f));
839 ImageView* imageView = ImageView::create("Hello.png");
840 _scrollView->addChild(imageView);
841 _scrollView->setInnerContainerSize(imageView->getContentSize());
842 Size innerSize = _scrollView->getInnerContainerSize();
843 imageView->setPosition(Vec2(innerSize.width / 2.0f, innerSize.height / 2.0f));
844 _uiLayer->addChild(_scrollView);
845
846 // Log some ScrollView events.
847 _scrollView->addEventListener([&] (Ref*, ui::ScrollView::EventType e)
848 {
849 switch (e)
850 {
851 case ui::ScrollView::EventType::SCROLLING_BEGAN:
852 CCLOG("scrolling began!");
853 break;
854 case ui::ScrollView::EventType::SCROLLING_ENDED:
855 CCLOG("scrolling ended!");
856 break;
857 case ui::ScrollView::EventType::AUTOSCROLL_ENDED:
858 CCLOG("auto-scrolling ended!");
859 break;
860 default: break;
861 }
862 });
863
864 // Jump to right bottom
865 _scrollView->jumpToBottomRight();
866
867 // Add button that will schedule scrolling stop when it is clicked.
868 Button* button_scale9 = Button::create("cocosui/button.png", "cocosui/buttonHighlighted.png");
869 button_scale9->setTitleText("Stop scrolling in 3 sec.");
870 button_scale9->setScale9Enabled(true);
871 button_scale9->setContentSize(Size(120.0f, button_scale9->getVirtualRendererSize().height));
872 button_scale9->setPosition(Vec2(innerSize.width / 2.0f, innerSize.height / 2.0f));
873 button_scale9->addClickEventListener([this] (Ref*) { this->_remainingTime = 3.0f; });
874 _scrollView->addChild(button_scale9);
875
876 // Schedule update for this scene.
877 Director::getInstance()->getScheduler()->scheduleUpdate(this, 0, false);
878
879 return true;
880 }
881
882 return false;
883}
cocos2d::Layer * _uiLayer
Definition: UIScene.h:44
virtual bool init() override
Definition: UIScene.cpp:46
cocos2d::ui::Layout * _widget
Definition: UIScene.h:45

引用了 _displayValueLabel, _remainingTime, _scrollView, UIScene::_uiLayer, UIScene::_widget , 以及 UIScene::init().

+ 函数调用图:

◆ update()

void UIScrollViewStopScrollingTest::update ( float  dt)
overridevirtual

在文件 UIScrollViewTest.cpp885 行定义.

886{
887 UIScene::update(dt);
888
889 if (_remainingTime > 0.0f)
890 {
891 _remainingTime -= dt;
892
893 if (_remainingTime > 0.0f)
894 {
895 // Update timer caption.
896 char strRemainingTime[100];
897 sprintf(strRemainingTime, "Stop scrolling in %.1f sec.", _remainingTime);
898 _displayValueLabel->setString(std::string(strRemainingTime));
899 }
900 else
901 {
902 _scrollView->stopOverallScroll();
903
904 // Update timer caption.
905 std::string strRemainingTime = "Scrolling stop isn't scheduled";
906 _displayValueLabel->setString(strRemainingTime);
907
908 // Show hint label.
909 auto hintLabel = Label::createWithTTF("Stopped!", "fonts/Marker Felt.ttf", 32.0f);
910 Size contentSize = _uiLayer->getContentSize();
911 hintLabel->setPosition(Vec2(contentSize.width / 2.0f, contentSize.height / 2.0f));
912 hintLabel->runAction(Spawn::createWithTwoActions(
913 FadeOut::create(0.3f),
914 ScaleTo::create(0.3f, 2.0f)
915 ));
916 _uiLayer->addChild(hintLabel);
917 }
918 }
919}

引用了 _displayValueLabel, _remainingTime, _scrollView , 以及 UIScene::_uiLayer.

类成员变量说明

◆ _displayValueLabel

cocos2d::ui::Text* UIScrollViewStopScrollingTest::_displayValueLabel
protected

在文件 UIScrollViewTest.h184 行定义.

被这些函数引用 init() , 以及 update().

◆ _remainingTime

float UIScrollViewStopScrollingTest::_remainingTime
protected

在文件 UIScrollViewTest.h186 行定义.

被这些函数引用 init() , 以及 update().

◆ _scrollView

cocos2d::ui::ScrollView* UIScrollViewStopScrollingTest::_scrollView
protected

在文件 UIScrollViewTest.h185 行定义.

被这些函数引用 init() , 以及 update().


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