Displaying variable height rows in widget.newTableView depending on text volume

Dear All,

I am implementing a chat screen, for which I am using widget.newTableView.

However, the challenge is to vary the row height based on the text volume to be rendered. Is there a way to do that efficiently? 

 -- Create a tableView chatTable = widget.newTableView { top = display.screenOriginY + 80, left = 10, width = display.contentWidth - 20, height = display.contentHeight + display.screenOriginY - 80, onRowRender = onRowRender, onRowTouch = onRowTouch, } chatTable:insertRow{ rowHeight = 50, -- this needs to be variable? params = {....}, }

In function onRowRender, we do have rowTitle.height and row.contentHeight but isn’t it too late and the row is already rendered?

Any help will be much appreciated!

Cheers,

Anshuman

I don’t think there is any good way to do this. You need to create your text object to check the height. You can then pass it into the rowrender as a param in insertRow for example.

hi Jon, I am doing that (rendering the display object somewhere outside the screen, getting the height and removing that object and using the height in the insertRow), but was wondering if there is something in the config. 

Thanks for your reply.

You can get a rough estimate of the height by doing a character count.  You know the width that you will use for a display.newText() so ti will wrap.  If you are using a 12 point font for instance, could use 12 as a base width (I know it’s a height, but on average with the spacing between letters, it’s a good approximation of the width too). 

rowHeight = math.ceil(string.len(mytext) * fontSize / desiredTextWidth) * (fontSize * 1.1)

should give you an approximation.  Of course  string filled with W’s and Ms or a string filled with I’s and j’s will be off.  You may need to tweak the fontSize * 1.1 based on the real line spacing in use.  Likewise the fontSize in the middle might need to be multiplied by 1.1 or 0.9 depending or more depending on the font metrics. 

I don’t think there is any good way to do this. You need to create your text object to check the height. You can then pass it into the rowrender as a param in insertRow for example.

hi Jon, I am doing that (rendering the display object somewhere outside the screen, getting the height and removing that object and using the height in the insertRow), but was wondering if there is something in the config. 

Thanks for your reply.

You can get a rough estimate of the height by doing a character count.  You know the width that you will use for a display.newText() so ti will wrap.  If you are using a 12 point font for instance, could use 12 as a base width (I know it’s a height, but on average with the spacing between letters, it’s a good approximation of the width too). 

rowHeight = math.ceil(string.len(mytext) * fontSize / desiredTextWidth) * (fontSize * 1.1)

should give you an approximation.  Of course  string filled with W’s and Ms or a string filled with I’s and j’s will be off.  You may need to tweak the fontSize * 1.1 based on the real line spacing in use.  Likewise the fontSize in the middle might need to be multiplied by 1.1 or 0.9 depending or more depending on the font metrics.