#include "UIRichTextTest.h" #include "editor-support/cocostudio/CCArmatureDataManager.h" #include "editor-support/cocostudio/CCArmature.h" USING_NS_CC; using namespace cocos2d::ui; UIRichTextTests::UIRichTextTests() { ADD_TEST_CASE(UIRichTextTest); ADD_TEST_CASE(UIRichTextXMLBasic); ADD_TEST_CASE(UIRichTextXMLSmallBig); ADD_TEST_CASE(UIRichTextXMLColor); ADD_TEST_CASE(UIRichTextXMLSUIB); ADD_TEST_CASE(UIRichTextXMLSUIB2); ADD_TEST_CASE(UIRichTextXMLSUIB3); ADD_TEST_CASE(UIRichTextXMLImg); ADD_TEST_CASE(UIRichTextXMLUrl); ADD_TEST_CASE(UIRichTextXMLUrlImg); ADD_TEST_CASE(UIRichTextXMLFace); ADD_TEST_CASE(UIRichTextXMLBR); ADD_TEST_CASE(UIRichTextXMLInvalid); ADD_TEST_CASE(UIRichTextXMLOutline); ADD_TEST_CASE(UIRichTextXMLShadow); ADD_TEST_CASE(UIRichTextXMLGlow); ADD_TEST_CASE(UIRichTextXMLExtend); } // // UIRichTextTest // bool UIRichTextTest::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); auto config = Configuration::getInstance(); config->loadConfigFile("configs/config-test-ok.plist"); std::string str1 = config->getValue("Chinese").asString(); std::string str2 = config->getValue("Japanese").asString(); CCLOG("str1:%s ascii length = %ld, utf8 length = %ld, substr = %s", str1.c_str(), static_cast(str1.length()), StringUtils::getCharacterCountInUTF8String(str1), Helper::getSubStringOfUTF8String(str1, 0, 5).c_str()); CCLOG("str2:%s ascii length = %ld, utf8 length = %ld, substr = %s", str2.c_str(), static_cast(str2.length()), StringUtils::getCharacterCountInUTF8String(str2), Helper::getSubStringOfUTF8String(str2, 0, 2).c_str()); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextTest::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::create(); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); RichElementText* re1 = RichElementText::create(1, Color3B::WHITE, 255, str1, "SimSun", 10); RichElementText* re2 = RichElementText::create(2, Color3B::YELLOW, 255, "And this is yellow. ", "Helvetica", 10); RichElementText* re3 = RichElementText::create(3, Color3B::GRAY, 255, str2, "Yu Mincho", 10); RichElementText* re4 = RichElementText::create(4, Color3B::GREEN, 255, "And green with TTF support. ", "fonts/Marker Felt.ttf", 10); RichElementText* re5 = RichElementText::create(5, Color3B::RED, 255, "Last one is red ", "Helvetica", 10); RichElementImage* reimg = RichElementImage::create(6, Color3B::WHITE, 255, "cocosui/sliderballnormal.png"); cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("cocosui/100/100.ExportJson"); cocostudio::Armature *pAr = cocostudio::Armature::create("100"); pAr->getAnimation()->play("Animation1"); RichElementCustomNode* recustom = RichElementCustomNode::create(1, Color3B::WHITE, 255, pAr); RichElementText* re6 = RichElementText::create(7, Color3B::ORANGE, 255, "Have fun!! ", "Helvetica", 10); _richText->pushBackElement(re1); _richText->insertElement(re2, 1); _richText->pushBackElement(re3); _richText->pushBackElement(re4); _richText->pushBackElement(re5); _richText->insertElement(reimg, 2); _richText->pushBackElement(recustom); _richText->pushBackElement(re6); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextTest::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextTest::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLBasic // bool UIRichTextXMLBasic::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBasic::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBasic::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("This is just a simple text. no xml tags here. testing the basics. testing word-wrapping. testing, testing, testing"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLBasic::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLBasic::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLSmallBig // bool UIRichTextXMLSmallBig::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSmallBig::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSmallBig::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("Regular size.smaller size.bigger.normal.bigger.normal."); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLSmallBig::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLSmallBig::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLColor // bool UIRichTextXMLColor::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLColor::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLColor::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("Defaul color.red.greenred again.default again"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLColor::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLColor::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLSUIB // bool UIRichTextXMLSUIB::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("system font: underlineitalicsboldstrike-through"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLSUIB::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLSUIB::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLSUIB2 // bool UIRichTextXMLSUIB2::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB2::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB2::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("ttf font: underlineitalicsboldstrike-through"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLSUIB2::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLSUIB2::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLSUIB3 // bool UIRichTextXMLSUIB3::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB3::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLSUIB3::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("ttf font: italics and underlinebold and strike-through"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLSUIB3::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLSUIB3::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLImg // bool UIRichTextXMLImg::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLImg::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLImg::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("you should see an image here: and this is text again. and this is the same image, but bigger: and here goes text again"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLImg::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLImg::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLUrl // bool UIRichTextXMLUrl::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrl::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrl::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("And this link will redirect you to google: click me"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLUrl::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLUrl::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLUrlImg // bool UIRichTextXMLUrlImg::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrlImg::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLUrlImg::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("And this link will redirect you to google: "); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLUrlImg::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLUrlImg::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLFace // bool UIRichTextXMLFace::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLFace::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLFace::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("Marker Felt 20.Arial 20.Thonburi 24 blue"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLFace::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLFace::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLBR // bool UIRichTextXMLBR::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBR::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLBR::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("this is one line.
this should be in another line.
and this is another line"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLBR::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLBR::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLInvalid // bool UIRichTextXMLInvalid::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("Invalid XML test", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); // RichText _richText = RichText::createWithXML("this is an invalid xml. no closing tag"); if (_richText) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); } return true; } return false; } // // UIRichTextXMLOutline // bool UIRichTextXMLOutline::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("Outline", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLOutline::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLOutline::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("OUTLINE"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLOutline::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLOutline::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLShadow // bool UIRichTextXMLShadow::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("Shadow", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLShadow::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLShadow::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("SHADOW"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLShadow::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLShadow::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLGlow // bool UIRichTextXMLGlow::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("Glow", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLGlow::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLGlow::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); // RichText _richText = RichText::createWithXML("GLOW"); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLGlow::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLGlow::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } } // // UIRichTextXMLExtend // bool UIRichTextXMLExtend::init() { if (UIScene::init()) { Size widgetSize = _widget->getContentSize(); // Add the alert Text *alert = Text::create("Extend", "fonts/Marker Felt.ttf", 30); alert->setColor(Color3B(159, 168, 176)); alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.125)); _widget->addChild(alert); Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button->setTouchEnabled(true); button->setTitleText("switch"); button->setPosition(Vec2(widgetSize.width * 1 / 3, widgetSize.height / 2.0f + button->getContentSize().height * 2.5)); button->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLExtend::touchEvent, this)); button->setLocalZOrder(10); _widget->addChild(button); Button* button2 = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); button2->setTouchEnabled(true); button2->setTitleText("wrap mode"); button2->setPosition(Vec2(widgetSize.width * 2 / 3, widgetSize.height / 2.0f + button2->getContentSize().height * 2.5)); button2->addTouchEventListener(CC_CALLBACK_2(UIRichTextXMLExtend::switchWrapMode, this)); button2->setLocalZOrder(10); _widget->addChild(button2); /* Tag extension */ RichText::setTagDescription("CloseNormal", false, [](const ValueMap& tagAttrValueMap) { RichElementImage* richElement = RichElementImage::create(0, Color3B::WHITE, 255, "cocosui/CloseNormal.png"); return make_pair(ValueMap(), richElement); }); RichText::setTagDescription("CloseSelected", false, [](const ValueMap& tagAttrValueMap) { RichElementImage* richElement = RichElementImage::create(0, Color3B::WHITE, 255, "cocosui/CloseSelected.png"); return make_pair(ValueMap(), richElement); }); /* Defaults */ ValueMap defaults; defaults[RichText::KEY_FONT_COLOR_STRING] = "#FFF"; defaults[RichText::KEY_FONT_SIZE] = 12.0f; defaults[RichText::KEY_FONT_FACE] = "fonts/Marker Felt.ttf"; defaults[RichText::KEY_ANCHOR_FONT_COLOR_STRING] = "#f0f8ff"; defaults[RichText::KEY_ANCHOR_TEXT_BOLD] = false; defaults[RichText::KEY_ANCHOR_TEXT_ITALIC] = false; //defaults[RichText::KEY_ANCHOR_TEXT_LINE] = RichText::VALUE_TEXT_LINE_NONE; //defaults[RichText::KEY_ANCHOR_TEXT_LINE] = RichText::VALUE_TEXT_LINE_DEL; defaults[RichText::KEY_ANCHOR_TEXT_LINE] = RichText::VALUE_TEXT_LINE_UNDER; //defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_NONE; //defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_OUTLINE; //defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_SHADOW; //defaults[RichText::KEY_ANCHOR_TEXT_STYLE] = RichText::VALUE_TEXT_STYLE_GLOW; defaults[RichText::KEY_ANCHOR_TEXT_OUTLINE_COLOR] = "#D2B48C"; defaults[RichText::KEY_ANCHOR_TEXT_OUTLINE_SIZE] = 4; defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_COLOR] = "#4169E1"; defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_OFFSET_WIDTH] = 4.0f; defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_OFFSET_HEIGHT] = -4.0f; defaults[RichText::KEY_ANCHOR_TEXT_SHADOW_BLUR_RADIUS] = 0; defaults[RichText::KEY_ANCHOR_TEXT_GLOW_COLOR] = "#AFEEEE"; // RichText _richText = RichText::createWithXML("CloseNormal-tag:


CloseSelected-tag:
", defaults, [](const std::string& url) { Application::getInstance()->openURL(url); }); _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); _richText->setPosition(Vec2(widgetSize.width / 2, widgetSize.height / 2)); _richText->setLocalZOrder(10); _widget->addChild(_richText); // test remove all children, this call won't effect the test _richText->removeAllChildren(); return true; } return false; } void UIRichTextXMLExtend::touchEvent(Ref *pSender, Widget::TouchEventType type) { switch (type) { case Widget::TouchEventType::ENDED: { if (_richText->isIgnoreContentAdaptWithSize()) { _richText->ignoreContentAdaptWithSize(false); _richText->setContentSize(Size(100, 100)); } else { _richText->ignoreContentAdaptWithSize(true); } } break; default: break; } } void UIRichTextXMLExtend::switchWrapMode(Ref *pSender, Widget::TouchEventType type) { if (type == Widget::TouchEventType::ENDED) { auto wrapMode = _richText->getWrapMode(); wrapMode = (wrapMode == RichText::WRAP_PER_WORD) ? RichText::WRAP_PER_CHAR : RichText::WRAP_PER_WORD; _richText->setWrapMode(wrapMode); } }