2014-02-02 23:21:59 +01:00
|
|
|
local setmetatable = setmetatable
|
2014-02-16 20:46:10 +01:00
|
|
|
local beautiful = require( "beautiful" )
|
|
|
|
local color = require( "gears.color" )
|
|
|
|
local cairo = require( "lgi" ).cairo
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
local checkbox = require( "radical.widgets.checkbox" )
|
|
|
|
local fkey = require( "radical.widgets.fkey" )
|
2014-02-23 05:59:03 +01:00
|
|
|
local horizontal = require( "radical.item.layout.horizontal" )
|
2014-02-02 23:21:59 +01:00
|
|
|
|
|
|
|
local module = {}
|
|
|
|
|
|
|
|
local function icon_fit(data,...)
|
|
|
|
local w,h = wibox.widget.imagebox.fit(...)
|
2014-07-28 01:20:04 +02:00
|
|
|
--Try to retermine the limiting factor
|
|
|
|
if data._internal.layout.dir == "y" then
|
|
|
|
return data.icon_size or w,data.icon_size or h
|
|
|
|
else
|
|
|
|
return w,data.icon_size or h
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local function icon_draw(self,w, cr, width, height)
|
|
|
|
local w,h = wibox.widget.imagebox.fit(self,width,height)
|
|
|
|
cr:save()
|
|
|
|
cr:translate((width-w)/2,0)
|
|
|
|
wibox.widget.imagebox.draw(self,w, cr, width, height)
|
|
|
|
cr:restore()
|
2014-02-02 23:21:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function create_item(item,data,args)
|
2014-02-16 20:46:10 +01:00
|
|
|
--Create the background
|
2014-02-02 23:21:59 +01:00
|
|
|
local bg = wibox.widget.background()
|
|
|
|
bg:set_fg(item._private_data.fg)
|
|
|
|
|
|
|
|
--Create the main item layout
|
|
|
|
local l,la,lr = wibox.layout.fixed.vertical(),wibox.layout.align.vertical(),wibox.layout.fixed.horizontal()
|
|
|
|
local m = wibox.layout.margin(la)
|
|
|
|
m:set_margins (0)
|
|
|
|
m:set_left ( data.item_style.margins.LEFT )
|
|
|
|
m:set_right ( data.item_style.margins.RIGHT )
|
|
|
|
m:set_top ( data.item_style.margins.TOP )
|
|
|
|
m:set_bottom( data.item_style.margins.BOTTOM )
|
|
|
|
local text_w = wibox.widget.textbox()
|
|
|
|
text_w:set_align("center")
|
|
|
|
item._private_data._fit = wibox.widget.background.fit
|
2014-07-28 01:20:04 +02:00
|
|
|
-- m.fit = function(...)
|
|
|
|
-- if item.visible == false or item._filter_out == true then
|
|
|
|
-- return 0,0
|
|
|
|
-- end
|
|
|
|
-- local w,h = data._internal.layout.item_fit(data,item,...)
|
|
|
|
-- print("item_fit",w,h)
|
|
|
|
-- return data._internal.layout.item_fit(data,item,...)
|
|
|
|
-- end
|
2014-02-02 23:21:59 +01:00
|
|
|
|
|
|
|
if data.fkeys_prefix == true then
|
|
|
|
local pref = wibox.widget.textbox()
|
|
|
|
pref.draw = function(self,w, cr, width, height)
|
|
|
|
cr:set_source(color(beautiful.fg_normal))
|
|
|
|
cr:paint()
|
|
|
|
wibox.widget.textbox.draw(self,w, cr, width, height)
|
|
|
|
end
|
|
|
|
l:add(pref)
|
|
|
|
m:set_left ( 0 )
|
|
|
|
end
|
|
|
|
|
|
|
|
if args.prefix_widget then
|
|
|
|
l:add(args.prefix_widget)
|
|
|
|
end
|
|
|
|
|
2014-08-08 08:02:37 +02:00
|
|
|
local icon = horizontal.setup_icon(horizontal,item,data)
|
2014-02-02 23:21:59 +01:00
|
|
|
icon.fit = function(...) return icon_fit(data,...) end
|
2014-07-28 01:20:04 +02:00
|
|
|
icon.draw = icon_draw
|
|
|
|
|
|
|
|
l:add(icon)
|
2014-02-02 23:21:59 +01:00
|
|
|
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
|
|
|
|
subArrow.fit = function(box, w, h) return subArrow._image:get_width(),item.height end
|
|
|
|
subArrow:set_image( beautiful.menu_submenu_icon )
|
|
|
|
lr:add(subArrow)
|
2014-07-28 01:20:04 +02:00
|
|
|
end
|
|
|
|
bg.fit = function(box,w,h,...)
|
|
|
|
-- args.y = data.height-h-data.margins.top --TODO dead code?
|
|
|
|
return data._internal.layout.item_fit(data,item,box,w,h)
|
2014-02-02 23:21:59 +01:00
|
|
|
end
|
|
|
|
if item.checkable then
|
2014-03-05 06:12:48 +01:00
|
|
|
item.get_checked = function()
|
2014-02-02 23:21:59 +01:00
|
|
|
if type(item._private_data.checked) == "function" then
|
|
|
|
return item._private_data.checked()
|
|
|
|
else
|
|
|
|
return item._private_data.checked
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local ck = wibox.widget.imagebox()
|
|
|
|
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
|
|
|
|
lr:add(ck)
|
2014-03-05 06:12:48 +01:00
|
|
|
item.set_checked = function (_,value)
|
2014-02-02 23:21:59 +01:00
|
|
|
item._private_data.checked = value
|
|
|
|
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if args.suffix_widget then
|
|
|
|
lr:add(args.suffix_widget)
|
|
|
|
end
|
|
|
|
la:set_top(l)
|
|
|
|
la:set_bottom(lr)
|
|
|
|
bg:set_widget(m)
|
|
|
|
|
|
|
|
item._internal.text_w = text_w
|
|
|
|
item._internal.icon_w = icon
|
2014-02-16 03:57:07 +01:00
|
|
|
|
2014-02-16 20:46:10 +01:00
|
|
|
-- Setup events
|
|
|
|
horizontal.setup_event(data,item,bg)
|
2014-02-16 03:57:07 +01:00
|
|
|
|
2014-02-02 23:21:59 +01:00
|
|
|
return bg
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return create_item(...) end })
|
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|