Add menu 'auto_resize' option for vertical menus

This commit is contained in:
Emmanuel Lepage Vallee 2013-07-01 18:18:25 -04:00
parent 70c27a360c
commit 9dc5137d92
3 changed files with 22 additions and 4 deletions

View File

@ -16,7 +16,7 @@ local module = {
CENTERED = 2, CENTERED = 2,
}} }}
function filter(data) local function filter(data)
local fs,visible_counter = data.filter_string:lower(),0 local fs,visible_counter = data.filter_string:lower(),0
for k,v in pairs(data.items) do for k,v in pairs(data.items) do
local tmp = v[1]._filter_out local tmp = v[1]._filter_out

View File

@ -142,7 +142,8 @@ local function setup_drawable(data)
end end
local function setup_item(data,item,args) local function setup_item(data,item,args)
;(data._internal.layout.setup_item or layout.vertical.setup_item)(data._internal.layout,data,item,args); local f = (data._internal.layout.setup_item) or (layout.vertical.setup_item)
f(data._internal.layout,data,item,args)
end end
local function new(args) local function new(args)

View File

@ -132,7 +132,6 @@ function module:setup_item(data,item,args)
icon:set_image(args.icon) icon:set_image(args.icon)
end end
l:add(icon) l:add(icon)
text_w:set_markup(item._private_data.text)
l:add(text_w) l:add(text_w)
if item._private_data.sub_menu_f or item._private_data.sub_menu_m then if item._private_data.sub_menu_f or item._private_data.sub_menu_m then
local subArrow = wibox.widget.imagebox() --TODO, make global local subArrow = wibox.widget.imagebox() --TODO, make global
@ -172,10 +171,24 @@ function module:setup_item(data,item,args)
data.style(data) data.style(data)
item._internal.set_map.text = function (value) item._internal.set_map.text = function (value)
text_w:set_markup(value) text_w:set_markup(value)
if data.auto_resize then
local fit_w,fit_h = text_w:fit(999,9999)
local is_largest = item == data._internal.largest_item_w
if not data._internal.largest_item_w_v or data._internal.largest_item_w_v < fit_w then
data._internal.largest_item_w = item
data._internal.largest_item_w_v = fit_w
end
--TODO find new largest is item is smaller
-- if data._internal.largest_item_h_v < fit_h then
-- data._internal.largest_item_h =item
-- data._internal.largest_item_h_v = fit_h
-- end
end
end end
item._internal.set_map.icon = function (value) item._internal.set_map.icon = function (value)
icon:set_image(value) icon:set_image(value)
end end
item._internal.set_map.text(item._private_data.text)
end end
local function new(data) local function new(data)
@ -202,8 +215,12 @@ local function new(data)
real_l.fit = function(a1,a2,a3) real_l.fit = function(a1,a2,a3)
local result,r2 = wibox.layout.fixed.fit(a1,99999,99999) local result,r2 = wibox.layout.fixed.fit(a1,99999,99999)
local total = data._total_item_height local total = data._total_item_height
if data.auto_resize and data._internal.largest_item_w then
return data._internal.largest_item_w_v+100,(total and total > 0 and total or data.rowcount*data.item_height) + (filter_tb and data.item_height or 0)
else
return data.default_width, (total and total > 0 and total or data.rowcount*data.item_height) + (filter_tb and data.item_height or 0) return data.default_width, (total and total > 0 and total or data.rowcount*data.item_height) + (filter_tb and data.item_height or 0)
end end
end
real_l.add = function(real_l,item) real_l.add = function(real_l,item)
return wibox.layout.fixed.add(l,item.widget) return wibox.layout.fixed.add(l,item.widget)
end end