Add support for checkboxes
This commit is contained in:
parent
88d7ad2ff1
commit
4b8e11f6ac
24
base.lua
24
base.lua
|
@ -115,6 +115,8 @@ function add_item(data,args)
|
|||
sub_menu_m = (args.sub_menu and type(args.sub_menu) == "table" and args.sub_menu.is_menu) and args.sub_menu or nil,
|
||||
sub_menu_f = (args.sub_menu and type(args.sub_menu) == "function") and args.sub_menu or nil,
|
||||
selected = false,
|
||||
checkable = args.checkable or (args.checked ~= nil) or false,
|
||||
checked = args.checked or false,
|
||||
},
|
||||
force_private = {
|
||||
visible = true,
|
||||
|
@ -128,6 +130,7 @@ function add_item(data,args)
|
|||
autogen_signals = true,
|
||||
})
|
||||
item._private_data = private_data
|
||||
item._internal = {get_map=get_map,set_map=set_map}
|
||||
|
||||
for i=1,10 do
|
||||
item["button"..i] = args["button"..i]
|
||||
|
@ -136,7 +139,7 @@ function add_item(data,args)
|
|||
set_map.selected = function(value)
|
||||
private_data.selected = value
|
||||
if value == false then
|
||||
data.item_style(data,item,false,false)
|
||||
data.item_style(data,item,false--[[ or (item._tmp_menu ~= nil and item._tmp_menu == data._tmp_menu)]],false)
|
||||
return
|
||||
end
|
||||
if data._current_item and data._current_item ~= item then
|
||||
|
@ -149,12 +152,14 @@ function add_item(data,args)
|
|||
end
|
||||
if (private_data.sub_menu_f or private_data.sub_menu_m)and data._current_item ~= item then
|
||||
local sub_menu = private_data.sub_menu_m or private_data.sub_menu_f()
|
||||
sub_menu.arrow_type = module.arrow_type.NONE
|
||||
sub_menu.parent_item = item
|
||||
sub_menu.parent_geometry = data
|
||||
sub_menu.visible = true
|
||||
item._tmp_menu = sub_menu
|
||||
data._tmp_menu = sub_menu
|
||||
if sub_menu then
|
||||
sub_menu.arrow_type = module.arrow_type.NONE
|
||||
sub_menu.parent_item = item
|
||||
sub_menu.parent_geometry = data
|
||||
sub_menu.visible = true
|
||||
item._tmp_menu = sub_menu
|
||||
data._tmp_menu = sub_menu
|
||||
end
|
||||
end
|
||||
data.item_style(data,item,true,false)
|
||||
data._current_item = item
|
||||
|
@ -307,6 +312,11 @@ local function new(args)
|
|||
end
|
||||
end
|
||||
|
||||
function data:clear()
|
||||
internal.items = {}
|
||||
data:emit_signal("clear::menu")
|
||||
end
|
||||
|
||||
if private_data.layout then
|
||||
private_data.layout:setup_key_hooks(data)
|
||||
end
|
||||
|
|
37
context.lua
37
context.lua
|
@ -2,6 +2,7 @@ local base = require( "radical.base" )
|
|||
local print = print
|
||||
local unpack = unpack
|
||||
local debug = debug
|
||||
local type = type
|
||||
local setmetatable = setmetatable
|
||||
local color = require( "gears.color" )
|
||||
local wibox = require( "wibox" )
|
||||
|
@ -11,6 +12,7 @@ local awful = require( "awful" )
|
|||
local util = require( "awful.util" )
|
||||
local button = require( "awful.button" )
|
||||
local layout = require( "radical.layout" )
|
||||
local checkbox = require( "radical.widgets.checkbox" )
|
||||
local arrow_style = require( "radical.style.arrow" )
|
||||
|
||||
local capi,module = { mouse = mouse , screen = screen , keygrabber = keygrabber },{}
|
||||
|
@ -134,6 +136,8 @@ local function setup_drawable(data)
|
|||
function internal:set_visible(value)
|
||||
internal.w.visible = value
|
||||
end
|
||||
local fit_w,fit_h = data._internal.layout:fit()
|
||||
data.width = fit_w
|
||||
end
|
||||
|
||||
local function setup_item(data,item,args)
|
||||
|
@ -163,9 +167,14 @@ local function setup_item(data,item,args)
|
|||
|
||||
--Be sure to always hide sub menus, even when data.visible is set manually
|
||||
data:connect_signal("visible::changed",function(_,vis)
|
||||
if data._tmp_menu and data.visible == false then
|
||||
data._tmp_menu.visible = false
|
||||
end
|
||||
if data._tmp_menu and data.visible == false then
|
||||
data._tmp_menu.visible = false
|
||||
end
|
||||
end)
|
||||
data:connect_signal("parent_geometry::changed",function(_,vis)
|
||||
local fit_w,fit_h = data._internal.layout:fit()
|
||||
data.height = fit_h
|
||||
data.style(data)
|
||||
end)
|
||||
item.widget:buttons( util.table.join(unpack(buttons)))
|
||||
|
||||
|
@ -219,6 +228,22 @@ local function setup_item(data,item,args)
|
|||
return wibox.widget.background.fit(box,w,h,...)
|
||||
end
|
||||
end
|
||||
if item.checkable then
|
||||
item._internal.get_map.checked = function()
|
||||
if type(item._private_data.checked) == "function" then
|
||||
return item._private_data.checked()
|
||||
else
|
||||
return item._private_data.checked
|
||||
end
|
||||
end
|
||||
local ck = wibox.widget.imagebox()
|
||||
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
|
||||
lr:add(ck)
|
||||
item._internal.set_map.checked = function (value)
|
||||
item._private_data.checked = value
|
||||
ck:set_image(item.checked and checkbox.checked() or checkbox.unchecked())
|
||||
end
|
||||
end
|
||||
if args.suffix_widget then
|
||||
lr:add(args.suffix_widget)
|
||||
end
|
||||
|
@ -227,7 +252,6 @@ local function setup_item(data,item,args)
|
|||
item.widget:set_widget(m)
|
||||
local fit_w,fit_h = data._internal.layout:fit()
|
||||
data.height = fit_h
|
||||
-- data.width = fit_w
|
||||
data.style(data)
|
||||
end
|
||||
|
||||
|
@ -241,8 +265,11 @@ local function new(args)
|
|||
args.internal.setup_item = args.internal.setup_item or setup_item
|
||||
args.style = args.style or arrow_style
|
||||
local ret = base(args)
|
||||
ret:connect_signal("clear::menu",function(_,vis)
|
||||
ret._internal.layout:reset()
|
||||
end)
|
||||
return ret
|
||||
end
|
||||
|
||||
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
||||
-- kate: space-indent on; indent-width 2; replace-tabs on;
|
||||
-- kate: space-indent on; indent-width 2; replace-tabs on;
|
|
@ -0,0 +1,63 @@
|
|||
local setmetatable = setmetatable
|
||||
local print = print
|
||||
local color = require("gears.color")
|
||||
local cairo = require( "lgi" ).cairo
|
||||
|
||||
local beautiful = require( "beautiful" )
|
||||
|
||||
local module = {}
|
||||
|
||||
local checkedI
|
||||
local notcheckedI
|
||||
local isinit = false
|
||||
|
||||
local function init()
|
||||
local size = beautiful.menu_height or 16
|
||||
notcheckedI = cairo.ImageSurface(cairo.Format.ARGB32, size,size)
|
||||
checkedI = cairo.ImageSurface(cairo.Format.ARGB32, size,size)
|
||||
local cr2 = cairo.Context(notcheckedI)
|
||||
local cr = cairo.Context(checkedI)
|
||||
cr:set_operator(cairo.Operator.CLEAR)
|
||||
cr2:set_operator(cairo.Operator.CLEAR)
|
||||
cr:paint()
|
||||
cr2:paint()
|
||||
cr:set_operator(cairo.Operator.SOURCE)
|
||||
cr2:set_operator(cairo.Operator.SOURCE)
|
||||
local sp = 2.5
|
||||
local rs = size - (2*sp)
|
||||
cr:set_source(color(beautiful.fg_normal))
|
||||
cr2:set_source(color(beautiful.fg_normal))
|
||||
cr:set_line_width(2)
|
||||
cr2:set_line_width(2)
|
||||
cr:move_to( sp , sp );cr:line_to( rs , sp )
|
||||
cr:move_to( sp , sp );cr:line_to( sp , rs )
|
||||
cr:move_to( sp , rs );cr:line_to( rs , rs )
|
||||
cr:move_to( rs , sp );cr:line_to( rs , rs )
|
||||
cr:move_to( sp , sp );cr:line_to( rs , rs )
|
||||
cr:move_to( sp , rs );cr:line_to( rs , sp )
|
||||
cr:stroke()
|
||||
|
||||
cr2:move_to( sp , sp );cr2:line_to (rs , sp , beautiful.fg_normal )
|
||||
cr2:move_to( sp , sp );cr2:line_to (sp , rs , beautiful.fg_normal )
|
||||
cr2:move_to( sp , rs );cr2:line_to (rs , rs , beautiful.fg_normal )
|
||||
cr2:move_to( rs , sp );cr2:line_to (rs , rs , beautiful.fg_normal )
|
||||
cr2:stroke()
|
||||
|
||||
isinit = true
|
||||
end
|
||||
|
||||
function module.checked()
|
||||
if not isinit then
|
||||
init()
|
||||
end
|
||||
return checkedI
|
||||
end
|
||||
|
||||
function module.unchecked()
|
||||
if not isinit then
|
||||
init()
|
||||
end
|
||||
return notcheckedI
|
||||
end
|
||||
|
||||
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
|
@ -0,0 +1,3 @@
|
|||
return {
|
||||
checkbox = require("radical.widgets.checkbox")
|
||||
}
|
Loading…
Reference in New Issue