PuzzleSDK
UIRichTextTest类 参考

#include <UIRichTextTest.h>

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

Public 成员函数

 CREATE_FUNC (UIRichTextTest)
 
bool init () override
 
void touchEvent (cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
 
void switchWrapMode (cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
 
void switchAlignment (cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
 
- 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::RichText * _richText
 
- 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
 

详细描述

在文件 UIRichTextTest.h34 行定义.

成员函数说明

◆ CREATE_FUNC()

UIRichTextTest::CREATE_FUNC ( UIRichTextTest  )

◆ init()

bool UIRichTextTest::init ( )
overridevirtual

重载 UIScene .

在文件 UIRichTextTest.cpp58 行定义.

59{
60 if (UIScene::init())
61 {
62 Size widgetSize = _widget->getContentSize();
63
64 auto config = Configuration::getInstance();
65 config->loadConfigFile("configs/config-test-ok.plist");
66
67
68 std::string str1 = config->getValue("Chinese").asString();
69 std::string str2 = config->getValue("Japanese").asString();
70 CCLOG("str1:%s ascii length = %ld, utf8 length = %ld, substr = %s",
71 str1.c_str(),
72 static_cast<long>(str1.length()),
73 StringUtils::getCharacterCountInUTF8String(str1),
74 Helper::getSubStringOfUTF8String(str1, 0, 5).c_str());
75 CCLOG("str2:%s ascii length = %ld, utf8 length = %ld, substr = %s",
76 str2.c_str(),
77 static_cast<long>(str2.length()),
78 StringUtils::getCharacterCountInUTF8String(str2),
79 Helper::getSubStringOfUTF8String(str2, 0, 2).c_str());
80
81 // Add the alert
82 Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
83 alert->setColor(Color3B(159, 168, 176));
84 alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125));
85 _widget->addChild(alert);
86
87 Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
88 button->setTouchEnabled(true);
89 button->setTitleText("switch");
90 button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5));
91 button->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::touchEvent, this));
92 button->setLocalZOrder(10);
93 _widget->addChild(button);
94
95 Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
96 button2->setTouchEnabled(true);
97 button2->setTitleText("wrap mode");
98 button2->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
99 button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::switchWrapMode, this));
100 button2->setLocalZOrder(10);
101 _widget->addChild(button2);
102
103 Button* button3 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png");
104 button3->setTouchEnabled(true);
105 button3->setTitleText("alignment");
106 button3->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5));
107 button3->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::switchAlignment, this));
108 button3->setLocalZOrder(10);
109 _widget->addChild(button3);
110
111 // RichText
112 _richText = RichText::create();
113 _richText->ignoreContentAdaptWithSize(false);
114 _richText->setContentSize(Size(100, 100));
115
116 RichElementText* re1 = RichElementText::create(1, Color3B::WHITE, 255, str1, "SimSun", 10);
117 RichElementText* re2 = RichElementText::create(2, Color3B::YELLOW, 255, "And this is yellow. ", "Helvetica", 10);
118 RichElementText* re3 = RichElementText::create(3, Color3B::GRAY, 255, str2, "Yu Mincho", 10);
119 RichElementText* re4 = RichElementText::create(4, Color3B::GREEN, 255, "And green with TTF support. ", "fonts/Marker Felt.ttf", 10);
120 RichElementText* re5 = RichElementText::create(5, Color3B::RED, 255, "Last one is red ", "Helvetica", 10);
121
122 RichElementImage* reimg = RichElementImage::create(6, Color3B::WHITE, 255, "cocosui/sliderballnormal.png");
123
124// TODO
125// cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("cocosui/100/100.ExportJson");
126// cocostudio::Armature *pAr = cocostudio::Armature::create("100"); //
127// pAr->getAnimation()->play("Animation1");
128
129// RichElementCustomNode* recustom = RichElementCustomNode::create(1, Color3B::WHITE, 255, pAr);
130 RichElementText* re6 = RichElementText::create(7, Color3B::ORANGE, 255, "Have fun!! ", "Helvetica", 10);
131 _richText->pushBackElement(re1);
132 _richText->insertElement(re2, 1);
133 _richText->pushBackElement(re3);
134 _richText->pushBackElement(re4);
135 _richText->pushBackElement(re5);
136 _richText->insertElement(reimg, 2);
137// _richText->pushBackElement(recustom);
138 _richText->pushBackElement(re6);
139
140 _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2));
141 _richText->setLocalZOrder(10);
142
143
144 _widget->addChild(_richText);
145
146 // test remove all children, this call won't effect the test
147 _richText->removeAllChildren();
148
149 return true;
150 }
151 return false;
152}
cocos2d::ui::RichText * _richText
void switchWrapMode(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void touchEvent(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
void switchAlignment(cocos2d::Ref *sender, cocos2d::ui::Widget::TouchEventType type)
virtual bool init() override
Definition: UIScene.cpp:46
cocos2d::ui::Layout * _widget
Definition: UIScene.h:45

引用了 _richText, UIScene::_widget, UIScene::init(), switchAlignment(), switchWrapMode() , 以及 touchEvent().

+ 函数调用图:

◆ switchAlignment()

void UIRichTextTest::switchAlignment ( cocos2d::Ref *  sender,
cocos2d::ui::Widget::TouchEventType  type 
)

在文件 UIRichTextTest.cpp187 行定义.

187 {
188 if (type == Widget::TouchEventType::ENDED)
189 {
190 auto alignment = _richText->getHorizontalAlignment();
191 alignment = static_cast<RichText::HorizontalAlignment>((static_cast<std::underlying_type<RichText::HorizontalAlignment>::type>(alignment) + 1) % 3);
192 _richText->setHorizontalAlignment(alignment);
193 }
194}

引用了 _richText.

被这些函数引用 init().

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

◆ switchWrapMode()

void UIRichTextTest::switchWrapMode ( cocos2d::Ref *  sender,
cocos2d::ui::Widget::TouchEventType  type 
)

在文件 UIRichTextTest.cpp177 行定义.

178{
179 if (type == Widget::TouchEventType::ENDED)
180 {
181 auto wrapMode = _richText->getWrapMode();
182 wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD;
183 _richText->setWrapMode(wrapMode);
184 }
185}

引用了 _richText.

被这些函数引用 init().

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

◆ touchEvent()

void UIRichTextTest::touchEvent ( cocos2d::Ref *  sender,
cocos2d::ui::Widget::TouchEventType  type 
)

在文件 UIRichTextTest.cpp154 行定义.

155{
156 switch (type)
157 {
158 case Widget::TouchEventType::ENDED:
159 {
160 if (_richText->isIgnoreContentAdaptWithSize())
161 {
162 _richText->ignoreContentAdaptWithSize(false);
163 _richText->setContentSize(Size(100, 100));
164 }
165 else
166 {
167 _richText->ignoreContentAdaptWithSize(true);
168 }
169 }
170 break;
171
172 default:
173 break;
174 }
175}

引用了 _richText.

被这些函数引用 init().

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

类成员变量说明

◆ _richText

cocos2d::ui::RichText* UIRichTextTest::_richText
protected

在文件 UIRichTextTest.h45 行定义.

被这些函数引用 init(), switchAlignment(), switchWrapMode() , 以及 touchEvent().


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