2013-07-14 07:58:39 +02:00
|
|
|
local wibox = require("wibox")
|
2013-07-15 06:33:43 +02:00
|
|
|
local beautiful = require("beautiful")
|
2013-07-21 10:15:56 +02:00
|
|
|
local color = require("gears.color")
|
2013-07-14 07:58:39 +02:00
|
|
|
local ipairs = ipairs
|
|
|
|
|
2015-12-29 11:19:23 +01:00
|
|
|
local function textbox_draw(self, context, cr, width, height)
|
2013-07-21 10:15:56 +02:00
|
|
|
cr:save()
|
|
|
|
cr:set_source(color(beautiful.menu_border_color or beautiful.border_normal or beautiful.border_color))
|
2013-07-15 06:33:43 +02:00
|
|
|
cr:rectangle(0,0,width,1)
|
|
|
|
cr:rectangle(width-1,0,1,height)
|
|
|
|
cr:stroke()
|
2013-07-21 10:15:56 +02:00
|
|
|
cr:restore()
|
|
|
|
cr:set_source(color(beautiful.menu_fg_normal or beautiful.fg_normal))
|
2015-12-29 11:19:23 +01:00
|
|
|
wibox.widget.textbox.draw(self, context, cr, width, height)
|
2013-07-15 06:33:43 +02:00
|
|
|
end
|
|
|
|
|
2016-06-24 22:53:47 +02:00
|
|
|
local function create_textbox(col_c,col,has_v_header,row_height)
|
2013-07-15 06:33:43 +02:00
|
|
|
local t = wibox.widget.textbox()
|
2014-03-22 22:03:04 +01:00
|
|
|
|
2015-12-29 11:19:23 +01:00
|
|
|
t.fit = function(s,context,w2,h)
|
2016-06-24 22:53:47 +02:00
|
|
|
local _,fh = wibox.widget.textbox.fit(s,context,w2,h)
|
2014-03-22 22:03:04 +01:00
|
|
|
return (w2/(col_c+2 - col)),row_height or fh
|
2013-07-15 06:33:43 +02:00
|
|
|
end
|
|
|
|
t.draw = textbox_draw
|
2013-07-21 10:15:56 +02:00
|
|
|
t:set_align("center")
|
2013-07-15 06:33:43 +02:00
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
2016-06-24 22:53:47 +02:00
|
|
|
local function create_h_header(main_l,cols,args)
|
2013-07-15 06:33:43 +02:00
|
|
|
if args.h_header then
|
2016-06-24 06:46:41 +02:00
|
|
|
local bg = wibox.container.background()
|
2013-07-15 06:33:43 +02:00
|
|
|
local row_l = wibox.layout.fixed.horizontal()
|
2014-11-23 06:32:13 +01:00
|
|
|
bg:set_bg(beautiful.menu_table_bg_header or beautiful.menu_bg_header or beautiful.fg_normal)
|
2013-07-15 06:33:43 +02:00
|
|
|
bg:set_widget(row_l)
|
|
|
|
if args.v_header then
|
2016-06-24 22:53:47 +02:00
|
|
|
local t = create_textbox(cols,1,args.v_header ~= nil,args.row_height)
|
2013-07-15 06:33:43 +02:00
|
|
|
t:set_markup("<span color='".. beautiful.bg_normal .."'>--</span>")
|
|
|
|
row_l:add(t)
|
|
|
|
end
|
|
|
|
for i=1,cols do
|
2016-06-24 22:53:47 +02:00
|
|
|
local t = create_textbox(cols,i+1,args.v_header ~= nil,args.row_height)
|
2013-07-15 06:33:43 +02:00
|
|
|
t:set_markup("<span color='".. beautiful.bg_normal .."'>".. (args.h_header[i] or "-") .."</span>")
|
|
|
|
row_l:add(t)
|
|
|
|
end
|
|
|
|
main_l:add(bg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function new(content,args)
|
2016-06-24 22:53:47 +02:00
|
|
|
args = args or {}
|
2013-07-14 07:58:39 +02:00
|
|
|
local cols = 0
|
2016-12-26 03:52:39 +01:00
|
|
|
local row_count = args.row_count or #content
|
|
|
|
|
2013-07-14 07:58:39 +02:00
|
|
|
for k,v in ipairs(content) do
|
|
|
|
if #v > cols then
|
|
|
|
cols = #v
|
|
|
|
end
|
|
|
|
end
|
2016-12-26 03:52:39 +01:00
|
|
|
|
|
|
|
local col_count = math.max(args.column_count or 0, cols)
|
|
|
|
|
2013-07-14 07:58:39 +02:00
|
|
|
local main_l = wibox.layout.fixed.vertical()
|
2016-06-24 22:53:47 +02:00
|
|
|
|
2015-12-29 11:19:23 +01:00
|
|
|
main_l.fit = function(self,context,width,height)
|
|
|
|
return wibox.layout.fixed.fit(self,context,width,height)
|
2013-07-14 07:58:39 +02:00
|
|
|
end
|
2016-06-24 22:53:47 +02:00
|
|
|
|
|
|
|
create_h_header(main_l,cols,args)
|
2014-03-22 22:03:04 +01:00
|
|
|
|
2013-07-21 10:15:56 +02:00
|
|
|
local j,widgets =1,{}
|
2013-07-14 07:58:39 +02:00
|
|
|
for k,v in ipairs(content) do
|
2013-07-21 10:15:56 +02:00
|
|
|
local row_l,row_w = wibox.layout.fixed.horizontal(),{}
|
2013-07-15 06:33:43 +02:00
|
|
|
if args.v_header then
|
2016-06-24 22:53:47 +02:00
|
|
|
local t = create_textbox(cols,1,args.v_header ~= nil,args.row_height)
|
2013-07-15 06:33:43 +02:00
|
|
|
t:set_markup("<span color='".. beautiful.bg_normal .."'>".. (args.v_header[j] or "-") .."</span>")
|
2016-06-24 06:46:41 +02:00
|
|
|
local bg = wibox.container.background()
|
2014-11-23 06:32:13 +01:00
|
|
|
bg:set_bg(beautiful.menu_table_bg_header or beautiful.menu_bg_header or beautiful.fg_normal)
|
2013-07-15 06:33:43 +02:00
|
|
|
bg:set_widget(t)
|
|
|
|
row_l:add(bg)
|
|
|
|
end
|
2013-07-14 07:58:39 +02:00
|
|
|
for i=1,cols do
|
2016-06-24 22:53:47 +02:00
|
|
|
local t = create_textbox(cols,i+1,args.v_header ~= nil,args.row_height)
|
2013-07-14 07:58:39 +02:00
|
|
|
t:set_text(v[i])
|
|
|
|
row_l:add(t)
|
2013-07-21 10:15:56 +02:00
|
|
|
row_w[#row_w+1] =t
|
2013-07-14 07:58:39 +02:00
|
|
|
end
|
|
|
|
main_l:add(row_l)
|
2013-07-21 10:15:56 +02:00
|
|
|
widgets[#widgets+1] = row_w
|
2013-07-15 06:33:43 +02:00
|
|
|
j = j +1
|
2013-07-14 07:58:39 +02:00
|
|
|
end
|
2013-07-21 10:15:56 +02:00
|
|
|
return main_l,widgets
|
2013-07-14 07:58:39 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable({}, { __call = function(_, ...) return new(...) end })
|
2016-12-26 03:52:39 +01:00
|
|
|
-- kate: space-indent on; indent-width 4; replace-tabs on;
|