-- render a square table (array of arrays) nicely
-- t contains a list of row/col names in key 'rows'
draw_table = function(t)
love.graphics.setLineWidth(3)
local f, c, py = 36, 50, 5 -- font size, cell side, padding
local namepx = 5
love.graphics.setFont(love.graphics.newFont(f))
local rside = max_row_width(t) + namepx*2 -- width of name column
local hrow = total_row_width(t) + namepx*2*#t
local width = rside + hrow
local height = (#t+1)*c
local top, left = 30,30
local cx = column_xs(t, left+rside, namepx) -- right margin of each column
-- border
love.graphics.rectangle('line', left,top, width,height, 5,5)
do
-- first column for names
local hx = left+rside
love.graphics.line(hx, top, hx, top+height)
-- remaining columns
for i=1,#cx-1 do
love.graphics.line(cx[i], top, cx[i], top+height)
end
end
-- rows
for i=1,#t do
love.graphics.line(left, top+i*c, left+width, top+i*c)
end
-- print out row headings
for i,name in ipairs(t.rows) do
love.graphics.print(name, left+namepx, top+i*c+py)
end
-- print out column headings
local l = left+rside
for i=1,#t do
local r = cx[i]
local w = r-l
local px = (w - App.width(t.rows[i])) / 2 -- x padding
love.graphics.print(t.rows[i], l+px, top+py)
l = r
end
-- print out cells
l = left+rside
for x,row in ipairs(t) do
for y,cell in ipairs(row) do
local px = (cx[x] - l - App.width(t[x][y])) / 2
love.graphics.print(t[x][y], l+px, top+y*c+py)
end
l = cx[x]
end
end