Hi Dev!
Can you please tip me about this issue? RichText control does not return the actual content size. this is my code:
void GameLayer::initRichText()
{
auto visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
Point posCenter = Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y);
auto contents = FileUtils::getInstance()->getStringFromFile(“text/news.txt”);
auto text = cocos2d::ui::RichText::create();
const auto font = std::string(“fonts/Marker Felt.ttf”);
text->setPosition(posCenter);
text->ignoreContentAdaptWithSize(false);
text->setContentSize(Size(visibleSize.width0.8, 0.f));
text->pushBackElement(ui::RichElementText::create(0, Color3B::BLUE, 0xFF, contents, font, 32));
ui::RichElement pElement = ui::RichElementText::create(0, Color3B::GREEN, 0xFF, "I listened to the radio.\nWaiting for my favorite song ", font, 32);
text->pushBackElement(pElement);
this->addChild(text);
text->formatText();
Size textSize = text->getVirtualRendererSize();
DrawNode* pNode = DrawNode::create();
pNode->drawRect(Point::ZERO, Point(textSize), Color4F::BLACK);
text->addChild(pNode);
}
Unfortunately when you set ignoreContentAdaptWithSize(false) the controls does not change its contentSize after formatting the text, even if it splits the text into multiple lines. Hence there is a problem to position other widgets on the scene correctly. The problem has been addressed several times sin the web, yet nothing seems to have changed.