How do you wrap a ui::RichText inside a ListView?

How do you wrap a ui::RichText inside a ListView?
0

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::Texts, 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?

The reason this doesn’t work with a Listview is that a RichText’s contentsize is hardcoded to use whatever you do with it it, when you disable ‘ignoreContentAdaptWithSize’, so the Listview thinks the content size is 0. Likewise there isn’t any bounds handling, like there is when you set text dimensions, so with a height of 0, the rest of the text is rendered in negative space.