From 9a7275a399e3805eddae2c151cfe8ef7f629b490 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 4 Jul 2016 04:22:31 -0400 Subject: [PATCH] item.layout: Use the checkbox widget --- item/common.lua | 28 +++++++++++++++++++++++++++- item/layout/horizontal.lua | 26 +++----------------------- item/layout/icon.lua | 27 +++++---------------------- 3 files changed, 35 insertions(+), 46 deletions(-) diff --git a/item/common.lua b/item/common.lua index cac9619..6d1ced8 100644 --- a/item/common.lua +++ b/item/common.lua @@ -1,4 +1,5 @@ -local wibox = require( "wibox" ) +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 diff --git a/item/layout/horizontal.lua b/item/layout/horizontal.lua index 3d6dd11..9d78a10 100644 --- a/item/layout/horizontal.lua +++ b/item/layout/horizontal.lua @@ -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 , diff --git a/item/layout/icon.lua b/item/layout/icon.lua index 1e637ad..51ed141 100644 --- a/item/layout/icon.lua +++ b/item/layout/icon.lua @@ -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