26#include "../testResource.h"
27#include "renderer/CCRenderer.h"
28#include "2d/CCFontAtlasCache.h"
32using namespace extension;
60NewLabelTests::NewLabelTests()
150 auto col = LayerColor::create( Color4B(128,128,128,255) );
153 auto label1 = Label::createWithBMFont(
"fonts/bitmapFontTest2.fnt",
"Test");
155 label1->setAnchorPoint( Vec2(0,0) );
157 auto fade = FadeOut::create(1.0f);
158 auto fade_in = fade->reverse();
159 auto seq = Sequence::create(fade, fade_in,
nullptr);
160 auto repeat = RepeatForever::create(seq);
161 label1->runAction(repeat);
163 auto label2 = Label::createWithBMFont(
"fonts/bitmapFontTest2.fnt",
"Test");
164 label2->setColor( Color3B::RED );
166 auto tint = Sequence::create(TintTo::create(1, 255, 0, 0),
167 TintTo::create(1, 0, 255, 0),
168 TintTo::create(1, 0, 0, 255),
170 label2->runAction( RepeatForever::create(tint) );
172 auto label3 = Label::createWithBMFont(
"fonts/bitmapFontTest2.fnt",
"Test");
173 label3->setAnchorPoint( Vec2(1,1) );
186 char string[15] = {0};
187 sprintf(
string,
"%2.2f Test j",
_time);
190 label1->setString(
string);
193 label2->setString(
string);
196 label3->setString(
string);
201 return "New Label + Bitmap font";
206 return "Testing fade/tint action";
213 auto s = Director::getInstance()->getWinSize();
215 auto drawNode = DrawNode::create();
216 drawNode->drawLine( Vec2(0.0f, s.height/2), Vec2(s.width, s.height/2), Color4F(1.0f, 1.0f, 1.0f, 1.0f) );
217 drawNode->drawLine( Vec2(s.width/2, 0.0f), Vec2(s.width/2, s.height), Color4F(1.0f, 1.0f, 1.0f, 1.0f) );
218 addChild(drawNode, -1);
221 auto label = Label::createWithBMFont(
"fonts/bitmapFontTest.fnt",
"Bitmap Font Atlas");
225 label->setPosition( Vec2(s.width/2, s.height/2) );
227 auto BChar = (Sprite*) label->getLetter(0);
228 auto FChar = (Sprite*) label->getLetter(7);
229 auto AChar = (Sprite*) label->getLetter(12);
232 auto rotate = RotateBy::create(2, 360);
233 auto rot_4ever = RepeatForever::create(rotate);
235 auto scale = ScaleBy::create(2, 1.5f);
236 auto scale_back = scale->reverse();
237 auto scale_seq = Sequence::create(scale, scale_back,
nullptr);
238 auto scale_4ever = RepeatForever::create(scale_seq);
240 auto jump = JumpBy::create(0.5f, Vec2::ZERO, 60, 1);
241 auto jump_4ever = RepeatForever::create(jump);
243 auto fade_out = FadeOut::create(1);
244 auto fade_in = FadeIn::create(1);
245 auto seq = Sequence::create(fade_out, fade_in,
nullptr);
246 auto fade_4ever = RepeatForever::create(seq);
248 BChar->runAction(rot_4ever);
249 BChar->runAction(scale_4ever);
250 FChar->runAction(jump_4ever);
251 AChar->runAction(fade_4ever);
255 auto label2 = Label::createWithBMFont(
"fonts/bitmapFontTest.fnt",
"00.0");
257 label2->setPosition( Vec2(s.width/2.0f, 80.0f) );
259 auto lastChar = (Sprite*) label2->getLetter(3);
260 lastChar->runAction( rot_4ever->clone() );
268 char string[10] = {0};
269 sprintf(
string,
"%04.1f",
_time);
271 label1->setString(
string);
276 return "New Label + Bitmap font";
281 return "Testing run action on the specified character";
286 auto label = Label::createWithBMFont(
"fonts/bitmapFontTest4.fnt",
"abcdefg");
289 auto s = Director::getInstance()->getWinSize();
291 label->setPosition( Vec2(s.width/2, s.height/2) );
296 return "New Label + Bitmap font";
301 return "Testing padding";
306 auto s = Director::getInstance()->getWinSize();
308 Label* label =
nullptr;
309 label = Label::createWithBMFont(
"fonts/bitmapFontTest5.fnt",
"FaFeFiFoFu");
311 label->setPosition( Vec2(s.width/2, s.height/2+50) );
313 label = Label::createWithBMFont(
"fonts/bitmapFontTest5.fnt",
"fafefifofu");
315 label->setPosition( Vec2(s.width/2, s.height/2) );
317 label = Label::createWithBMFont(
"fonts/bitmapFontTest5.fnt",
"aeiou");
319 label->setPosition( Vec2(s.width/2, s.height/2-50) );
324 return "New Label + Bitmap font";
329 return "Rendering should be OK. Testing offset";
334 auto winSize = Director::getInstance()->getWinSize();
336 auto label = Label::createWithBMFont(
"fonts/bitmapFontTest5.fnt",
"Blue");
337 label->setColor( Color3B::BLUE );
339 label->setPosition(winSize.width / 2, winSize.height * 0.7f);
341 label = Label::createWithBMFont(
"fonts/bitmapFontTest5.fnt",
"Red");
343 label->setPosition(winSize.width / 2, winSize.height * 0.5f);
344 label->setColor( Color3B::RED );
346 label = Label::createWithBMFont(
"fonts/bitmapFontTest5.fnt",
"Green");
348 label->setPosition(winSize.width / 2, winSize.height * 0.3f);
349 label->setColor( Color3B::GREEN );
350 label->setString(
"Green");
355 return "New Label + Bitmap font";
360 return "Testing color";
365 auto winSize = Director::getInstance()->getWinSize();
367 auto label = Label::createWithBMFont(
"fonts/bitmapFontTest5.fnt",
"Opacity 100");
368 label->setOpacity(100);
370 label->setPosition(winSize.width / 2, winSize.height * 0.6f);
372 label = Label::createWithBMFont(
"fonts/bitmapFontTest5.fnt",
"Opacity 200");
373 label->setOpacity(200);
375 label->setPosition(winSize.width / 2, winSize.height * 0.4f);
380 return "New Label + Bitmap font";
385 return "Testing opacity";
391 for (
int i=0 ; i < 100;i ++ )
394 sprintf(str,
"-%d-", i);
395 auto label = Label::createWithBMFont(
"fonts/bitmapFontTest.fnt", str);
398 auto s = Director::getInstance()->getWinSize();
400 auto p = Vec2( CCRANDOM_0_1() * s.width, CCRANDOM_0_1() * s.height);
401 label->setPosition( p );
407 return "New Label + Bitmap font";
412 return "Creating several Labels using the same FNT file; should be fast";
420 auto label1 = Label::createWithBMFont(
"fonts/bitmapFontTest3.fnt",
" Multi line\nLeft");
421 label1->setAnchorPoint(Vec2(0,0));
424 s = label1->getContentSize();
425 CCLOG(
"content size: %.2fx%.2f", s.width, s.height);
429 auto label2 = Label::createWithBMFont(
"fonts/bitmapFontTest3.fnt",
"Multi line\nCenter");
432 s= label2->getContentSize();
433 CCLOG(
"content size: %.2fx%.2f", s.width, s.height);
436 auto label3 = Label::createWithBMFont(
"fonts/bitmapFontTest3.fnt",
"Multi line\nRight\nThree lines Three");
437 label3->setAnchorPoint(Vec2(1, 1));
440 s = label3->getContentSize();
441 CCLOG(
"content size: %.2fx%.2f", s.width, s.height);
450 return "New Label + Bitmap font";
455 return "Multiline + anchor point";
460 auto s = Director::getInstance()->getWinSize();
463 auto label1 = Label::createWithBMFont(
"fonts/bitmapFontTest3.fnt",
"", TextHAlignment::CENTER, s.width);
465 label1->setPosition(Vec2(s.width/2, s.height - 100));
468 TTFConfig ttfConfig(
"fonts/arial.ttf",24);
469 auto label2 = Label::createWithTTF(ttfConfig,
"", TextHAlignment::CENTER,s.width);
471 label2->setPosition(Vec2(s.width/2, s.height / 2));
473 auto label3 = Label::createWithCharMap(
"fonts/tuffy_bold_italic-charmap.plist");
475 label3->setPosition(Vec2(s.width/2, 100.0f));
490 label1->setString(
"not empty");
491 label2->setString(
"not empty");
492 label3->setString(
"hi");
498 label1->setString(
"");
499 label2->setString(
"");
500 label3->setString(
"");
508 return "New Label + FNT/TTF/CharMap";
513 return "Testing empty string.";
518 auto s = Director::getInstance()->getWinSize();
521 auto label1 = Label::createWithBMFont(
"fonts/konqa32.fnt",
"TESTING RETINA DISPLAY");
523 label1->setPosition(Vec2(s.width/2, s.height/2));
528 return "New Label + Bitmap font";
533 return "loading arista16 or arista16-hd";
538 auto winSize = Director::getInstance()->getWinSize();
540 auto layer = LayerColor::create(Color4B(128,128,128,255));
541 addChild(layer, -10);
543 auto label1 = Label::createWithBMFont(
"fonts/futura-48.fnt",
"Testing Glyph Designer");
546 FontAtlasCache::reloadFontAtlasFNT(
"fonts/futura-48.fnt");
547 label1->setBMFontFilePath(
"fonts/futura-48.fnt");
549 label1->setPosition(Vec2(winSize.width / 2, winSize.height * 0.4f));
551 auto label2 = Label::createWithBMFont(
"fonts/bitmapFontTest2.fnt",
"Hello World");
552 label2->setPosition(Vec2(winSize.width / 2, winSize.height * 0.6f));
558 return "New Label + Bitmap font";
563 return "Testing Glyph Designer";
568#define LongSentencesExample "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
569#define LineBreaksExample "Lorem ipsum dolor\nsit amet\nconsectetur adipisicing elit\nblah\nblah"
570#define MixedExample "ABC\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt\nDEF"
572#define ArrowsMax 0.95
579#define LongSentences 0
588 if (!AtlasDemoNew::init())
593 auto listener = EventListenerTouchAllAtOnce::create();
598 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener,
this);
600 auto size = Director::getInstance()->getWinSize();
603 this->
_label = Label::createWithBMFont(
"fonts/markerFelt.fnt",
"", TextHAlignment::CENTER, size.width/1.5);
605 this->
_arrowsBar = Sprite::create(
"Images/arrowsBar.png");
606 this->
_arrows = Sprite::create(
"Images/arrows.png");
608 MenuItemFont::setFontSize(20);
612 auto stringMenu = Menu::create(longSentences, lineBreaks, mixed,
nullptr);
613 stringMenu->alignItemsVertically();
617 mixed->setTag(
Mixed);
623 MenuItemFont::setFontSize(30);
629 auto alignmentMenu = Menu::create(left, center, right,
nullptr);
637 this->
_label->setPosition(Vec2(size.width/2, size.height/2));
642 this->_arrowsBar->setScaleX(arrowsWidth / this->_arrowsBar->getContentSize().width);
652 this->addChild(this->
_label);
655 this->addChild(stringMenu);
656 this->addChild(alignmentMenu);
679 item->setColor(Color3B::RED);
681 switch (item->getTag())
684 this->
_label->setAlignment(TextHAlignment::LEFT);
687 this->
_label->setAlignment(TextHAlignment::CENTER);
690 this->
_label->setAlignment(TextHAlignment::RIGHT);
706 item->setColor(Color3B::RED);
709 this->
_label->setString(str);
716 switch (item->getTag())
737 auto item = (MenuItemFont*)sender;
746 auto item =
static_cast<MenuItemFont*
>(sender);
755 auto touch = touches[0];
756 auto location = touch->getLocationInView();
758 if (this->
_arrows->getBoundingBox().containsPoint(location))
780 auto touch = touches[0];
781 auto location = touch->getLocationInView();
783 auto winSize = Director::getInstance()->getWinSize();
786 this->_arrows->getPosition().y));
788 float labelWidth = fabs(this->
_arrows->getPosition().x - this->_label->getPosition().x) * 2;
790 this->
_label->setMaxLineWidth(labelWidth);
795 this->
_arrows->setPosition(Vec2(this->
_label->getPosition().x + this->_label->getContentSize().width/2,
796 this->_label->getPosition().y));
812 auto ttfConfig = this->
_label->getTTFConfig();
813 ttfConfig.fontSize = 20;
814 ttfConfig.fontFilePath =
"fonts/tahoma.ttf";
815 this->
_label->setTTFConfig(ttfConfig);
837 auto strings = FileUtils::getInstance()->getValueMapFromFile(
"strings/LabelFNTMultiLineAlignmentUNICODE.xml");
839 switch (item->getTag())
842 str = strings[
"french"].asString();
845 str = strings[
"spanish"].asString();
848 str = strings[
"ukrainian"].asString();
861 auto strings = FileUtils::getInstance()->getValueMapFromFile(
"strings/LabelFNTUNICODELanguages.xml");
862 std::string chinese = strings[
"chinese1"].asString();
863 std::string russian = strings[
"russian"].asString();
864 std::string spanish = strings[
"spanish"].asString();
865 std::string japanese = strings[
"japanese"].asString();
867 auto s = Director::getInstance()->getWinSize();
869 auto label1 = Label::createWithBMFont(
"fonts/arial-unicode-26.fnt", spanish, TextHAlignment::CENTER, 200);
871 label1->setPosition(Vec2(s.width/2, s.height/5*3));
873 auto label2 = Label::createWithBMFont(
"fonts/arial-unicode-26.fnt", chinese);
875 label2->setPosition(Vec2(s.width/2, s.height/5*2.5));
877 auto label3 = Label::createWithBMFont(
"fonts/arial-26-en-ru.fnt", russian);
879 label3->setPosition(Vec2(s.width/2, s.height/5*2));
881 auto label4 = Label::createWithBMFont(
"fonts/arial-unicode-26.fnt", japanese);
883 label4->setPosition(Vec2(s.width/2, s.height/5*1.5));
888 return "New Label + Bitmap font";
893 return "Testing Unicode.You should see 4 different labels:In Spanish, Chinese, Russian and Japanese";
898 auto s = Director::getInstance()->getWinSize();
900 auto layer = LayerColor::create(Color4B(128,128,128,255));
901 addChild(layer, -10);
904 auto label1 = Label::createWithBMFont(
"fonts/boundsTestFont.fnt",
"Testing Glyph Designer", TextHAlignment::CENTER,s.width);
906 label1->setPosition(Vec2(s.width/2, s.height/2));
908 auto drawNode = DrawNode::create();
909 auto labelSize = label1->getContentSize();
910 auto origin = Director::getInstance()->getWinSize();
912 origin.width = origin.width / 2 - (labelSize.width / 2);
913 origin.height = origin.height / 2 - (labelSize.height / 2);
917 Vec2(origin.width, origin.height),
918 Vec2(labelSize.width + origin.width, origin.height),
919 Vec2(labelSize.width + origin.width, labelSize.height + origin.height),
920 Vec2(origin.width, labelSize.height + origin.height)
922 drawNode->drawPoly(vertices, 4,
true, Color4F(1.0f, 1.0f, 1.0f, 1.0f));
928 return "New Label + Bitmap font";
933 return "Testing bounding-box";
938 auto size = Director::getInstance()->getWinSize();
941 TTFConfig ttfConfig(
"fonts/arial.ttf", 14);
942 auto label1 = Label::createWithTTF(ttfConfig,
LongSentencesExample, TextHAlignment::CENTER,size.width);
943 label1->setPosition( Vec2(size.width/2, size.height/2) );
944 label1->setAnchorPoint(Vec2(0.5f, 1.0f));
950 return "New Label + .TTF";
955 return "Testing auto-wrapping";
960 auto size = Director::getInstance()->getWinSize();
962 TTFConfig ttfConfig(
"fonts/arial.ttf", 18);
964 auto label1 = Label::createWithTTF(ttfConfig,
"Green", TextHAlignment::CENTER, size.width);
965 label1->setPosition(size.width/2, size.height * 0.5f);
966 label1->setTextColor( Color4B::GREEN );
970 auto label2 = Label::createWithTTF(ttfConfig,
"Red", TextHAlignment::CENTER, size.width);
971 label2->setPosition(size.width/2, size.height * 0.65f);
972 label2->setTextColor( Color4B::RED );
976 auto label3 = Label::createWithTTF(ttfConfig,
"Blue", TextHAlignment::CENTER, size.width);
977 label3->setPosition(size.width/2, size.height * 0.35f);
978 label3->setTextColor( Color4B::BLUE );
984 return "New Label + .TTF";
989 return "Testing Color";
994 auto winSize = Director::getInstance()->getWinSize();
996 TTFConfig ttfConfig(
"fonts/arial.ttf", 23);
998 _label->setPosition(winSize.width / 2, winSize.height / 2);
1001 auto menu = Menu::create(
1007 menu->alignItemsHorizontallyWithPadding(20);
1008 menu->setPosition(winSize.width / 2, winSize.height * 0.25f);
1040 return "New Label + .TTF";
1045 return "Testing text alignment";
1053 auto size = Director::getInstance()->getWinSize();
1055 auto drawNode = DrawNode::create();
1056 drawNode->setAnchorPoint(Vec2(0, 0));
1057 this->addChild(drawNode);
1058 drawNode->drawSegment(
1059 Vec2(size.width * 0.1f, size.height * 0.8f),
1060 Vec2(size.width * 0.1, 0.0f), 1, Color4F(1.0f, 0.0f, 0.0f, 1.0f));
1061 drawNode->drawSegment(
1062 Vec2(size.width * 0.85f, size.height * 0.8f),
1063 Vec2(size.width * 0.85f, 0.0f), 1, Color4F(1.0f, 0.0f, 0.0f, 1.0f));
1065 TTFConfig ttfConfig(
"fonts/HKYuanMini.ttf", 25, GlyphCollection::DYNAMIC);
1066 auto label1 = Label::createWithTTF(ttfConfig,
1067 "你好,Cocos2d-x v3的New Label.", TextHAlignment::LEFT, size.width * 0.75f);
1069 label1->setTextColor(Color4B(128, 255, 255, 255));
1070 label1->setPosition(Vec2(size.width * 0.1f, size.height * 0.6f));
1071 label1->setAnchorPoint(Vec2(0.0f, 0.5f));
1072 this->addChild(label1);
1075 FontAtlasCache::unloadFontAtlasTTF(
"fonts/HKYuanMini.ttf");
1076 label1->setTTFConfig(ttfConfig);
1079 auto label2 = Label::createWithTTF(ttfConfig,
1080 "早上好,Cocos2d-x v3的New Label.", TextHAlignment::LEFT, size.width * 0.75f);
1082 label2->setTextColor(Color4B(255, 128, 255, 255));
1083 label2->setPosition(Vec2(size.width * 0.1f, size.height * 0.4f));
1084 label2->setAnchorPoint(Vec2(0.0f, 0.5f));
1085 this->addChild(label2);
1088 auto label3 = Label::createWithTTF(ttfConfig,
1089 "美好的一天啊美好的一天啊美好的一天啊", TextHAlignment::LEFT, size.width * 0.75f);
1091 label3->setTextColor(Color4B(255, 255, 128, 255));
1092 label3->setPosition(Vec2(size.width * 0.1f, size.height * 0.2f));
1093 label3->setAnchorPoint(Vec2(0.0f, 0.5f));
1094 this->addChild(label3);
1100 return "New Label + .TTF";
1105 return "New Label with CJK + ASCII characters\n"
1106 "Characters should stay in the correct position";
1114 auto strings = FileUtils::getInstance()->getValueMapFromFile(
"strings/LabelFNTUNICODELanguages.xml");
1115 std::string chinese = strings[
"chinese1"].asString();
1116 auto winSize = Director::getInstance()->getWinSize();
1119 auto label1 = Label::createWithTTF(
"Buen día, ¿cómo te llamas?",
"fonts/arial.ttf", 23);
1120 label1->setPosition(winSize.width / 2, winSize.height * 0.65f);
1124 auto label2 = Label::createWithTTF(
"In welcher Straße haben Sie gelebt?",
"fonts/arial.ttf", 23);
1125 label2->setPosition(winSize.width / 2, winSize.height * 0.5f);
1129 auto label3 = Label::createWithTTF(chinese,
"fonts/HKYuanMini.ttf", 24);
1130 label3->setPosition(winSize.width / 2, winSize.height * 0.35f);
1136 return "New Label + TTF unicode";
1141 return "Uses the new Label with TTF. Testing unicode";
1149 std::string emojiString = FileUtils::getInstance()->getStringFromFile(
"fonts/emoji.txt");
1150 auto winSize = Director::getInstance()->getWinSize();
1152 auto label = Label::createWithTTF(emojiString,
"fonts/NotoEmoji-Regular.ttf", 23);
1153 label->setPosition(winSize.width / 2, winSize.height / 2);
1154 label->setDimensions(winSize.width, winSize.height);
1155 label->setVerticalAlignment(cocos2d::TextVAlignment::CENTER);
1156 label->setHorizontalAlignment(cocos2d::TextHAlignment::CENTER);
1162 return "New Label + Emoji";
1167 return "Uses the new Label with TTF. Testing Emoji";
1173 const char *ttfpaths[] = {
1174 "fonts/A Damn Mess.ttf",
1175 "fonts/Abberancy.ttf",
1176 "fonts/Abduction.ttf",
1177 "fonts/American Typewriter.ttf",
1178 "fonts/Paint Boy.ttf",
1179 "fonts/Schwarzwald.ttf",
1180 "fonts/Scissor Cuts.ttf",
1183 int fontCount =
sizeof(ttfpaths) /
sizeof(ttfpaths[0]);
1184 auto size = Director::getInstance()->getWinSize();
1185 TTFConfig ttfConfig(ttfpaths[0],20, GlyphCollection::NEHE);
1187 for (
int i = 0; i < fontCount; ++i) {
1188 ttfConfig.fontFilePath = ttfpaths[i];
1189 auto label = Label::createWithTTF(ttfConfig, ttfpaths[i], TextHAlignment::CENTER,0);
1191 label->setPosition(size.width / 2, ((size.height * 0.6) / fontCount * i) + (size.height / 4));
1194 log(
"ERROR: Cannot load: %s", ttfpaths[i]);
1201 return "New Label + TTF";
1211 auto size = Director::getInstance()->getWinSize();
1212 TTFConfig ttfConfig(
"fonts/arial.ttf", 40, GlyphCollection::DYNAMIC,
nullptr,
true);
1214 auto label1 = Label::createWithTTF(ttfConfig,
"Distance Field",TextHAlignment::CENTER,size.width);
1215 label1->setPosition( Vec2(size.width/2, size.height * 0.6f) );
1216 label1->setTextColor( Color4B::GREEN );
1219 auto action = Sequence::create(
1220 DelayTime::create(1.0f),
1221 ScaleTo::create(6.0f,5.0f,5.0f),
1222 ScaleTo::create(6.0f,1.0f,1.0f),
1224 label1->runAction(RepeatForever::create(action));
1227 auto& labelContentSize = label1->getContentSize();
1228 auto borderDraw = DrawNode::create();
1229 label1->addChild(borderDraw);
1230 borderDraw->clear();
1231 borderDraw->setLineWidth(1);
1235 Vec2(labelContentSize.width, 0.0f),
1236 Vec2(labelContentSize.width, labelContentSize.height),
1237 Vec2(0.0f, labelContentSize.height)
1239 borderDraw->drawPoly(vertices, 4,
true, Color4F::RED);
1241 auto label2 = Label::createWithTTF(ttfConfig,
"Distance Field",TextHAlignment::CENTER,size.width);
1242 label2->setPosition( Vec2(size.width/2, size.height * 0.3f) );
1243 label2->setTextColor( Color4B::RED );
1247 auto& labelContentSize2 = label2->getContentSize();
1248 auto borderDraw2 = DrawNode::create();
1249 label2->addChild(borderDraw2);
1250 borderDraw2->clear();
1251 borderDraw2->setLineWidth(1);
1255 Vec2(labelContentSize2.width, 0.0f),
1256 Vec2(labelContentSize2.width, labelContentSize2.height),
1257 Vec2(0.0f, labelContentSize2.height)
1259 borderDraw2->drawPoly(vertices2, 4,
true, Color4F::GREEN);
1264 return "New Label + .TTF";
1269 return "Testing rendering base on DistanceField";
1274 auto size = Director::getInstance()->getWinSize();
1276 auto bg = LayerColor::create(Color4B(200,191,231,255));
1279 TTFConfig ttfConfig(
"fonts/arial.ttf", 40, GlyphCollection::DYNAMIC,
nullptr,
true);
1281 auto label1 = Label::createWithTTF(ttfConfig,
"Glow", TextHAlignment::CENTER, size.width);
1282 label1->setPosition( Vec2(size.width/2, size.height*0.7) );
1283 label1->setTextColor( Color4B::GREEN );
1284 label1->enableGlow(Color4B::YELLOW);
1287 ttfConfig.outlineSize = 1;
1288 auto label2 = Label::createWithTTF(ttfConfig,
"Outline", TextHAlignment::CENTER, size.width);
1289 label2->setPosition( Vec2(size.width/2, size.height*0.6) );
1290 label2->setTextColor( Color4B::RED );
1291 label2->enableOutline(Color4B::BLUE);
1294 ttfConfig.outlineSize = 2;
1295 auto label3 = Label::createWithTTF(ttfConfig,
"Outline", TextHAlignment::CENTER, size.width);
1296 label3->setPosition( Vec2(size.width/2, size.height*0.48) );
1297 label3->setTextColor( Color4B::RED );
1298 label3->enableOutline(Color4B::BLUE);
1301 ttfConfig.outlineSize = 3;
1302 auto label4 = Label::createWithTTF(ttfConfig,
"Outline", TextHAlignment::CENTER, size.width);
1303 label4->setPosition( Vec2(size.width/2, size.height*0.36) );
1304 label4->setTextColor( Color4B::RED );
1305 label4->enableOutline(Color4B::BLUE);
1311 return "New Label + .TTF";
1316 return "Testing outline and glow of label";
1328 auto size = Director::getInstance()->getWinSize();
1330 auto bg = LayerColor::create(Color4B(200,191,231,255));
1333 auto slider = ui::Slider::create();
1335 slider->setTouchEnabled(
true);
1336 slider->loadBarTexture(
"cocosui/sliderTrack.png");
1337 slider->loadSlidBallTextures(
"cocosui/sliderThumb.png",
"cocosui/sliderThumb.png",
"");
1338 slider->loadProgressBarTexture(
"cocosui/sliderProgress.png");
1339 slider->setPosition(Vec2(size.width / 2.0f, size.height * 0.15f + slider->getContentSize().height * 2.0f));
1340 slider->setPercent(52);
1342 addChild(slider, 999);
1344 auto slider2 = ui::Slider::create();
1346 slider2->setTouchEnabled(
true);
1347 slider2->loadBarTexture(
"cocosui/sliderTrack.png");
1348 slider2->loadSlidBallTextures(
"cocosui/sliderThumb.png",
"cocosui/sliderThumb.png",
"");
1349 slider2->loadProgressBarTexture(
"cocosui/sliderProgress.png");
1350 slider2->setPosition(Vec2(size.width * 0.15f, size.height / 2.0f));
1351 slider2->setRotation(90);
1352 slider2->setPercent(52);
1354 addChild(slider2, 999);
1357 float horizontalSliderY = slider->getPosition().y;
1358 float step = (subtitleY - horizontalSliderY) / 4;
1360 TTFConfig ttfConfig(
"fonts/arial.ttf", 40, GlyphCollection::DYNAMIC,
nullptr,
true);
1363 shadowLabelTTF->setPosition( Vec2(size.width/2, horizontalSliderY + step * (0.5f + 3)) );
1369 shadowLabelOutline->setPosition( Vec2(size.width/2, horizontalSliderY + step * (0.5f + 2)) );
1376 shadowLabelGrow->setPosition( Vec2(size.width/2, horizontalSliderY + step * (0.5f + 1)) );
1382 shadowLabelBMFont = Label::createWithBMFont(
"fonts/bitmapFontTest.fnt",
"BMFont:Shadow");
1383 shadowLabelBMFont->setPosition( Vec2(size.width/2, horizontalSliderY + step * 0.5f));
1391 if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
1393 Slider* slider = (Slider*)this->getChildByTag(1);
1394 Slider* slider2 = (Slider*)this->getChildByTag(2);
1396 auto offset = Size(slider->getPercent()-50,50 - slider2->getPercent());
1411 return "Testing shadow of label";
1418 auto label1 = Label::createWithCharMap(
"fonts/tuffy_bold_italic-charmap.plist");
1420 label1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
1421 label1->setPosition( Vec2(10,100) );
1422 label1->setOpacity( 200 );
1424 auto label2 = Label::createWithCharMap(
"fonts/tuffy_bold_italic-charmap.plist");
1426 label2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
1427 label2->setPosition( Vec2(10,200) );
1428 label2->setOpacity( 32 );
1436 char string[12] = {0};
1437 sprintf(
string,
"%2.2f Test",
_time);
1440 label1->setString(
string);
1443 sprintf(
string,
"%d", (
int)
_time);
1444 label2->setString(
string);
1449 return "New Label + char map file";
1454 return "Updating label should be fast.";
1464 auto label1 = Label::createWithCharMap(
"fonts/tuffy_bold_italic-charmap.plist");
1466 label1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
1467 label1->setPosition( Vec2(10,100) );
1468 label1->setOpacity( 200 );
1470 auto label2 = Label::createWithCharMap(
"fonts/tuffy_bold_italic-charmap.plist");
1472 label2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
1473 label2->setPosition( Vec2(10,200) );
1474 label2->setColor( Color3B::RED );
1476 auto fade = FadeOut::create(1.0f);
1477 auto fade_in = fade->reverse();
1479 auto seq = Sequence::create(fade, fade_in, cb,
nullptr);
1480 auto repeat = RepeatForever::create( seq );
1481 label2->runAction( repeat );
1490 CCLOG(
"Action finished");
1496 char string[12] = {0};
1497 sprintf(
string,
"%2.2f Test",
_time);
1499 label1->setString(
string);
1502 sprintf(
string,
"%d", (
int)
_time);
1503 label2->setString(
string );
1508 return "New Label + CharMap";
1513 return "Opacity + Color should work at the same time";
1518 auto size = Director::getInstance()->getWinSize();
1520 TTFConfig ttfConfig(
"fonts/arial.ttf", 40, GlyphCollection::DYNAMIC,
nullptr,
true);
1522 auto label1 = Label::createWithTTF(ttfConfig,
"Test崩溃123", TextHAlignment::CENTER, size.width);
1523 label1->setPosition( Vec2(size.width/2, size.height/2) );
1529 return "New Label Crash Test";
1534 return "Not crash when use character that is not contained in font.";
1539 auto s = Director::getInstance()->getWinSize();
1540 float delta = s.height/4;
1542 auto label1 = Label::createWithSystemFont(
"Cocos2d-x Label Test",
"arial", 24);
1544 label1->setPosition(Vec2(s.width/2, delta * 2));
1545 label1->setColor(Color3B::RED);
1547 TTFConfig ttfConfig(
"fonts/arial.ttf", 24);
1548 auto label2 = Label::createWithTTF(ttfConfig,
"Cocos2d-x Label Test");
1550 label2->setPosition(Vec2(s.width/2, delta * 2));
1552 auto drawNode = DrawNode::create();
1553 auto labelSize = label1->getContentSize();
1554 auto origin = Director::getInstance()->getWinSize();
1556 origin.width = origin.width / 2 - (labelSize.width / 2);
1557 origin.height = origin.height / 2 - (labelSize.height / 2);
1561 Vec2(origin.width, origin.height),
1562 Vec2(labelSize.width + origin.width, origin.height),
1563 Vec2(labelSize.width + origin.width, labelSize.height + origin.height),
1564 Vec2(origin.width, labelSize.height + origin.height)
1566 drawNode->drawPoly(vertices, 4,
true, Color4F(1.0f, 0.0f, 0.0f, 1.0f));
1568 labelSize = label2->getContentSize();
1569 origin = Director::getInstance()->getWinSize();
1571 origin.width = origin.width / 2 - (labelSize.width / 2);
1572 origin.height = origin.height / 2 - (labelSize.height / 2);
1576 Vec2(origin.width, origin.height),
1577 Vec2(labelSize.width + origin.width, origin.height),
1578 Vec2(labelSize.width + origin.width, labelSize.height + origin.height),
1579 Vec2(origin.width, labelSize.height + origin.height)
1581 drawNode->drawPoly(vertices2, 4,
true, Color4F(1.0f, 1.0f, 1.0f, 1.0f));
1588 return "New / Old TTF";
1593 return "Comparison between old(red) and new(white) TTF label";
1598 auto size = Director::getInstance()->getWinSize();
1600 auto label1 = Label::create();
1601 label1->setString(
"Default Font");
1602 label1->setPosition( Vec2(size.width/2, size.height * 0.7) );
1605 auto label3 = Label::createWithSystemFont(
"Marker Felt",
"Marker Felt",32);
1606 label3->setPosition( Vec2(size.width/2, size.height * 0.5) );
1612 return "New Label Test";
1617 return "create label by font name,compatible with old labelTTF";
1622 auto blockSize = Size(200, 160);
1623 auto s = Director::getInstance()->getWinSize();
1625 auto pos = Vec2((s.width - blockSize.width) / 2, (s.height - blockSize.height) / 2);
1626 auto colorLayer = LayerColor::create(Color4B(100, 100, 100, 255), blockSize.width, blockSize.height);
1627 colorLayer->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
1628 colorLayer->setPosition(pos);
1630 this->addChild(colorLayer);
1632 MenuItemFont::setFontSize(30);
1633 auto menu = Menu::create(
1638 menu->alignItemsVerticallyWithPadding(4);
1639 menu->setPosition(Vec2(50.0f, s.height / 2 - 20));
1640 this->addChild(menu);
1642 menu = Menu::create(
1647 menu->alignItemsVerticallyWithPadding(4);
1648 menu->setPosition(Vec2(s.width - 50, s.height / 2 - 20));
1649 this->addChild(menu);
1651 TTFConfig ttfConfig(
"fonts/arial.ttf", 50);
1652 _label = Label::createWithTTF(ttfConfig,
"abc efg hijk lmn opq rst uvw xyz");
1653 _label->setDimensions(200, 160);
1654 _label->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
1655 _label->setPosition(pos);
1661 _label->setHorizontalAlignment(TextHAlignment::LEFT);
1666 _label->setHorizontalAlignment(TextHAlignment::CENTER);
1671 _label->setHorizontalAlignment(TextHAlignment::RIGHT);
1676 _label->setVerticalAlignment(TextVAlignment::TOP);
1681 _label->setVerticalAlignment(TextVAlignment::CENTER);
1686 _label->setVerticalAlignment(TextVAlignment::BOTTOM);
1691 return "Testing New Label";
1696 return "Test text alignment";
1701 auto size = Director::getInstance()->getWinSize();
1703 auto label = Label::createWithBMFont(
"fonts/bitmapFontTest3.fnt",
"123\n456");
1704 label->setPosition(Vec2(size.width /2.0f, size.height / 2.0f));
1705 label->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
1708 int len = label->getStringLength();
1709 for (
int i = 0; i < len; ++i)
1711 auto sprite = label->getLetter(i);
1712 if (sprite !=
nullptr)
1714 sprite->setFlippedY(
true);
1721 return "New Label Bugs Test";
1726 return "Reorder issue #4428.The label should be flipped vertically.";
1731 auto label = Label::createWithTTF(
"Smaller font test",
"fonts/arial.ttf",5);
1733 label->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
1739 return "New Label Bugs Test";
1744 return "Reorder issue #4999.The label should be display cleanly.";
1749 auto size = Director::getInstance()->getWinSize();
1751 auto bg = LayerColor::create(Color4B(200,191,231,255));
1754 TTFConfig ttfConfig(
"fonts/arial.ttf", 25, GlyphCollection::DYNAMIC,
nullptr,
false);
1756 label = Label::createWithTTF(ttfConfig,
"Test\nLine\nHeight");
1757 label->setPosition( Vec2(size.width/2, size.height*0.5f) );
1758 label->setTextColor( Color4B::RED );
1761 auto slider = ui::Slider::create();
1762 slider->setTouchEnabled(
true);
1763 slider->loadBarTexture(
"cocosui/sliderTrack.png");
1764 slider->loadSlidBallTextures(
"cocosui/sliderThumb.png",
"cocosui/sliderThumb.png",
"");
1765 slider->loadProgressBarTexture(
"cocosui/sliderProgress.png");
1766 slider->setPosition(Vec2(size.width / 2.0f, size.height * 0.15f + slider->getContentSize().height * 2.0f));
1767 slider->setPercent(
label->getLineHeight());
1774 if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
1776 Slider* slider = (Slider*)sender;
1777 label->setLineHeight(slider->getPercent());
1788 return "Testing line height of label";
1793 auto size = Director::getInstance()->getWinSize();
1795 auto bg = LayerColor::create(Color4B(200,191,231,255));
1798 TTFConfig ttfConfig(
"fonts/arial.ttf", 40, GlyphCollection::DYNAMIC,
nullptr,
false);
1800 label = Label::createWithTTF(ttfConfig,
"Test additional kerning");
1801 label->setPosition(size.width/2, size.height * 0.5f);
1802 label->setTextColor( Color4B::RED );
1805 auto slider = ui::Slider::create();
1806 slider->setTouchEnabled(
true);
1807 slider->loadBarTexture(
"cocosui/sliderTrack.png");
1808 slider->loadSlidBallTextures(
"cocosui/sliderThumb.png",
"cocosui/sliderThumb.png",
"");
1809 slider->loadProgressBarTexture(
"cocosui/sliderProgress.png");
1810 slider->setPosition(Vec2(size.width / 2.0f, size.height * 0.15f + slider->getContentSize().height * 2.0f));
1811 slider->setPercent(0);
1818 if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
1820 Slider* slider = (Slider*)sender;
1821 label->setAdditionalKerning(slider->getPercent());
1832 return "Testing additional kerning of label";
1837 auto label = Label::createWithBMFont(
"fonts/bitmapFontChinese.fnt",
"中国中国中国中国中国");
1838 label->setDimensions(5,100);
1845 return "Reorder issue #8492";
1850 return "Work fine when dimensions are not enough to fit one character";
1855 auto label = Label::createWithTTF(
"Multi-line text\nwith\noutline feature",
"fonts/arial.ttf", 24);
1856 label->enableOutline(Color4B::ORANGE,1);
1863 return "Reorder issue #9095";
1868 return "end in string 'outline feature'";
1874 Size s = Director::getInstance()->getWinSize();
1875 auto parent = Node::create();
1876 parent->setPosition(s.width/2, s.height/2);
1877 parent->setVisible(
false);
1878 this->addChild(parent);
1880 auto label = Label::createWithTTF(
"Crashed!!!",
"fonts/HKYuanMini.ttf", 24);
1882 parent->addChild(label);
1887 return "Test for Issue #9255";
1892 return "switch to desktop and switch back. Crashed!!!";
1897 auto label = Label::createWithSystemFont(
"Hello World!",
"fonts/arial.ttf", 24, Size(30.0f,100.0f));
1904 return "New Label + System font";
1909 return "Testing create Label with small dimensions.Program should not dead loop";
1916 auto labelA = Label::createWithSystemFont(
"create label with system font",
"fonts/arial.ttf", 24);
1917 auto size = labelA->getContentSize();
1918 labelA->setDimensions(size.width, size.height);
1919 labelA->setPosition(center.x, center.y + 50);
1922 auto labelB = Label::createWithTTF(
"create label with TTF",
"fonts/arial.ttf", 24);
1923 size = labelB->getContentSize();
1924 labelB->setDimensions(size.width, size.height);
1925 labelB->setPosition(center.x, center.y - 50);
1931 return "Test for Issue #10089";
1936 return "Should be able to see two single-line text";
1941 auto size = Director::getInstance()->getWinSize();
1943 auto label1 = Label::createWithSystemFont(
"Color4B::Red",
"fonts/arial.ttf", 20);
1944 label1->setPosition(Vec2(size.width / 2, size.height * 0.3f));
1945 label1->setTextColor(Color4B::RED);
1948 auto label2 = Label::createWithSystemFont(
"Color4B::Green",
"fonts/arial.ttf", 20);
1949 label2->setPosition(Vec2(size.width / 2, size.height * 0.4f));
1950 label2->setTextColor(Color4B::GREEN);
1953 auto label3 = Label::createWithSystemFont(
"Color4B::Blue",
"fonts/arial.ttf", 20);
1954 label3->setPosition(Vec2(size.width / 2, size.height * 0.5f));
1955 label3->setTextColor(Color4B::BLUE);
1958 auto label4 = Label::createWithSystemFont(
"Color4B(0, 0, 255, 100)",
"fonts/arial.ttf", 20);
1959 label4->setPosition(Vec2(size.width / 2, size.height * 0.6f));
1960 label4->setTextColor(Color4B(0, 0, 255, 100));
1966 return "New Label + system font";
1971 return "Testing text color of system font";
1978 auto label = Label::createWithTTF(
"create label with TTF",
"fonts/arial.ttf", 24);
1979 label->getLetter(5);
1980 label->setString(
"Hi");
1981 label->setPosition(center.x, center.y);
1987 return "Test for Issue #10773";
1992 return "Should not crash!";
1999 auto label = Label::createWithTTF(
"abcdefg",
"fonts/arial.ttf", 24);
2000 for (
int index = 0; index < label->getStringLength(); ++index)
2002 label->getLetter(index);
2005 this->runAction(Sequence::create(DelayTime::create(2.0f), CallFunc::create([label](){
2006 label->setString(
"Hello World!");
2009 label->setPosition(center.x, center.y);
2015 return "Test for Issue #11576";
2020 return "You should see another string displayed correctly after 2 seconds.";
2027 auto label = Label::createWithTTF(
"中国",
"fonts/HKYuanMini.ttf", 150);
2028 label->enableOutline(Color4B::RED, 2);
2029 label->setPosition(center.x, center.y);
2035 return "Test for Issue #11699";
2040 return "Outline should match with the characters exactly.";
2047 auto label = Label::createWithTTF(
"abcdefghijklmn",
"fonts/arial.ttf", 30);
2048 label->setWidth(70);
2049 label->setLineBreakWithoutSpace(
true);
2050 label->setPosition(center.x, center.y);
2053 auto labelSize = label->getContentSize();
2054 auto winSize = Director::getInstance()->getWinSize();
2056 labelOrigin.x = winSize.width / 2 - (labelSize.width / 2);
2057 labelOrigin.y = winSize.height / 2 - (labelSize.height / 2);
2060 Vec2(labelOrigin.x, labelOrigin.y),
2061 Vec2(labelOrigin.x + labelSize.width, labelOrigin.y),
2062 Vec2(labelOrigin.x + labelSize.width, labelOrigin.y + labelSize.height),
2063 Vec2(labelOrigin.x, labelOrigin.y + labelSize.height)
2066 auto drawNode = DrawNode::create();
2067 drawNode->drawPoly(vertices, 4,
true, Color4F::WHITE);
2073 return "Test for Issue #12409";
2078 return "Testing auto-wrapping without space.";
2085 auto label = Label::createWithTTF(
"Label with child node:",
"fonts/arial.ttf", 24);
2086 label->setPosition(center.x, center.y);
2089 auto jump = JumpBy::create(1.0f, Vec2::ZERO, 60, 1);
2090 auto jump_4ever = RepeatForever::create(jump);
2091 label->runAction(jump_4ever);
2093 auto spite = Sprite::create(
"Images/SpookyPeas.png");
2094 spite->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
2095 spite->setPosition(label->getContentSize().width, label->getContentSize().height/2);
2096 label->addChild(spite);
2101 return "Label support add child nodes";
2108 auto label = Label::createWithTTF(
"Hello",
"fonts/xingkai-incomplete.ttf", 30);
2109 label->setPosition(center.x, center.y);
2115 return "Test for Issue #12775";
2120 return "Should not crash if the font not contain a Unicode charmap.";
2127 auto label = Label::createWithTTF(
"Hello World",
"fonts/arial.ttf", 24);
2128 label->setPosition(center.x, center.y);
2131 label->getLetter(0)->setColor(Color3B::RED);
2132 label->getLetter(1)->setColor(Color3B::GREEN);
2133 label->getLetter(2)->setColor(Color3B::BLUE);
2134 auto action = RepeatForever::create(Sequence::create(
2135 FadeOut::create(2), FadeIn::create(2),
nullptr));
2136 label->runAction(action);
2141 return "Test for Issue #11585";
2146 return "The color of letter should not be overridden by fade action.";
2153 auto label = Label::createWithTTF(
"Glow MenuItemLabel",
"fonts/arial.ttf", 30);
2154 label->setTextColor(Color4B::RED);
2155 label->enableGlow(Color4B::YELLOW);
2156 auto menuItem1 = MenuItemLabel::create(label, [](Ref*){});
2157 menuItem1->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
2158 menuItem1->setPosition(center.x - label->getContentSize().width/2, center.y);
2160 auto menu = Menu::create(menuItem1, NULL);
2161 menu->setPosition(Vec2::ZERO);
2162 this->addChild(menu);
2167 return "Test for Issue #10688";
2172 return "The MenuItemLabel should be displayed in the middle of the screen.";
2179 auto label = Label::createWithTTF(
"asdfghjklzxcvbnmqwertyuiop",
"fonts/arial.ttf", 150);
2180 label->setPosition(center);
2183 label->getContentSize();
2184 label->setString(
"A");
2185 this->scheduleOnce([](
float dt){
2186 FontAtlasCache::purgeCachedData();
2187 }, 0.15f,
"FontAtlasCache::purgeCachedData");
2192 return "Test for Issue #13202";
2197 return "FontAtlasCache::purgeCachedData should not cause crash.";
2204 auto label = Label::createWithTTF(
"Spaces should not be lost",
"fonts/Fingerpop.ttf", 20);
2205 label->setPosition(center);
2211 return "Test for Issue #9500";
2216 return "Spaces should not be lost if label created with Fingerpop.ttf";
2221 auto minusSprite = Sprite::create(
"extensions/stepper-minus.png");
2222 auto plusSprite = Sprite::create(
"extensions/stepper-plus.png");
2224 return ControlStepper::create(minusSprite, plusSprite);
2229 auto size = Director::getInstance()->getVisibleSize();
2247 auto fontSizeLabel = Label::createWithSystemFont(
"font size:20",
"Arial", 10);
2248 fontSizeLabel->setName(
"fontSize");
2251 stepper->setPosition(size.width * 0.5 - stepper->getContentSize().width / 2,
2253 stepper->setValue(20);
2254 stepper->addTargetWithActionForControlEvents(
this,
2256 Control::EventType::VALUE_CHANGED);
2257 this->addChild(stepper);
2258 stepper->setName(
"stepper");
2259 stepper->setScale(0.5);
2261 fontSizeLabel->setPosition(stepper->getPosition() -
2262 Vec2(stepper->getContentSize().width/2 + fontSizeLabel->getContentSize().width/2,0.0f));
2263 this->addChild(fontSizeLabel);
2268 auto label = Label::createWithSystemFont(
"Enable Wrap:",
"Arial", 10);
2269 label->setColor(Color3B::WHITE);
2270 label->setPosition(Vec2(size.width * 0.8f - 100, size.height * 0.8f));
2271 this->addChild(label);
2273 CheckBox* checkBox = CheckBox::create(
"cocosui/check_box_normal.png",
2274 "cocosui/check_box_normal_press.png",
2275 "cocosui/check_box_active.png",
2276 "cocosui/check_box_normal_disable.png",
2277 "cocosui/check_box_active_disable.png");
2278 checkBox->setPosition(Vec2(size.width * 0.8f - 55, size.height * 0.8f));
2279 checkBox->setScale(0.5);
2280 checkBox->setSelected(
true);
2281 checkBox->setName(
"toggleWrap");
2283 checkBox->addEventListener([=](Ref* ref, CheckBox::EventType event){
2284 if (event == CheckBox::EventType::SELECTED) {
2285 _label->enableWrap(
true);
2287 _label->enableWrap(
false);
2291 this->addChild(checkBox);
2296 auto label = Label::createWithSystemFont(
"Toggle Label Type:",
"Arial", 10);
2297 label->setColor(Color3B::WHITE);
2298 label->setPosition(Vec2(size.width * 0.8f + 15, size.height * 0.8f));
2299 this->addChild(label);
2301 CheckBox* checkBox = CheckBox::create(
"cocosui/check_box_normal.png",
2302 "cocosui/check_box_normal_press.png",
2303 "cocosui/check_box_active.png",
2304 "cocosui/check_box_normal_disable.png",
2305 "cocosui/check_box_active_disable.png");
2306 checkBox->setPosition(Vec2(size.width * 0.8f + 70, size.height * 0.8f));
2307 checkBox->setScale(0.5);
2308 checkBox->setName(
"toggleType");
2309 checkBox->setSelected(
true);
2311 auto stepper = (ControlStepper*)this->getChildByName(
"stepper");
2313 checkBox->addEventListener([=](Ref* ref, CheckBox::EventType event){
2314 float fontSize = stepper->getValue();
2316 if (event == CheckBox::EventType::SELECTED) {
2318 auto ttfConfig =
_label->getTTFConfig();
2319 ttfConfig.fontSize = fontSize;
2320 _label->setTTFConfig(ttfConfig);
2323 _label->setBMFontFilePath(
"fonts/enligsh-chinese.fnt");
2324 _label->setBMFontSize(fontSize);
2327 this->addChild(checkBox);
2334 MenuItemFont::setFontSize(30);
2335 auto menu = Menu::create(
2340 menu->alignItemsVerticallyWithPadding(4);
2341 menu->setPosition(Vec2(50.0f, size.height / 2 - 20));
2342 this->addChild(menu);
2344 menu = Menu::create(
2349 menu->alignItemsVerticallyWithPadding(4);
2350 menu->setPosition(Vec2(size.width - 50, size.height / 2 - 20));
2351 this->addChild(menu);
2356 auto slider = ui::Slider::create();
2358 slider->setTouchEnabled(
true);
2359 slider->loadBarTexture(
"cocosui/sliderTrack.png");
2360 slider->loadSlidBallTextures(
"cocosui/sliderThumb.png",
"cocosui/sliderThumb.png",
"");
2361 slider->loadProgressBarTexture(
"cocosui/sliderProgress.png");
2362 slider->setPosition(Vec2(size.width / 2.0f, size.height * 0.15f + slider->getContentSize().height * 2.0f - 5));
2363 slider->setPercent(52);
2366 auto slider2 = ui::Slider::create();
2368 slider2->setTouchEnabled(
true);
2369 slider2->loadBarTexture(
"cocosui/sliderTrack.png");
2370 slider2->loadSlidBallTextures(
"cocosui/sliderThumb.png",
"cocosui/sliderThumb.png",
"");
2371 slider2->loadProgressBarTexture(
"cocosui/sliderProgress.png");
2372 slider2->setPosition(Vec2(size.width * 0.2f, size.height / 2.0f));
2373 slider2->setRotation(90);
2374 slider2->setPercent(52);
2376 auto winSize = Director::getInstance()->getVisibleSize();
2378 slider->addEventListener([=](Ref* ref, Slider::EventType event){
2379 float percent = slider->getPercent();
2380 auto labelSize =
_label->getContentSize();
2381 auto drawNodeSize = Size(percent / 100.0 * winSize.width, labelSize.height);
2382 if(drawNodeSize.width <=0){
2383 drawNodeSize.width = 0.1f;
2385 _label->setDimensions(drawNodeSize.width, drawNodeSize.height);
2389 slider2->addEventListener([=](Ref* ref, Slider::EventType event){
2390 float percent = slider2->getPercent();
2391 auto labelSize =
_label->getContentSize();
2392 auto drawNodeSize = Size( labelSize.width, percent / 100.0 * winSize.height);
2393 if(drawNodeSize.height <= 0){
2394 drawNodeSize.height = 0.1f;
2396 _label->setDimensions(drawNodeSize.width, drawNodeSize.height);
2404 _label = Label::createWithTTF(
"五六七八This is a very long sentence一二三四.",
"fonts/HKYuanMini.ttf", 20);
2405 _label->setDimensions(size.width/2, size.height/2);
2406 _label->setPosition(center);
2407 _label->setName(
"Label");
2408 _label->setString(
"五六七八This is a very long sentence一二三.");
2425 _label->setHorizontalAlignment(TextHAlignment::LEFT);
2430 _label->setHorizontalAlignment(TextHAlignment::CENTER);
2435 _label->setHorizontalAlignment(TextHAlignment::RIGHT);
2440 _label->setVerticalAlignment(TextVAlignment::TOP);
2445 _label->setVerticalAlignment(TextVAlignment::CENTER);
2450 _label->setVerticalAlignment(TextVAlignment::BOTTOM);
2456 ControlStepper* pControl = (ControlStepper*)sender;
2458 auto fontSizeLabel = (Label*)this->getChildByName(
"fontSize");
2459 float fontSize = (float)pControl->getValue();
2460 fontSizeLabel->setString(StringUtils::format(
"font size:%d", (
int)fontSize));
2463 auto ttfConfig =
_label->getTTFConfig();
2464 ttfConfig.fontSize = fontSize;
2465 _label->setTTFConfig(ttfConfig);
2467 _label->setBMFontSize(fontSize);
2469 _label->setSystemFontSize(fontSize);
2484 auto origin = Director::getInstance()->getWinSize();
2485 auto labelSize =
_label->getContentSize();
2487 origin.width = origin.width / 2 - (labelSize.width / 2);
2488 origin.height = origin.height / 2 - (labelSize.height / 2);
2492 Vec2(origin.width, origin.height),
2493 Vec2(drawNodeSize.width + origin.width, origin.height),
2494 Vec2(drawNodeSize.width + origin.width, drawNodeSize.height + origin.height),
2495 Vec2(origin.width, drawNodeSize.height + origin.height)
2498 _drawNode->drawLine(vertices[0], vertices[1], Color4F(1.0f, 1.0f, 1.0f, 1.0f));
2499 _drawNode->drawLine(vertices[0], vertices[3], Color4F(1.0f, 1.0f, 1.0f, 1.0f));
2500 _drawNode->drawLine(vertices[2], vertices[3], Color4F(1.0f, 1.0f, 1.0f, 1.0f));
2501 _drawNode->drawLine(vertices[1], vertices[2], Color4F(1.0f, 1.0f, 1.0f, 1.0f));
2507 _label->setLineSpacing(5);
2508 _label->setAdditionalKerning(2);
2509 _label->setVerticalAlignment(TextVAlignment::CENTER);
2510 _label->setOverflow(Label::Overflow::CLAMP);
2516 return "Clamp content Test: Word Wrap";
2526 _label->setLineBreakWithoutSpace(
true);
2527 _label->setString(
"五六七八This \nis a very long sentence一二三四.");
2528 _label->setLineSpacing(5);
2529 _label->setAdditionalKerning(2);
2530 _label->setVerticalAlignment(TextVAlignment::TOP);
2531 _label->setOverflow(Label::Overflow::CLAMP);
2537 return "Clamp content Test: Char Wrap";
2549 _label->setLineBreakWithoutSpace(
false);
2550 const char* no_break_space_utf8 =
"\xC2\xA0";
2551 auto str = StringUtils::format(
"The price is $%s1.25. \n\nthe space between \"$\" and \"1.25\" is a no break space.", no_break_space_utf8);
2553 _label->setVerticalAlignment(TextVAlignment::TOP);
2554 _label->setOverflow(Label::Overflow::CLAMP);
2559 return "Wrap Test: No break space";
2571 _label->setLineSpacing(5);
2572 _label->setAdditionalKerning(2);
2573 _label->setString(
"This is Hello World hehe I love 一二三");
2574 _label->setVerticalAlignment(TextVAlignment::TOP);
2575 _label->setOverflow(Label::Overflow::SHRINK);
2580 return "Shrink content Test: Word Wrap";
2590 _label->setLineSpacing(5);
2591 _label->setAdditionalKerning(2);
2592 _label->setLineBreakWithoutSpace(
true);
2593 _label->setString(
"This is Hello World hehe I love 一二三");
2594 _label->setVerticalAlignment(TextVAlignment::CENTER);
2595 _label->setOverflow(Label::Overflow::SHRINK);
2600 return "Shrink content Test: Char Wrap";
2610 _label->setLineSpacing(5);
2611 _label->setAdditionalKerning(2);
2612 _label->setVerticalAlignment(TextVAlignment::TOP);
2613 _label->setOverflow(Label::Overflow::RESIZE_HEIGHT);
2618 auto slider1 = (ui::Slider*)this->getChildByTag(1);
2620 auto slider2 = (ui::Slider*)this->getChildByTag(2);
2621 slider2->setVisible(
false);
2623 auto winSize = Director::getInstance()->getVisibleSize();
2624 slider1->addEventListener([=](Ref* ref, Slider::EventType event){
2625 float percent = slider1->getPercent();
2626 auto drawNodeSize = Size(percent / 100.0 * winSize.width,
_label->getContentSize().height);
2627 if(drawNodeSize.height <= 0){
2628 drawNodeSize.height = 0.1f;
2630 _label->setDimensions(drawNodeSize.width, drawNodeSize.height);
2634 auto stepper = (ControlStepper*)this->getChildByName(
"stepper");
2635 stepper->setValue(12);
2637 auto label = Label::createWithSystemFont(
"Char Line break:",
"Arial", 10);
2638 label->setColor(Color3B::WHITE);
2639 label->setPosition(Vec2(winSize.width * 0.1f, winSize.height * 0.8f));
2640 this->addChild(label);
2642 CheckBox* checkBox = CheckBox::create(
"cocosui/check_box_normal.png",
2643 "cocosui/check_box_normal_press.png",
2644 "cocosui/check_box_active.png",
2645 "cocosui/check_box_normal_disable.png",
2646 "cocosui/check_box_active_disable.png");
2647 checkBox->setPosition(Vec2(winSize.width * 0.2f , winSize.height * 0.8f));
2648 checkBox->setScale(0.5);
2649 checkBox->setSelected(
false);
2650 checkBox->setName(
"LineBreak");
2652 checkBox->addEventListener([=](Ref* ref, CheckBox::EventType event){
2653 if (event == CheckBox::EventType::SELECTED) {
2654 _label->setLineBreakWithoutSpace(
true);
2656 _label->setLineBreakWithoutSpace(
false);
2660 this->addChild(checkBox);
2666 return "Resize content Test";
2676 _label->setLineSpacing(5);
2677 _label->setAdditionalKerning(2);
2678 _label->setVerticalAlignment(TextVAlignment::CENTER);
2679 _label->setOverflow(Label::Overflow::NONE);
2684 auto slider1 = (ui::Slider*)this->getChildByTag(1);
2686 auto slider2 = (ui::Slider*)this->getChildByTag(2);
2687 slider2->setVisible(
false);
2689 auto winSize = Director::getInstance()->getVisibleSize();
2690 slider1->addEventListener([=](Ref* ref, Slider::EventType event){
2691 float percent = slider1->getPercent();
2692 auto drawNodeSize = Size(percent / 100.0 * winSize.width,
_label->getContentSize().height);
2693 if(drawNodeSize.height <= 0){
2694 drawNodeSize.height = 0.1f;
2696 _label->setDimensions(drawNodeSize.width, drawNodeSize.height);
2700 auto stepper = (ControlStepper*)this->getChildByName(
"stepper");
2701 stepper->setValue(12);
2703 auto label = Label::createWithSystemFont(
"Char Line break:",
"Arial", 10);
2704 label->setColor(Color3B::WHITE);
2705 label->setPosition(Vec2(winSize.width * 0.1f, winSize.height * 0.8f));
2706 this->addChild(label);
2708 CheckBox* checkBox = CheckBox::create(
"cocosui/check_box_normal.png",
2709 "cocosui/check_box_normal_press.png",
2710 "cocosui/check_box_active.png",
2711 "cocosui/check_box_normal_disable.png",
2712 "cocosui/check_box_active_disable.png");
2713 checkBox->setPosition(Vec2(winSize.width * 0.2f , winSize.height * 0.8f));
2714 checkBox->setScale(0.5);
2715 checkBox->setSelected(
false);
2716 checkBox->setName(
"LineBreak");
2718 checkBox->addEventListener([=](Ref* ref, CheckBox::EventType event){
2719 if (event == CheckBox::EventType::SELECTED) {
2720 _label->setLineBreakWithoutSpace(
true);
2722 _label->setLineBreakWithoutSpace(
false);
2726 this->addChild(checkBox);
2735 Size winSize = Director::getInstance()->getVisibleSize();
2738 auto radioButtonGroup = RadioButtonGroup::create();
2739 this->addChild(radioButtonGroup);
2742 static const int NUMBER_OF_BUTTONS = 4;
2744 std::vector<std::string> labelTypes = {
"Normal",
"Clamp",
"Shrink",
"RESIZE"};
2746 for(
int i = 0; i < NUMBER_OF_BUTTONS; ++i)
2749 RadioButton* radioButton = RadioButton::create(
"cocosui/radio_button_off.png",
"cocosui/radio_button_on.png");
2751 radioButton->setPosition(Vec2(posX, winSize.height / 2.0f + 70));
2752 radioButton->setScale(1.2f);
2754 radioButton->setTag(i);
2755 radioButtonGroup->addRadioButton(radioButton);
2756 this->addChild(radioButton);
2758 auto label = Label::createWithSystemFont(labelTypes.at(i),
"Arial", 20);
2759 label->setPosition(radioButton->getPosition() + Vec2(50.0f,0.0f));
2760 this->addChild(label);
2766 return "Toggle Label Type Test";
2777 if(radioButton ==
nullptr)
2784 case RadioButton::EventType::SELECTED:
2786 switch (radioButton->getTag()) {
2788 _label->setOverflow(Label::Overflow::NONE);
2791 _label->setOverflow(Label::Overflow::CLAMP);
2794 _label->setOverflow(Label::Overflow::SHRINK);
2797 _label->setOverflow(Label::Overflow::RESIZE_HEIGHT);
2807 auto checkbox = (CheckBox*)(this->getChildByName(
"toggleWrap"));
2808 checkbox->setSelected(
_label->isWrapEnabled());
2814 _label->setLineSpacing(5);
2815 _label->setVerticalAlignment(TextVAlignment::CENTER);
2816 _label->setOverflow(Label::Overflow::NONE);
2817 _label->setSystemFontName(
"Hiragino Sans GB");
2818 _label->setSystemFontSize(20);
2819 _label->enableOutline(Color4B::RED, 1.0);
2820 _label->setString(
"This is a very\n 我爱你中国\n long sentence");
2823 auto stepper = (ControlStepper*)this->getChildByName(
"stepper");
2824 stepper->setEnabled(
true);
2826 auto checkbox = (CheckBox*)(this->getChildByName(
"toggleType"));
2827 checkbox->setEnabled(
false);
2831 auto slider1 = (ui::Slider*)this->getChildByTag(1);
2833 auto winSize = Director::getInstance()->getVisibleSize();
2834 slider1->addEventListener([=](Ref* ref, Slider::EventType event){
2835 float percent = slider1->getPercent();
2836 auto drawNodeSize = Size(percent / 100.0 * winSize.width,
_label->getContentSize().height);
2837 if(drawNodeSize.height <= 0){
2838 drawNodeSize.height = 0.1f;
2840 _label->setDimensions(drawNodeSize.width, drawNodeSize.height);
2845 auto label = Label::createWithSystemFont(
"char Line break:",
"Arial", 10);
2846 label->setColor(Color3B::WHITE);
2847 label->setPosition(Vec2(winSize.width * 0.1f, winSize.height * 0.8f));
2848 this->addChild(label);
2850 CheckBox* checkBox = CheckBox::create(
"cocosui/check_box_normal.png",
2851 "cocosui/check_box_normal_press.png",
2852 "cocosui/check_box_active.png",
2853 "cocosui/check_box_normal_disable.png",
2854 "cocosui/check_box_active_disable.png");
2855 checkBox->setPosition(Vec2(winSize.width * 0.2f , winSize.height * 0.8f));
2856 checkBox->setScale(0.5);
2857 checkBox->setSelected(
false);
2858 checkBox->setName(
"LineBreak");
2860 checkBox->addEventListener([=](Ref* ref, CheckBox::EventType event){
2861 if (event == CheckBox::EventType::SELECTED) {
2862 _label->setLineBreakWithoutSpace(
true);
2864 _label->setLineBreakWithoutSpace(
false);
2868 this->addChild(checkBox);
2872 auto checkboxToggleWrap = (CheckBox*)(this->getChildByName(
"toggleWrap"));
2873 checkboxToggleWrap->setEnabled(
true);
2880 Size winSize = Director::getInstance()->getVisibleSize();
2883 auto radioButtonGroup = RadioButtonGroup::create();
2884 this->addChild(radioButtonGroup);
2887 static const int NUMBER_OF_BUTTONS = 4;
2889 std::vector<std::string> labelTypes = {
"Normal",
"Clamp",
"Shrink",
"RESIZE"};
2891 for(
int i = 0; i < NUMBER_OF_BUTTONS; ++i)
2894 RadioButton* radioButton = RadioButton::create(
"cocosui/radio_button_off.png",
"cocosui/radio_button_on.png");
2896 radioButton->setPosition(Vec2(posX, winSize.height / 2.0f + 70));
2897 radioButton->setScale(1.2f);
2899 radioButton->setTag(i);
2900 radioButtonGroup->addRadioButton(radioButton);
2901 this->addChild(radioButton);
2903 auto label = Label::createWithSystemFont(labelTypes.at(i),
"Arial", 20);
2904 label->setPosition(radioButton->getPosition() + Vec2(50.0f,0.0f));
2905 this->addChild(label);
2911 return "System Font Test";
2922 if(radioButton ==
nullptr)
2929 case RadioButton::EventType::SELECTED:
2931 switch (radioButton->getTag()) {
2933 _label->setOverflow(Label::Overflow::NONE);
2936 _label->setOverflow(Label::Overflow::CLAMP);
2939 _label->setOverflow(Label::Overflow::SHRINK);
2942 _label->setOverflow(Label::Overflow::RESIZE_HEIGHT);
2957 _label->setLineSpacing(5);
2958 _label->setVerticalAlignment(TextVAlignment::CENTER);
2959 _label->setOverflow(Label::Overflow::NONE);
2960 _label->setCharMap(
"fonts/tuffy_bold_italic-charmap.plist");
2961 _label->setString(
"Hello World, This is a char map test.");
2964 auto stepper = (ControlStepper*)this->getChildByName(
"stepper");
2965 stepper->setEnabled(
true);
2967 auto checkbox = (CheckBox*)(this->getChildByName(
"toggleType"));
2968 checkbox->setEnabled(
false);
2977 return "CharMap Font Test";
2989 auto label = Label::createWithTTF(
"12345",
"fonts/arial.ttf", 26);
2990 label->setPosition(center);
2993 label->getLetter(2)->setVisible(
false);
2998 return "Test for Issue #13846";
3003 return "Test hide label's letter,the label should display '12 45' as expected";
3013 auto richText2 = RichText::createWithXML(
"Mixing <b>UIRichText</b> with non <i>UIWidget</i> code. For more samples, see the UIRichTextTest.cpp file");
3016 richText2->ignoreContentAdaptWithSize(
false);
3017 richText2->setContentSize(Size(400.0f, 400.0f));
3018 richText2->setPosition(center);
3020 addChild(richText2);
3031 return "Testing RichText";
3036 auto s = Director::getInstance()->getWinSize();
3039 auto label1 = Label::createWithBMFont(
"fonts/bitmapFontTest2.fnt",
"hello non-italics", TextHAlignment::CENTER, s.width);
3041 label1->setPosition(Vec2(s.width/2, s.height*4/6));
3044 _label1a = Label::createWithBMFont(
"fonts/bitmapFontTest2.fnt",
"hello italics", TextHAlignment::CENTER, s.width);
3046 _label1a->setPosition(Vec2(s.width/2, s.height*3/6));
3052 TTFConfig ttfConfig(
"fonts/arial.ttf",24);
3053 auto label2 = Label::createWithTTF(ttfConfig,
"hello non-italics", TextHAlignment::CENTER,s.width);
3055 label2->setPosition(Vec2(s.width/2, s.height*2/6));
3058 ttfConfig.italics =
true;
3059 _label2a = Label::createWithTTF(ttfConfig,
"hello italics", TextHAlignment::CENTER,s.width);
3061 _label2a->setPosition(Vec2(s.width/2, s.height*1/6));
3063 auto menuItem = MenuItemFont::create(
"disable italics", [&](cocos2d::Ref* sender) {
3064 _label2a->disableEffect(LabelEffect::ITALICS);
3065 _label1a->disableEffect(LabelEffect::ITALICS);
3067 menuItem->setFontSizeObj(12);
3068 auto menu = Menu::createWithItem(menuItem);
3070 auto winSize = Director::getInstance()->getWinSize();
3071 menu->setPosition(winSize.width * 0.9, winSize.height * 0.25f);
3076 return "Testing Italics";
3081 return "italics on TTF and BMfont";
3088 auto s = Director::getInstance()->getWinSize();
3091 auto label1 = Label::createWithBMFont(
"fonts/bitmapFontTest2.fnt",
"hello non-bold", TextHAlignment::CENTER, s.width);
3093 label1->setPosition(Vec2(s.width/2, s.height*4/6));
3096 _label1a = Label::createWithBMFont(
"fonts/bitmapFontTest2.fnt",
"hello bold", TextHAlignment::CENTER, s.width);
3098 _label1a->setPosition(Vec2(s.width/2, s.height*3/6));
3104 TTFConfig ttfConfig(
"fonts/arial.ttf",24);
3105 auto label2 = Label::createWithTTF(ttfConfig,
"hello non-bold", TextHAlignment::CENTER,s.width);
3107 label2->setPosition(Vec2(s.width/2, s.height*2/6));
3110 ttfConfig.bold =
true;
3111 _label2a = Label::createWithTTF(ttfConfig,
"hello bold", TextHAlignment::CENTER,s.width);
3113 _label2a->setPosition(Vec2(s.width/2, s.height*1/6));
3115 auto menuItem = MenuItemFont::create(
"disable bold", [&](cocos2d::Ref* sender) {
3116 _label2a->disableEffect(LabelEffect::BOLD);
3117 _label1a->disableEffect(LabelEffect::BOLD);
3119 menuItem->setFontSizeObj(12);
3120 auto menu = Menu::createWithItem(menuItem);
3122 auto winSize = Director::getInstance()->getWinSize();
3123 menu->setPosition(winSize.width * 0.9, winSize.height * 0.25f);
3128 return "Testing Bold";
3133 return "Bold on TTF and BMfont";
3140 auto s = Director::getInstance()->getWinSize();
3143 auto label1 = Label::createWithBMFont(
"fonts/bitmapFontTest2.fnt",
"hello non-underline", TextHAlignment::CENTER, s.width);
3145 label1->setPosition(Vec2(s.width/2, s.height*4/6));
3148 _label1a = Label::createWithBMFont(
"fonts/bitmapFontTest2.fnt",
"hello underline", TextHAlignment::CENTER, s.width);
3150 _label1a->setPosition(Vec2(s.width/2, s.height*3/6));
3156 TTFConfig ttfConfig(
"fonts/arial.ttf",24);
3157 auto label2 = Label::createWithTTF(ttfConfig,
"hello non-underline", TextHAlignment::CENTER,s.width);
3159 label2->setPosition(Vec2(s.width/2, s.height*2/6));
3162 ttfConfig.underline =
true;
3163 _label2a = Label::createWithTTF(ttfConfig,
"hello underline", TextHAlignment::CENTER,s.width);
3165 _label2a->setPosition(Vec2(s.width/2, s.height*1/6));
3167 auto menuItem = MenuItemFont::create(
"disable underline", [&](cocos2d::Ref* sender) {
3168 _label2a->disableEffect(LabelEffect::UNDERLINE);
3169 _label1a->disableEffect(LabelEffect::UNDERLINE);
3171 menuItem->setFontSizeObj(12);
3172 auto menu = Menu::createWithItem(menuItem);
3174 auto winSize = Director::getInstance()->getWinSize();
3175 menu->setPosition(winSize.width * 0.9, winSize.height * 0.25f);
3180 return "Testing Underline";
3185 return "Underline on TTF and BMfont";
3192 auto s = Director::getInstance()->getWinSize();
3195 _label1a = Label::createWithBMFont(
"fonts/bitmapFontTest5.fnt",
"hello underline\nand multiline", TextHAlignment::CENTER, s.width);
3197 _label1a->setPosition(Vec2(s.width/2, s.height*2/3));
3202 TTFConfig ttfConfig(
"fonts/arial.ttf",24);
3203 ttfConfig.underline =
true;
3204 _label2a = Label::createWithTTF(ttfConfig,
"hello\nunderline\nwith multiline", TextHAlignment::LEFT, s.width);
3206 _label2a->setPosition(Vec2(s.width/2, s.height*1/3));
3208 auto menuItem = MenuItemFont::create(
"disable underline", [&](cocos2d::Ref* sender) {
3209 _label2a->disableEffect(LabelEffect::UNDERLINE);
3210 _label1a->disableEffect(LabelEffect::UNDERLINE);
3212 menuItem->setFontSizeObj(12);
3213 auto menu = Menu::createWithItem(menuItem);
3215 auto winSize = Director::getInstance()->getWinSize();
3216 menu->setPosition(winSize.width * 0.9, winSize.height * 0.25f);
3221 return "Testing Underline + multiline";
3226 return "Underline on TTF and BMfont with multiline";
3233 auto s = Director::getInstance()->getWinSize();
3236 _label1a = Label::createWithBMFont(
"fonts/bitmapFontTest4.fnt",
"hello strikethrough\nand multiline", TextHAlignment::LEFT, s.width);
3238 _label1a->setPosition(Vec2(s.width/2, s.height*2/3));
3243 TTFConfig ttfConfig(
"fonts/arial.ttf",24);
3244 ttfConfig.strikethrough =
true;
3245 _label2a = Label::createWithTTF(ttfConfig,
"hello\nstrikethrough\nwith multiline", TextHAlignment::RIGHT, s.width);
3247 _label2a->setPosition(Vec2(s.width/2, s.height*1/3));
3249 auto menuItem = MenuItemFont::create(
"disable underline", [&](cocos2d::Ref* sender) {
3250 _label2a->disableEffect(LabelEffect::STRIKETHROUGH);
3251 _label1a->disableEffect(LabelEffect::STRIKETHROUGH);
3253 menuItem->setFontSizeObj(12);
3254 auto menu = Menu::createWithItem(menuItem);
3256 auto winSize = Director::getInstance()->getWinSize();
3257 menu->setPosition(winSize.width * 0.9, winSize.height * 0.25f);
3262 return "Testing Strikethrough + multiline";
3267 return "Strikethrough on TTF and BMfont with multiline";
3280 Size winSize = Director::getInstance()->getVisibleSize();
3283 auto radioButtonGroup = RadioButtonGroup::create();
3284 this->addChild(radioButtonGroup);
3287 const int NUMBER_OF_BUTTONS = 3;
3289 std::vector<std::string> labelTypes = {
"English",
"Chinese",
"Japanese" };
3291 for (
int i = 0; i < NUMBER_OF_BUTTONS; ++i)
3293 RadioButton* radioButton = RadioButton::create(
"cocosui/radio_button_off.png",
"cocosui/radio_button_on.png");
3295 radioButton->setPosition(Vec2(posX, winSize.height / 2.0f + 70));
3296 radioButton->setScale(1.2f);
3298 radioButton->setTag(i);
3299 radioButtonGroup->addRadioButton(radioButton);
3300 this->addChild(radioButton);
3302 auto label = Label::createWithSystemFont(labelTypes.at(i),
"Arial", 20);
3303 label->setPosition(radioButton->getPosition() + Vec2(50.0f, 0.0f));
3304 this->addChild(label);
3309 _label1->setPosition(Vec2(winSize.width / 2, winSize.height * 1 / 3));
3311 Label * label = Label::createWithSystemFont(
"From json data :",
"Arial", 24);
3312 label->setAnchorPoint(Vec2(0.0f, 0.5f));
3314 label->setPosition(Vec2(20.0f, winSize.height * 1 / 3 + 24));
3318 _label2->setPosition(Vec2(winSize.width / 2, winSize.height * 1 / 2));
3320 label = Label::createWithSystemFont(
"From binary data :",
"Arial", 24);
3321 label->setAnchorPoint(Vec2(0.0f, 0.5f));
3323 label->setPosition(Vec2(20.0f, winSize.height * 1 / 2 + 24));
3328 return "Localization Test";
3333 return "Change language selected and see label change";
3339 if (radioButton ==
nullptr)
3346 case RadioButton::EventType::SELECTED:
3348 switch (radioButton->getTag()) {
3382 auto size = Director::getInstance()->getVisibleSize();
3385 Label* label = Label::createWithTTF(
"TTF with setColor()",
"fonts/arial.ttf", 24.0f);
3386 label->enableUnderline();
3387 label->setColor(cocos2d::Color3B::BLUE);
3388 label->setPosition(size.width/2, size.height/5*4);
3389 this->addChild(label);
3392 Label* label2 = Label::createWithSystemFont(
"System with setColor()",
"Verdana", 24.0f);
3393 label2->enableUnderline();
3394 label2->setColor(cocos2d::Color3B::BLUE);
3395 label2->setPosition(size.width/2, size.height/5*3);
3396 this->addChild(label2);
3399 Label* label3 = Label::createWithTTF(
"TTF with setTextColor()",
"fonts/arial.ttf", 24.0f);
3400 label3->enableUnderline();
3401 label3->setTextColor(Color4B::BLUE);
3402 label3->setPosition(size.width/2, size.height/5*2);
3403 this->addChild(label3);
3406 Label* label4 = Label::createWithSystemFont(
"System with setTextColor()",
"Verdana", 24.0f);
3407 label4->enableUnderline();
3408 label4->setTextColor(Color4B::BLUE);
3409 label4->setPosition(size.width/2, size.height/5*1);
3410 this->addChild(label4);
3415 return "Github Issue 15214";
3420 return "Font + underline: same color with setColor()";
3428 auto size = Director::getInstance()->getVisibleSize();
3429 Label* label = Label::createWithTTF(
"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
"fonts/arial.ttf", 12);
3430 label->setPosition(size.width/2, size.height/2);
3431 this->addChild(label);
3436 return "Github Issue 16293";
3441 return "No TextureAtlas resizes";
3449 auto size = Director::getInstance()->getVisibleSize();
3451 auto node = Node::create();
3452 addChild(node, 100);
3453 node->setPosition(size.width/2, size.height/2);
3462 node->setCascadeColorEnabled(
true);
3463 Label* label = Label::createWithTTF(
"Should be Yellow",
"fonts/arial.ttf", 12);
3464 label->setTextColor(Color4B::YELLOW);
3465 node->addChild(label);
3470 return "Github Issue 16471";
3475 return "Label should be yellow";
3483 auto bg = Sprite::create(
"cocosui/Hello.png");
3488 auto label = Label::createWithTTF(
"Hello World",
"fonts/arial.ttf", 70);
3490 label->enableOutline(Color4B(0, 255, 0, 100), 10);
3491 label->setTextColor(Color4B(0, 0, 255, 100));
3496 auto label = Label::createWithTTF(
"Hello World",
"fonts/arial.ttf", 70);
3498 label->enableOutline(Color4B(0, 255, 0, 100), 10);
3499 label->setTextColor(Color4B(0, 255, 0, 100));
3506 return "Github Issue 16717";
3520 auto size = Director::getInstance()->getWinSize();
3522 auto label1 = Label::createWithTTF(
"test \ntest",
"fonts/FingerpopGap.ttf", 30);
3523 label1->setPosition(Vec2(size.width / 3, size.height / 2));
3526 auto label2 = Label::createWithSystemFont(
"test \ntest",
"fonts/FingerpopGap.ttf", 30);
3527 label2->setPosition(Vec2(size.width / 3 * 1.8 , size.height / 2));
3533 return "Label line gap issue";
3538 return "two label must have exactly the same position and distance between lines";
3548 auto label = Label::createWithTTF(
"abcdefg\nhijklmn",
"fonts/arial.ttf", 26);
3549 label->setLineHeight(40);
3550 label->setPosition(center);
3558 FontAtlasCache::purgeCachedData();
3563 return "Github Issue 17902";
3577 auto label = Label::createWithTTF(
"",
"fonts/arial.ttf", 24);
3578 label->setPosition(center.x, center.y);
3581 label->setString(
"1\n2\n3");
3584 label->setString(
"abcd\ne");
3588 return "Test for letter colors";
3592 return "Should not crash!";
3596 int n = label->getStringLength();
3597 for (
int i = 0; i < n; ++i) {
3598 Sprite* letter = label->getLetter(i);
3599 if (letter !=
nullptr)
3600 letter->setColor(color);
#define ADD_TEST_CASE(__className__)
#define LineBreaksExample
#define LongSentencesExample
BitmapFontMultiLineAlignmentNew
static float menuItemPaddingCenter
static float alignmentItemPadding
virtual std::string title() const override
LabelAdditionalKerningTest()
virtual std::string subtitle() const override
void sliderEvent(cocos2d::Ref *sender, cocos2d::ui::Slider::EventType type)
virtual std::string title() const override
void setAlignmentTop(cocos2d::Ref *sender)
void setAlignmentRight(cocos2d::Ref *sender)
void setAlignmentLeft(cocos2d::Ref *sender)
virtual std::string subtitle() const override
void setAlignmentCenter(cocos2d::Ref *sender)
void setAlignmentMiddle(cocos2d::Ref *sender)
void setAlignmentBottom(cocos2d::Ref *sender)
virtual std::string title() const override
cocos2d::Label * _label2a
virtual std::string title() const override
virtual std::string subtitle() const override
cocos2d::Label * _label1a
virtual std::string title() const override
void actionFinishCallback()
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void step(float dt)
LabelFNTColorAndOpacity()
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
cocos2d::MenuItemFont * _lastAlignmentItem
void alignmentChanged(cocos2d::Ref *sender)
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
void selectSentenceItem(cocos2d::MenuItemFont *item)
cocos2d::Sprite * _arrowsBar
void stringChanged(cocos2d::Ref *sender)
cocos2d::Sprite * _arrows
virtual std::string subtitle() const override
void selectAlignmentItem(cocos2d::MenuItemFont *item)
virtual bool init() override
cocos2d::MenuItemFont * _lastSentenceItem
void onTouchesEnded(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
std::vector< cocos2d::MenuItemFont * > _menuItems
virtual std::string title() const override
void onTouchesBegan(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual std::string getItemString(cocos2d::MenuItemFont *item)
virtual std::string getItemString(cocos2d::MenuItemFont *item) override
virtual std::string subtitle() const override
bool init() override
LabelFNTMultiLineAlignmentUNICODE
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual void step(float dt)
virtual std::string title() const override
virtual std::string subtitle() const override
LabelFNTUNICODELanguages()
BMFontUnicodeNew
virtual std::string title() const override
virtual std::string title() const override
void updateStrings(float dt)
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual void purgeCachedData()
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
cocos2d::Label * _label1a
cocos2d::Label * _label2a
void setAlignmentMiddle(cocos2d::Ref *sender)
void initFontSizeChange(const cocos2d::Size &size)
void initTestLabel(const cocos2d::Size &size)
void initSliders(const cocos2d::Size &size)
void initWrapOption(const cocos2d::Size &size)
void initDrawNode(const cocos2d::Size &size)
void setAlignmentBottom(cocos2d::Ref *sender)
void initToggleLabelTypeOption(const cocos2d::Size &size)
void updateDrawNodeSize(const cocos2d::Size &drawNodeSize)
cocos2d::extension::ControlStepper * makeControlStepper()
void setAlignmentTop(cocos2d::Ref *sender)
void setAlignmentLeft(cocos2d::Ref *sender)
void setAlignmentRight(cocos2d::Ref *sender)
void setAlignmentCenter(cocos2d::Ref *sender)
void initAlignmentOption(const cocos2d::Size &size)
cocos2d::DrawNode * _drawNode
void valueChanged(cocos2d::Ref *sender, cocos2d::extension::Control::EventType controlEvent)
virtual std::string subtitle() const override
virtual std::string title() const override
static void setLetterColors(cocos2d::Label *label, const cocos2d::Color3B &color)
virtual std::string title() const override
void sliderEvent(cocos2d::Ref *sender, cocos2d::ui::Slider::EventType type)
virtual std::string subtitle() const override
cocostudio::ILocalizationManager * _localizationBin
virtual std::string title() const override
virtual std::string subtitle() const override
void onChangedRadioButtonSelect(cocos2d::ui::RadioButton *radioButton, cocos2d::ui::RadioButton::EventType type)
cocostudio::ILocalizationManager * _localizationJson
virtual std::string title() const override
LabelMultilineWithOutline()
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
LabelOutlineAndGlowTest()
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
cocos2d::Label * shadowLabelGrow
void sliderEvent(cocos2d::Ref *sender, cocos2d::ui::Slider::EventType type)
cocos2d::Label * shadowLabelOutline
cocos2d::Label * shadowLabelTTF
virtual void onEnter() override
cocos2d::Label * shadowLabelBMFont
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
LabelSmallDimensionsTest()
virtual std::string title() const override
cocos2d::Label * _label2a
virtual std::string subtitle() const override
cocos2d::Label * _label1a
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
void initToggleCheckboxes()
virtual std::string subtitle() const override
void onChangedRadioButtonSelect(cocos2d::ui::RadioButton *radioButton, cocos2d::ui::RadioButton::EventType type)
virtual std::string subtitle() const override
LabelTTFCJKWrappingTest()
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
LabelTTFDynamicAlignment()
virtual std::string subtitle() const override
virtual std::string title() const override
cocos2d::TextHAlignment _horizAlign
void setAlignmentCenter(cocos2d::Ref *sender)
void setAlignmentLeft(cocos2d::Ref *sender)
void setAlignmentRight(cocos2d::Ref *sender)
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
LabelTTFLongLineWrapping()
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
void initToggleCheckboxes()
void onChangedRadioButtonSelect(cocos2d::ui::RadioButton *radioButton, cocos2d::ui::RadioButton::EventType type)
virtual std::string title() const override
virtual std::string subtitle() const override
cocos2d::Label * _label2a
cocos2d::Label * _label1a
virtual std::string subtitle() const override
virtual std::string title() const override
cocos2d::Label * _label2a
cocos2d::Label * _label1a
virtual std::string title() const override
LabelUnderlineMultiline()
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
LabelWrapNoBreakSpaceTest()
virtual std::string subtitle() const override
virtual void onEnter() override
cocos2d::Label * _subtitleLabel
static cocos2d::Vec2 center()
static cocos2d::Vec2 rightTop()
static cocos2d::Vec2 leftBottom()