Trying to add a ui::RichText
to a ui::ListView*
, but it doesn’t resize itself according to the listview. The following sizes it properly in the middle of a layer in a scene:
std::string xml = "<font color='#FF0000'>red</font> no red anymore <font color='#00FF00'>some <a href='http://google.com'>link</a>other color</font>";
auto rich_txt = cocos2d::ui::RichText::create();
rich_txt->setNormalizedPosition({0.5, 0.5});
top_most_layer_in_scene->addChild(rich_txt);
rich_txt->setDefaults({});
rich_txt->setFontFace("fonts/Coda-Regular.ttf");
rich_txt->setWrapMode(cocos2d::ui::RichText::WrapMode::WRAP_PER_WORD);
rich_txt->setFontColor("#000000");
rich_txt->setFontSize(48);
rich_txt->initWithXML(xml);
rich_txt->setContentSize({100, 0});
rich_txt->ignoreContentAdaptWithSize(false);
but if I add it to a ListView instead of another child in the scene, my_listview->addChild(rich_txt);
the sizing gets all messed up.
For regular ui::Text
s, this works after I call text->setTextAreaSize
, which calls its label renderers’ setDimensions, but since RichText doesn’t have setDimensions
, I’m in a tough spot here.
Has anyone had luck with properly wrapping RichTexts inside of a ListView?