TableView widget with variable row height

Is it possible to have a table view widget with variable row height?
In my case table rows are filled with arbitrarily long text, so I need to adjust the row height.
I could not find any tip about it in the forum.

Thanks [import]uid: 3778 topic_id: 25937 reply_id: 325937[/import]

If you’re using widget.newTableView(), then yes, you can set variable row height. In fact, that’s how it works by default (assuming you’re using the .722+ daily builds)

If you look closely at how the sample code works, the category rows (such as the one on the API page that says “Row #25” is actually just another row. It’s just set to be:
a. Shorter
b. A different color
c. Not be clickable
d. “isCategory = true”, which basically gives it that sorting property that causes it to “stick” to the top of the view if you scroll too far down.

[code]-- Create 100 rows, and two categories to the tableView:
for i=1,100 do
local rowHeight, rowColor, lineColor, isCategory

– make the 25th item a category
if i == 25 then
isCategory = true; rowHeight = 24; rowColor={ 70, 70, 130, 255 }; lineColor={0,0,0,255}
end

– make the 45th item a category as well
if i == 45 then
isCategory = true; rowHeight = 24; rowColor={ 70, 70, 130, 255 }; lineColor={0,0,0,255}
end

– function below is responsible for creating the row
list:insertRow{
onEvent=onRowTouch,
onRender=onRowRender,
height=rowHeight,
isCategory=isCategory,
rowColor=rowColor,
lineColor=lineColor
}
end[/code]

This is some of the sample code clipped right out of the API page. “rowHeight = x” is literally how you do it. The trick is that you set it here, in the row iterator stage, and not on the render stage. [import]uid: 41884 topic_id: 25937 reply_id: 104999[/import]

Thanks Richard for your help!

As you point out the row height is set when the table widget is created and rows are inserted, but the needed height is known only on the render stage, when I create variable height multi-line text objects.

The only workaround I’ve found is to create a temporary text object before the insertRow, just to know it’s height, and then remove it.
I’ll create again the text object on the render stage to be added to the row group.

Is there a better solution?
Thanks [import]uid: 3778 topic_id: 25937 reply_id: 105048[/import]

That’s a pretty safe idea; you can always create, measure, remove and then nil the text object.

The only other solutions I can think of are:

-Pre-measure: Do exactly what you have done but build a function to do so ahead of time, either at app startup (if possible) or before creating the list. Probably of little advantage unless your list is really big, though.

-Character measurement: If you can figure out the number of characters and some basic width + font information it might be possible to measure that way. You’d have to fudge it a bit if it’s not a fixed width font though, and it may be even more performance intensive than what you’re already doing. [import]uid: 41884 topic_id: 25937 reply_id: 105286[/import]