Multi Line Text

Hi,

So I am using the multiline functionality of display.newText and I am predefining the width and height the text image can be. Is there a way to detect if the text is too big for the predefined width and height parameters? I am trying to create something that basically shows that if the height of the predefined does not fit the entire message I want it to then show “…”  so the user knows that there is more to the message.

If anyone knows how to detect if the text is not fitting inside the parameters that would be great.

This is a piece of my code below:

local options = { text = textMessage, x = display.contentWidth/2, y = yValue, width = display.contentWidth/1.2, height = display.contentWidth/1.8, font = native.systemFontBold, fontSize = display.contentHeight/30, align = "left" -- Alignment parameter } local text = display.newText(options) text:setFillColor(1,1,1) text.y = text.y + text.height/1.7 --I am not sure what to compare the display.newText object height value to. if textMessage.height \> text.height then print("yo") end

I prefer/use obj.contentWidth and obj.contentHeight.

Anyone else have an opinion on this.

Maybe create text with height = 0 and make it autoadjust. Then compare with number value (or height of the dummy rectangle).  
 

if text.height \> 400 then print("yo") end

The only way I know to detect if you’ve overflowed the box when clamping on height is to create two display.newText() objects, one with the height set to 0, one with your clamped height and compare the difference between the two. If the one set to 0 is bigger, then you’ve overflowed the box.

Another way that might work is to create the text with 0 for the height and then have the text inside a display.newContainer that has your clamped height. That way it won’t show the excess but you can compare the height of the text object with your clamped height. Note this method involves masks and text is already masked so adding any more masks (i.e. the newContainer inside of a tableView) may hit the mask limit.

Rob

I prefer/use obj.contentWidth and obj.contentHeight.

Anyone else have an opinion on this.

Maybe create text with height = 0 and make it autoadjust. Then compare with number value (or height of the dummy rectangle).  
 

if text.height \> 400 then print("yo") end

The only way I know to detect if you’ve overflowed the box when clamping on height is to create two display.newText() objects, one with the height set to 0, one with your clamped height and compare the difference between the two. If the one set to 0 is bigger, then you’ve overflowed the box.

Another way that might work is to create the text with 0 for the height and then have the text inside a display.newContainer that has your clamped height. That way it won’t show the excess but you can compare the height of the text object with your clamped height. Note this method involves masks and text is already masked so adding any more masks (i.e. the newContainer inside of a tableView) may hit the mask limit.

Rob