converting text + font + size into screen width in pixels

has anyone written a function that looks like this:

1
2
3
4
5
6
function getTextWidth(text, font, size)
  -- do some math
  -- figure out how much screen real estate required for the text obj
  -- in pixels
  return howWideThisTextObjWouldBe
end

with the new Daily Build, which you can get your hands on, you do not have to bother, you can just set the width and the textObject will wrap the text in the object and make it multi-line.

otherwise you can always use

local text = display.newText(...)
print(text.contentWidth)

cheers,

?:)

I just found that new feature after posting this. However, I can't see any way to set the alignment to anything other than left justified. Am I missing an option??

views:1665 update:2011/10/19 14:58:09
corona forums © 2003-2011