item.layout: Use the checkbox widget

This commit is contained in:
Emmanuel Lepage Vallee 2016-07-04 04:22:31 -04:00
parent 7600e4b888
commit 0618a8d18c
3 changed files with 35 additions and 46 deletions

View File

@ -1,4 +1,5 @@
local wibox = require( "wibox" )
local beautiful = require( "beautiful" )
local module = {}
@ -47,6 +48,31 @@ function module.setup_fkey(item,data)
end
end
-- Setup the checkbox
function module.setup_checked(item, data)
if item.checkable then
item.get_checked = function()
if type(item._private_data.checked) == "function" then
return item._private_data.checked(data,item)
else
return item._private_data.checked
end
end
local ck = wibox.widget.checkbox(item.checked or false, {
style = beautiful.menu_checkbox_style,
color = beautiful.fg_normal
})
item.set_checked = function (_,value)
item._private_data.checked = value
ck.checked = value
item._internal.has_changed = true
end
return ck
end
end
-- Proxy all events to the parent
function module.setup_event(data,item,widget)
widget = widget or item.widget

View File

@ -1,7 +1,6 @@
local setmetatable = setmetatable
local beautiful = require( "beautiful" )
local wibox = require( "wibox" )
local checkbox = require( "radical.widgets.checkbox" )
local fkey = require( "radical.widgets.fkey" )
local infoshapes = require( "radical.widgets.infoshapes" )
local util = require( "awful.util" )
@ -12,27 +11,6 @@ local common = require( "radical.item.common" )
local module = {}
-- Show the checkbox
function module:setup_checked(item,data)
if item.checkable then
item.get_checked = function()
if type(item._private_data.checked) == "function" then
return item._private_data.checked(data,item)
else
return item._private_data.checked
end
end
local ck = wibox.widget.imagebox()
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
item.set_checked = function (_,value)
item._private_data.checked = value
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
item._internal.has_changed = true
end
return ck
end
end
-- Create sub_menu arrows
local sub_arrow = nil
function module:setup_sub_menu_arrow(item,data)
@ -65,6 +43,8 @@ local function create_item(item,data,args)
-- Icon
local icon = common.setup_icon(item,data)
local checkbox = common.setup_checked(item,data)
if data.icon_per_state == true then --TODO create an icon widget, see item/common.lua
item:connect_signal("state::changed",function(i,d,st)
if item._original_icon and data.icon_transformation then
@ -119,7 +99,7 @@ local function create_item(item,data,args)
-- Suffixes
-- Widget
module:setup_checked(item,data) ,
checkbox ,
module:setup_sub_menu_arrow(item,data),
args.suffix_widget ,

View File

@ -2,7 +2,6 @@ local setmetatable = setmetatable
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" )
local common = require( "radical.item.common" )
@ -36,7 +35,7 @@ local function icon_draw(self, context, cr, width, height)
end
local function create_item(item,data,args)
local pref, subArrow, ck = nil, nil, nil
local pref, subArrow = nil, nil
if data.fkeys_prefix == true then
pref = wibox.widget.textbox()
@ -50,7 +49,9 @@ local function create_item(item,data,args)
local icon = common.setup_icon(item,data)
icon.fit = function(...) return icon_fit(data,...) end
icon.draw = icon_draw
icon.draw = icon_draw --TODO use a constraint
local checkbox = common.setup_checked(item,data)
local has_children = item._private_data.sub_menu_f or item._private_data.sub_menu_m
@ -72,24 +73,6 @@ local function create_item(item,data,args)
end
end
if item.checkable then
function item.get_checked(_, i)
if type(i._private_data.checked) == "function" then
return i._private_data.checked()
else
return i._private_data.checked
end
end
ck = wibox.widget.imagebox()
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
local w = wibox.widget.base.make_widget_declarative {
{
{
@ -110,7 +93,7 @@ local function create_item(item,data,args)
-- Widgets
subArrow or nil ,
ck or nil ,
checkbox or nil ,
args.suffix_widget ,
-- Attributes