Make it possible to change item text and icon dynamically

This commit is contained in:
Emmanuel Lepage Vallee 2013-06-22 22:30:27 -04:00
parent cd4d8d1dbe
commit 70c27a360c
3 changed files with 21 additions and 8 deletions

View File

@ -142,7 +142,7 @@ 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)
;(data._internal.layout.setup_item or layout.vertical.setup_item)(data._internal.layout,data,item,args);
end
local function new(args)

View File

@ -125,14 +125,15 @@ function module:setup_item(data,item,args)
l:add(args.prefix_widget)
end
local icon_flex = wibox.layout.align.horizontal()
local icon = wibox.widget.imagebox()
icon.fit = function(...) return icon_fit(data,...) end
if args.icon then
local icon_flex = wibox.layout.align.horizontal()
local icon = wibox.widget.imagebox()
icon.fit = function(...) return icon_fit(data,...) end
icon:set_image(args.icon)
icon_flex:set_middle(icon)
l:add(icon_flex)
end
icon_flex:set_middle(icon)
l:add(icon_flex)
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
@ -171,6 +172,12 @@ function module:setup_item(data,item,args)
data.width = fit_w
data.height = fit_h
data.style(data)
item._internal.set_map.text = function (value)
text_w:set_markup(value)
end
item._internal.set_map.icon = function (value)
icon:set_image(value)
end
end
--Get preferred item geometry

View File

@ -127,11 +127,11 @@ function module:setup_item(data,item,args)
l:add(args.prefix_widget)
end
local icon = wibox.widget.imagebox()
if args.icon then
local icon = wibox.widget.imagebox()
icon:set_image(args.icon)
l:add(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
@ -170,6 +170,12 @@ function module:setup_item(data,item,args)
data.width = fit_w
data.height = fit_h
data.style(data)
item._internal.set_map.text = function (value)
text_w:set_markup(value)
end
item._internal.set_map.icon = function (value)
icon:set_image(value)
end
end
local function new(data)