2014-01-13 06:46:33 +01:00
|
|
|
local setmetatable = setmetatable
|
2014-01-23 05:58:50 +01:00
|
|
|
local base = require( "radical.base" )
|
|
|
|
local beautiful = require("beautiful" )
|
|
|
|
local color = require("gears.color" )
|
|
|
|
local cairo = require("lgi" ).cairo
|
|
|
|
local wibox = require("wibox" )
|
2014-02-23 05:59:03 +01:00
|
|
|
local arrow_alt = require("radical.item.style.arrow_alt")
|
2014-01-13 06:46:33 +01:00
|
|
|
|
|
|
|
local module = {
|
|
|
|
margins = {
|
2014-01-16 06:25:50 +01:00
|
|
|
TOP = 0,
|
|
|
|
BOTTOM = 0,
|
2014-01-23 05:58:50 +01:00
|
|
|
RIGHT = 0,
|
|
|
|
LEFT = 0
|
2014-01-13 06:46:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local function prefix_draw(self, w, cr, width, height)
|
|
|
|
cr:save()
|
2014-02-03 05:01:31 +01:00
|
|
|
local col = self._item.bg_prefix or beautiful.icon_grad or beautiful.fg_normal
|
|
|
|
cr:set_source(color(col))
|
2014-01-23 05:58:50 +01:00
|
|
|
cr:rectangle(0,0,width-height/2-2-height/6,height)
|
2014-01-13 06:46:33 +01:00
|
|
|
cr:fill()
|
2014-02-03 05:01:31 +01:00
|
|
|
cr:set_source_surface(arrow_alt.get_beg_arrow({width=height/2+2,height=height,bg_color=col}),width-height/2-2 - height/6,0)
|
2014-01-23 05:58:50 +01:00
|
|
|
cr:paint()
|
2014-01-13 06:46:33 +01:00
|
|
|
cr:restore()
|
|
|
|
self._draw(self, w, cr, width, height)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function prefix_fit(box,w,h)
|
|
|
|
local width,height = box._fit(box,w,h)
|
2014-01-23 05:58:50 +01:00
|
|
|
return width + h/2 + h/6,height
|
|
|
|
end
|
|
|
|
|
|
|
|
local function suffix_draw(self, w, cr, width, height)
|
|
|
|
cr:save()
|
2014-02-03 05:01:31 +01:00
|
|
|
cr:set_source_surface(arrow_alt.get_end_arrow({width=height/2+2,height=height,bg_color=self._item.bg_prefix or beautiful.icon_grad or beautiful.fg_normal}),width-height/2-2,0)
|
2014-01-23 05:58:50 +01:00
|
|
|
cr:paint()
|
|
|
|
cr:restore()
|
|
|
|
self._draw(self, w, cr, width, height)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function suffix_fit(box,w,h)
|
|
|
|
local width,height = box._fit(box,w,h)
|
|
|
|
return width + h/2 + h/6,height
|
2014-01-13 06:46:33 +01:00
|
|
|
end
|
|
|
|
|
2014-02-15 05:35:53 +01:00
|
|
|
local function widget_draw(self, w, cr, width, height)
|
2014-02-16 20:46:10 +01:00
|
|
|
self:_drawprefix(w, cr, width, height)
|
2014-02-15 05:35:53 +01:00
|
|
|
local overlay = self._item and self._item.overlay
|
|
|
|
if overlay then
|
|
|
|
overlay(self._item._menu,self._item,cr,width,height)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-13 06:46:33 +01:00
|
|
|
local function draw(data,item,args)
|
2014-02-21 04:29:40 +01:00
|
|
|
local args = args or {}
|
2014-01-13 06:46:33 +01:00
|
|
|
|
2014-02-15 05:35:53 +01:00
|
|
|
if not item.widget._overlay_init then
|
2014-02-16 20:46:10 +01:00
|
|
|
item.widget._drawprefix = item.widget.draw
|
2014-02-15 05:35:53 +01:00
|
|
|
item.widget.draw = widget_draw
|
|
|
|
item.widget._overlay_init = true
|
|
|
|
end
|
|
|
|
|
2014-01-13 06:46:33 +01:00
|
|
|
if not item._internal.align._setup then
|
|
|
|
item._internal.align._setup = true
|
2014-01-23 05:58:50 +01:00
|
|
|
|
|
|
|
-- Replace prefix function
|
2014-02-03 05:01:31 +01:00
|
|
|
item._internal.align.first._item = item
|
2014-01-13 06:46:33 +01:00
|
|
|
item._internal.align.first._fit = item._internal.align.first.fit
|
|
|
|
item._internal.align.first._draw = item._internal.align.first.draw
|
|
|
|
item._internal.align.first.fit = prefix_fit
|
|
|
|
item._internal.align.first.draw = prefix_draw
|
2014-01-23 05:58:50 +01:00
|
|
|
|
|
|
|
-- Replace suffix function
|
2014-02-03 05:01:31 +01:00
|
|
|
item._internal.align.third._item = item
|
2014-01-23 05:58:50 +01:00
|
|
|
item._internal.align.third._fit = item._internal.align.third.fit
|
|
|
|
item._internal.align.third._draw = item._internal.align.third.draw
|
|
|
|
item._internal.align.third.fit = suffix_fit
|
|
|
|
item._internal.align.third.draw = suffix_draw
|
2014-01-13 06:46:33 +01:00
|
|
|
end
|
|
|
|
|
2014-02-21 04:29:40 +01:00
|
|
|
local state = item.state or {}
|
2014-02-22 04:22:13 +01:00
|
|
|
local current_state = state._current_key or nil
|
|
|
|
local state_name = base.colors_by_id[current_state]
|
2014-02-21 04:29:40 +01:00
|
|
|
|
2014-02-22 04:22:13 +01:00
|
|
|
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
2014-01-13 06:46:33 +01:00
|
|
|
item.widget:set_bg(args.color or data.bg_focus)
|
2014-02-22 04:22:13 +01:00
|
|
|
elseif state_name then
|
|
|
|
item.widget:set_bg(args.color or item["bg_"..state_name] or data["bg_"..state_name])
|
2014-01-13 06:46:33 +01:00
|
|
|
else
|
|
|
|
item.widget:set_bg(args.color or nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return draw(...) end })
|
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|