From 5f37caab7f8db196eda82e16e2a84a4b919fc07c Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 14 Jul 2013 01:58:39 -0400 Subject: [PATCH] Add a basic table widget --- widgets/init.lua | 1 + widgets/table.lua | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 widgets/table.lua diff --git a/widgets/init.lua b/widgets/init.lua index 26d8f50..b4d8c78 100644 --- a/widgets/init.lua +++ b/widgets/init.lua @@ -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" ), } \ No newline at end of file diff --git a/widgets/table.lua b/widgets/table.lua new file mode 100644 index 0000000..2a08e40 --- /dev/null +++ b/widgets/table.lua @@ -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;