2014-02-02 23:21:59 +01:00
|
|
|
local setmetatable = setmetatable
|
2016-02-28 08:04:51 +01:00
|
|
|
local beautiful = require( "beautiful" )
|
|
|
|
local color = require( "gears.color" )
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
local checkbox = require( "radical.widgets.checkbox" )
|
|
|
|
local util = require( "awful.util" )
|
|
|
|
local margins2 = require( "radical.margins" )
|
2016-03-05 08:14:24 +01:00
|
|
|
local common = require( "radical.item.common" )
|
2014-02-02 23:21:59 +01:00
|
|
|
|
|
|
|
local module = {}
|
|
|
|
|
2016-03-05 08:14:24 +01:00
|
|
|
local function after_draw_children(self, context, cr, width, height)
|
2016-06-24 06:46:41 +02:00
|
|
|
wibox.container.background.after_draw_children(self, context, cr, width, height)
|
2016-03-05 08:14:24 +01:00
|
|
|
--TODO get rid of this, use the stack container
|
|
|
|
if self._item.overlay_draw then
|
|
|
|
self._item.overlay_draw(context,self._item,cr,width,height)
|
|
|
|
end
|
|
|
|
end
|
2016-01-12 09:33:38 +01:00
|
|
|
|
2016-03-05 08:14:24 +01:00
|
|
|
local function icon_fit(data,...)
|
|
|
|
local w,h = wibox.widget.imagebox.fit(...)
|
|
|
|
--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
|
2016-01-12 09:33:38 +01:00
|
|
|
end
|
|
|
|
|
2015-12-29 11:19:23 +01:00
|
|
|
local function icon_draw(self, context, cr, width, height)
|
2016-06-24 22:53:47 +02:00
|
|
|
local w = wibox.widget.imagebox.fit(self,context,width,height)
|
2016-03-05 08:14:24 +01:00
|
|
|
cr:save()
|
|
|
|
cr:translate((width-w)/2,0)
|
|
|
|
wibox.widget.imagebox.draw(self, context, cr, width, height)
|
|
|
|
cr:restore()
|
2014-02-02 23:21:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function create_item(item,data,args)
|
2016-06-24 22:53:47 +02:00
|
|
|
local pref, subArrow, ck = nil, nil, nil
|
|
|
|
|
2016-02-12 05:25:03 +01:00
|
|
|
if data.fkeys_prefix == true then
|
2016-06-24 22:53:47 +02:00
|
|
|
pref = wibox.widget.textbox()
|
2014-02-02 23:21:59 +01:00
|
|
|
|
2016-02-12 05:25:03 +01:00
|
|
|
function pref:draw(context, cr, width, height)
|
|
|
|
cr:set_source(color(beautiful.fg_normal))
|
|
|
|
cr:paint()
|
|
|
|
wibox.widget.textbox.draw(self, context, cr, width, height)
|
|
|
|
end
|
2014-02-02 23:21:59 +01:00
|
|
|
end
|
|
|
|
|
2016-03-05 08:14:24 +01:00
|
|
|
local icon = common.setup_icon(item,data)
|
2016-02-12 05:25:03 +01:00
|
|
|
icon.fit = function(...) return icon_fit(data,...) end
|
|
|
|
icon.draw = icon_draw
|
|
|
|
|
|
|
|
local has_children = item._private_data.sub_menu_f or item._private_data.sub_menu_m
|
|
|
|
|
|
|
|
if has_children then
|
2016-06-24 22:53:47 +02:00
|
|
|
subArrow = wibox.widget.imagebox() --TODO, make global
|
2014-02-16 03:57:07 +01:00
|
|
|
|
2016-02-12 05:25:03 +01:00
|
|
|
function subArrow:fit(context, w, h)
|
|
|
|
return subArrow._image:get_width(),item.height
|
|
|
|
end
|
2016-01-12 09:33:38 +01:00
|
|
|
|
2016-02-12 05:25:03 +01:00
|
|
|
subArrow:set_image( beautiful.menu_submenu_icon )
|
|
|
|
end
|
|
|
|
|
|
|
|
local function bg_fit(box, context, w,h)
|
|
|
|
if data._internal.layout.item_fit then
|
|
|
|
return data._internal.layout.item_fit(data,item,box,context, w, h)
|
|
|
|
else
|
2016-06-24 06:46:41 +02:00
|
|
|
return wibox.container.background.fit(box,context, w,h)
|
2016-02-12 05:25:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if item.checkable then
|
2016-06-24 22:53:47 +02:00
|
|
|
function item.get_checked(_, i)
|
|
|
|
if type(i._private_data.checked) == "function" then
|
|
|
|
return i._private_data.checked()
|
2016-02-12 05:25:03 +01:00
|
|
|
else
|
2016-06-24 22:53:47 +02:00
|
|
|
return i._private_data.checked
|
2016-02-12 05:25:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-24 22:53:47 +02:00
|
|
|
ck = wibox.widget.imagebox()
|
2016-02-12 05:25:03 +01:00
|
|
|
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
|
|
|
|
|
|
|
|
function item:set_checked(value)
|
|
|
|
item._private_data.checked = value
|
|
|
|
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
|
|
|
|
end
|
|
|
|
end
|
2016-01-12 09:33:38 +01:00
|
|
|
|
2016-02-12 05:25:03 +01:00
|
|
|
local w = wibox.widget.base.make_widget_declarative {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{
|
2016-06-24 22:53:47 +02:00
|
|
|
pref or nil,
|
2016-02-12 05:25:03 +01:00
|
|
|
args.prefix_widget ,
|
|
|
|
icon,
|
|
|
|
{
|
|
|
|
align = "center" ,
|
|
|
|
id = "main_text" ,
|
|
|
|
widget = wibox.widget.textbox,
|
|
|
|
},
|
|
|
|
layout = wibox.layout.fixed.vertical,
|
|
|
|
},
|
|
|
|
nil, -- Center
|
|
|
|
{
|
|
|
|
-- Suffix
|
|
|
|
|
|
|
|
-- Widgets
|
2016-06-24 22:53:47 +02:00
|
|
|
subArrow or nil ,
|
|
|
|
ck or nil ,
|
2016-02-12 05:25:03 +01:00
|
|
|
args.suffix_widget ,
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
layout = wibox.layout.fixed.horizontal,
|
|
|
|
},
|
|
|
|
layout = wibox.layout.align.vertical
|
|
|
|
},
|
2016-02-12 05:39:45 +01:00
|
|
|
left = data.fkeys_prefix and 0 or nil,
|
|
|
|
id = "main_margin",
|
2016-06-24 06:46:41 +02:00
|
|
|
layout = wibox.container.margin,
|
2016-02-12 05:25:03 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
-- Attributes
|
|
|
|
fg = item._private_data.fg,
|
|
|
|
_item = item,
|
2016-06-24 06:46:41 +02:00
|
|
|
widget = wibox.container.background
|
2016-02-12 05:25:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
item.widget = w
|
|
|
|
item._internal.icon_w = icon
|
2016-02-12 05:39:45 +01:00
|
|
|
item._internal.margin_w = item.widget:get_children_by_id("main_margin")[1]
|
2016-02-12 05:25:03 +01:00
|
|
|
item._internal.text_w = item.widget:get_children_by_id("main_text")[1]
|
2016-06-24 06:46:41 +02:00
|
|
|
item._private_data._fit = wibox.container.background.fit
|
2016-03-05 08:14:24 +01:00
|
|
|
w.after_draw_children = after_draw_children
|
2016-02-12 05:25:03 +01:00
|
|
|
w.fit = bg_fit
|
|
|
|
|
2016-02-12 05:39:45 +01:00
|
|
|
-- Setup margins
|
|
|
|
local mrgns = margins2(
|
|
|
|
item._internal.margin_w,
|
|
|
|
util.table.join(data.item_style.margins,data.default_item_margins)
|
|
|
|
)
|
|
|
|
|
|
|
|
function item:get_margins()
|
|
|
|
return mrgns
|
|
|
|
end
|
|
|
|
|
2016-02-12 05:25:03 +01:00
|
|
|
-- Setup events
|
2016-03-05 08:14:24 +01:00
|
|
|
common.setup_event(data,item,w)
|
2016-02-12 05:25:03 +01:00
|
|
|
|
|
|
|
return w
|
2014-02-02 23:21:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return create_item(...) end })
|
2016-02-12 05:25:03 +01:00
|
|
|
-- kate: space-indent on; indent-width 4; replace-tabs on;
|