Multiline text objects return the wrong height just after creation

I’ve encountered a problem when I tried to rely on a text object height to position elements in the UI.

Strangely enough when I ask a multiline text object for its contentHeight I get the height for a single line. If I ask again after a short timer, I get the correct value.

 local pLabel = { text=text, --long text x=x, y=y, width = w, align = align or "left", font=fontName, fontSize=fontSize, } local label = display.newEmbossedText(pLabel) label.anchorX = 0.0 parent:insert(label) print("Label", text, w, label.contentHeight) timer.performWithDelay(10, function() print("Label2", text, w, label.contentHeight) end)

The code above illustrates the issue quite well. Does the text object manipulates itself to multiple lines using some delay so its height is not updated on its creation? I did not see this issue before.

The parameter width defines the maximum width for multiline text - Corona auto-wraps at that width.

When I run this code I get 236 as the height for both outputs. If I run with after truncating the text at the end of “wrong” I get 96 for both heights.

local pLabel = { text="some text and stuff is going wrong\nbut i don't care cos nah nah blah blah\ni'm a blooby coo coo", --long text x=200, y=200, width = 400, align = align or "left", fontSize=40, } local label = display.newEmbossedText(pLabel) print("Label", label.height) timer.performWithDelay(1000, function() print("Label2", label.height) end)

Hi, My bad. found the problem. In between the print calls, Another method modified the text value which changed the results. Please ignore.

The parameter width defines the maximum width for multiline text - Corona auto-wraps at that width.

When I run this code I get 236 as the height for both outputs. If I run with after truncating the text at the end of “wrong” I get 96 for both heights.

local pLabel = { text="some text and stuff is going wrong\nbut i don't care cos nah nah blah blah\ni'm a blooby coo coo", --long text x=200, y=200, width = 400, align = align or "left", fontSize=40, } local label = display.newEmbossedText(pLabel) print("Label", label.height) timer.performWithDelay(1000, function() print("Label2", label.height) end)

Hi, My bad. found the problem. In between the print calls, Another method modified the text value which changed the results. Please ignore.