[Solved] RichText getContentSize() return (0, 0)

On web calling getContentSize() of a RichText object returns the right value, but in the JSB it always give (0, 0).

If any one have the same trouble, the rigth way to get RichText content size is:

richText.ignoreContentAdaptWithSize (true); // the content size will grow with its elements

// add your elements with richText.pushBackElement (someElement)

richText.formatText (); // force recalculate the content size
var contentSize = richText.getVirtualRendererSize (); // The content size

1 Like

Hi El_Jorge! do you get real size of richText with richText.getVirtualRendererSize ()??? can’t you help me?

var richText = new ccui.RichText();
richText.ignoreContentAdaptWithSize(false);
richText.setContentSize(cc.size(500, 100));
richText.pushBackElement(retext); // 10 time
richText.getVirtualRendererSize();

I want get real size of richText after push some element, but it return {width: 500, height: 100}, not a real size! please help me!

call formatText and set ignoreContentAdaptWithSize (true) look above

2 Likes

Thank for you help EI-Jorge! i did but when set ignoreContentAdaptWithSize(true) my richtext isn’t wordwarp and still get real height!
so I want to show a bubble chat contain text and icon chat, which control should i use to show?
Thank a lot!

the ignoreContentAdaptWithSize(false) will fit any text in the content size so it makes sence that the VirtualRendererSize is {width: 500, height: 100};

if i understand what you are trying to do:

var richText = new ccui.RichText();
// richText.setContentSize(cc.size(500, 100)); // do not set the content size
richText.ignoreContentAdaptWithSize(true); // set this to true to ignore the content size since is not seted
richText.pushBackElement(retext); // 10 time

var contentSize = richText.getVirtualRendererSize();
// now try to fit in the text in the bubble chat
var scale = Math.min(500/contentSize.width, 100/contentSize.height);
richText.setScale (scale, scale); // fit the contents by the smaller scale thus showing all text