Add a basic table widget

This commit is contained in:
Emmanuel Lepage Vallee 2013-07-14 01:58:39 -04:00
parent e8027779dc
commit 5f37caab7f
2 changed files with 37 additions and 0 deletions

View File

@ -3,4 +3,5 @@ return {
scroll = require( "radical.widgets.scroll" ),
filter = require( "radical.widgets.filter" ),
fkey = require( "radical.widgets.fkey" ),
table = require( "radical.wigdets.table" ),
}

36
widgets/table.lua Normal file
View File

@ -0,0 +1,36 @@
local wibox = require("wibox")
local ipairs = ipairs
local print = print
local function new(content)
local rows = #content
local cols = 0
for k,v in ipairs(content) do
if #v > cols then
cols = #v
end
end
local main_l = wibox.layout.fixed.vertical()
local w =200
main_l.fit = function(self,width,height)
w = width
return wibox.layout.fixed.fit(self,width,height)
end
for k,v in ipairs(content) do
local row_l = wibox.layout.fixed.horizontal()
for i=1,cols do
local t = wibox.widget.textbox()
t.fit = function(...)
local fw,fh = wibox.widget.textbox.fit(...)
return w/4,fh
end
t:set_text(v[i])
row_l:add(t)
end
main_l:add(row_l)
end
return main_l
end
return setmetatable({}, { __call = function(_, ...) return new(...) end })
-- kate: space-indent on; indent-width 2; replace-tabs on;