RichText: how to get the real content size?


#1

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});
richText->ignoreContentAdaptWithSize(false);

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

scrollView->addChild(richText);

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

scrollView->setInnerContainerSize(richText->getContentSize());

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?

Thanks


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

Anyone knows this? :pensive:


#3

Did you solve this problem?


#4

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


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