RichText: how to get the real content size?


Hi guys :smile:

Iā€™m using RichText class to put some text inside a ScrollView Instance.
I need to set the RichText width in order to split text in multiple lines.
To do that I did:

RichText* richText = RichText::create();
richText->setContentSize({720, 0});

Then I added multiple RichElementText objects.
Finally I added richText inside my scrollView


Because the RichText is bigger than my scrollView I need to set scrollView InnerContainerSize:


Here comes the problem:
The richText content size height is 0, and was not updated after I added the RichElementTextobjects!

I tried also:

auto cs   = richText->getContentSize();
auto bbcs = richText->getBoundingBox().size;
auto vrs  = richText->getVirtualRendererSize();

All return the contentSize I set: {720, 0}.
How can I get real richText height?


Rich Text or Label for text-wrapping & how to calculate Height?

Anyone knows this? :pensive:


Did you solve this problem?


@anhtuan89 Sadly no! :weary:
You have to put a RichText instance inside a parent container like in my case?

RichText *richText = RichText::createWithXML(xml);
richText->formatText(); //force calculation of content size
Size s = richText->getContentSize();  //use it