2013-05-11 21:02:42 +02:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
local color = require( "gears.color" )
|
|
|
|
local cairo = require( "lgi" ).cairo
|
2013-07-07 06:39:17 +02:00
|
|
|
local beautiful = require( "beautiful" )
|
2013-05-11 21:02:42 +02:00
|
|
|
local print = print
|
|
|
|
|
|
|
|
local module = {
|
|
|
|
margins = {
|
|
|
|
TOP = 2,
|
|
|
|
BOTTOM = 2,
|
|
|
|
RIGHT = 0,
|
|
|
|
LEFT = 4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-07 06:39:17 +02:00
|
|
|
local focussed,default,alt = nil, nil,nil
|
2013-05-11 21:02:42 +02:00
|
|
|
|
|
|
|
local function gen(item_height,bg_color,border_color)
|
|
|
|
local img = cairo.ImageSurface(cairo.Format.ARGB32, 800,item_height)
|
|
|
|
local cr = cairo.Context(img)
|
|
|
|
cr:set_source( color(bg_color) )
|
|
|
|
cr:paint()
|
|
|
|
cr:set_source( color(border_color) )
|
|
|
|
cr:rectangle(0,item_height-1,800,1)
|
|
|
|
cr:fill()
|
|
|
|
return cairo.Pattern.create_for_surface(img)
|
|
|
|
end
|
|
|
|
|
2013-07-07 06:39:17 +02:00
|
|
|
local function draw(data,item,is_focussed,is_pressed,is_alt)
|
2013-05-11 21:02:42 +02:00
|
|
|
local ih = data.item_height
|
|
|
|
if not focussed or not focussed[ih] then
|
|
|
|
if not focussed then
|
2013-07-07 06:39:17 +02:00
|
|
|
focussed,default,alt={},{},{}
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
local bc = data.border_color
|
|
|
|
focussed[ih] = gen(ih,data.bg_focus,bc)
|
|
|
|
default [ih] = gen(ih,data.bg,bc)
|
2013-07-07 06:39:17 +02:00
|
|
|
alt [ih] = gen(ih,beautiful.bg_highlight,bc)
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if is_focussed then
|
|
|
|
item.widget:set_bg(focussed[ih])
|
2013-07-07 06:39:17 +02:00
|
|
|
elseif is_alt then
|
|
|
|
item.widget:set_bg(alt[ih])
|
2013-05-11 21:02:42 +02:00
|
|
|
else
|
2013-07-07 06:39:17 +02:00
|
|
|
item.widget:set_bg(default[ih])
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return draw(...) end })
|
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|