Add menu 'auto_resize' option for vertical menus
This commit is contained in:
parent
70c27a360c
commit
9dc5137d92
2
base.lua
2
base.lua
|
@ -16,7 +16,7 @@ local module = {
|
|||
CENTERED = 2,
|
||||
}}
|
||||
|
||||
function filter(data)
|
||||
local function filter(data)
|
||||
local fs,visible_counter = data.filter_string:lower(),0
|
||||
for k,v in pairs(data.items) do
|
||||
local tmp = v[1]._filter_out
|
||||
|
|
|
@ -142,7 +142,8 @@ local function setup_drawable(data)
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
local function new(args)
|
||||
|
|
|
@ -132,7 +132,6 @@ function module:setup_item(data,item,args)
|
|||
icon:set_image(args.icon)
|
||||
end
|
||||
l:add(icon)
|
||||
text_w:set_markup(item._private_data.text)
|
||||
l:add(text_w)
|
||||
if item._private_data.sub_menu_f or item._private_data.sub_menu_m then
|
||||
local subArrow = wibox.widget.imagebox() --TODO, make global
|
||||
|
@ -172,10 +171,24 @@ function module:setup_item(data,item,args)
|
|||
data.style(data)
|
||||
item._internal.set_map.text = function (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
|
||||
item._internal.set_map.icon = function (value)
|
||||
icon:set_image(value)
|
||||
end
|
||||
item._internal.set_map.text(item._private_data.text)
|
||||
end
|
||||
|
||||
local function new(data)
|
||||
|
@ -202,8 +215,12 @@ local function new(data)
|
|||
real_l.fit = function(a1,a2,a3)
|
||||
local result,r2 = wibox.layout.fixed.fit(a1,99999,99999)
|
||||
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)
|
||||
end
|
||||
end
|
||||
real_l.add = function(real_l,item)
|
||||
return wibox.layout.fixed.add(l,item.widget)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue