Fix a bug when table (widgets) are resized

This commit is contained in:
Emmanuel Lepage Vallee 2014-03-22 17:03:04 -04:00
parent 0a5f240ab1
commit 9b9c96be1b
1 changed files with 10 additions and 9 deletions

View File

@ -15,11 +15,12 @@ local function textbox_draw(self, w, cr, width, height)
wibox.widget.textbox.draw(self, w, cr, width, height) wibox.widget.textbox.draw(self, w, cr, width, height)
end end
local function create_textbox(w,col_c,has_v_header,row_height) local function create_textbox(w,col_c,col,has_v_header,row_height)
local t = wibox.widget.textbox() local t = wibox.widget.textbox()
t.fit = function(...)
local fw,fh = wibox.widget.textbox.fit(...) t.fit = function(s,w2,h)
return w/(col_c + (has_v_header and 1 or 0)),row_height or fh local fw,fh = wibox.widget.textbox.fit(s,w2,h)
return (w2/(col_c+2 - col)),row_height or fh
end end
t.draw = textbox_draw t.draw = textbox_draw
t:set_align("center") t:set_align("center")
@ -33,12 +34,12 @@ local function create_h_header(main_l,cols,w,args)
bg:set_bg(beautiful.menu_bg_header or beautiful.fg_normal) bg:set_bg(beautiful.menu_bg_header or beautiful.fg_normal)
bg:set_widget(row_l) bg:set_widget(row_l)
if args.v_header then if args.v_header then
local t = create_textbox(w,cols,args.v_header ~= nil,args.row_height) local t = create_textbox(w,cols,1,args.v_header ~= nil,args.row_height)
t:set_markup("<span color='".. beautiful.bg_normal .."'>--</span>") t:set_markup("<span color='".. beautiful.bg_normal .."'>--</span>")
row_l:add(t) row_l:add(t)
end end
for i=1,cols do for i=1,cols do
local t = create_textbox(w,cols,args.v_header ~= nil,args.row_height) local t = create_textbox(w,cols,i+1,args.v_header ~= nil,args.row_height)
t:set_markup("<span color='".. beautiful.bg_normal .."'>".. (args.h_header[i] or "-") .."</span>") t:set_markup("<span color='".. beautiful.bg_normal .."'>".. (args.h_header[i] or "-") .."</span>")
row_l:add(t) row_l:add(t)
end end
@ -62,12 +63,12 @@ local function new(content,args)
return wibox.layout.fixed.fit(self,width,height) return wibox.layout.fixed.fit(self,width,height)
end end
create_h_header(main_l,cols,w,args) create_h_header(main_l,cols,w,args)
local j,widgets =1,{} local j,widgets =1,{}
for k,v in ipairs(content) do for k,v in ipairs(content) do
local row_l,row_w = wibox.layout.fixed.horizontal(),{} local row_l,row_w = wibox.layout.fixed.horizontal(),{}
if args.v_header then if args.v_header then
local t = create_textbox(w,cols,args.v_header ~= nil,args.row_height) local t = create_textbox(w,cols,1,args.v_header ~= nil,args.row_height)
t:set_markup("<span color='".. beautiful.bg_normal .."'>".. (args.v_header[j] or "-") .."</span>") t:set_markup("<span color='".. beautiful.bg_normal .."'>".. (args.v_header[j] or "-") .."</span>")
local bg = wibox.widget.background() local bg = wibox.widget.background()
bg:set_bg(beautiful.menu_bg_header or beautiful.fg_normal) bg:set_bg(beautiful.menu_bg_header or beautiful.fg_normal)
@ -75,7 +76,7 @@ local function new(content,args)
row_l:add(bg) row_l:add(bg)
end end
for i=1,cols do for i=1,cols do
local t = create_textbox(w,cols,args.v_header ~= nil,args.row_height) local t = create_textbox(w,cols,i+1,args.v_header ~= nil,args.row_height)
t:set_text(v[i]) t:set_text(v[i])
row_l:add(t) row_l:add(t)
row_w[#row_w+1] =t row_w[#row_w+1] =t