radical/widgets/separator.lua

39 lines
1.1 KiB
Lua
Raw Normal View History

2014-01-05 00:51:07 +01:00
local setmetatable = setmetatable
local print = print
local color = require( "gears.color")
local cairo = require( "lgi" ).cairo
local wibox = require( "wibox" )
local beautiful = require( "beautiful" )
2014-03-12 05:31:50 +01:00
local module = {HORIZONTAL=1,VERTICAL=2}
2014-01-05 00:51:07 +01:00
local function draw(self, w, cr, width, height)
cr:save()
cr:set_source(self._color)
2014-03-12 05:31:50 +01:00
if self.direction == module.VERTICAL then
cr:rectangle(2,2,1,height-4)
else
cr:rectangle(5,2,width-10,1)
end
2014-01-05 00:51:07 +01:00
cr:fill()
cr:restore()
end
local function fit(box, w, h)
local direction = box.direction or w > h and module.HORIZONTAL or module.VERTICAL
return direction == module.VERTICAL and 5 or w,direction == module.VERTICAL and h or 5
2014-01-05 00:51:07 +01:00
end
2014-03-12 05:31:50 +01:00
local function new(menu,direction)
2014-01-05 00:51:07 +01:00
local bg = wibox.widget.base.make_widget()
2014-03-12 05:31:50 +01:00
bg.direction = direction or module.HORIZONTAL
2014-01-05 00:51:07 +01:00
bg.fit = fit
bg._color = color( menu and menu.separator_color or beautiful.border_color or beautiful.fg_normal)
bg.draw = draw
bg._force_fit = true
return bg
end
2014-03-12 05:31:50 +01:00
return setmetatable(module, { __call = function(_, ...) return new(...) end })
2014-01-05 00:51:07 +01:00
-- kate: space-indent on; indent-width 2; replace-tabs on;