Replace old item_style attributes by a more flexible array

This commit is contained in:
Emmanuel Lepage Vallee 2014-01-08 00:59:57 -05:00
parent e20c6921dc
commit a1144564ab
9 changed files with 45 additions and 24 deletions

View File

@ -135,7 +135,7 @@ local function create_item(item,data,args)
item.widget:set_tooltip(item.tooltip)
-- Draw
data.item_style(data,item,false,false)
data.item_style(data,item,{})
item.widget:set_fg(item._private_data.fg)
return bg

View File

@ -5,7 +5,6 @@ local print,unpack = print, unpack
local beautiful = require( "beautiful" )
local util = require( "awful.util" )
local object = require( "radical.object" )
local item_style = require( "radical.item_style" )
local capi = { mouse = mouse, screen = screen , keygrabber = keygrabber }
@ -22,6 +21,13 @@ local module = {
BUTTON3 = 3,
SELECTED = 100,
},
item_flags = {
SELECTED = 1,
HOVERED = 2,
PRESSED = 3,
URGENT = 4,
USED = 5,
}
}
local function filter(data)
@ -165,7 +171,7 @@ local 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,{})
return
end
if data._current_item and data._current_item ~= item then
@ -173,14 +179,14 @@ local function add_item(data,args)
data._current_item._tmp_menu.visible = false
data._current_item._tmp_menu = nil
data._tmp_menu = nil
data.item_style(data,data._current_item,false,false)
data.item_style(data,data._current_item,{})
end
data._current_item.selected = false
end
if data.sub_menu_on == module.sub_menu_on.SELECTED and data._current_item ~= item then
execute_sub_menu(data,item)
end
data.item_style(data,item,true,false)
data.item_style(data,item,{module.item_flags.SELECTED})
data._current_item = item
end
@ -276,7 +282,7 @@ local function new(args)
layout = args.layout or nil,
screen = args.screen or nil,
style = args.style or nil,
item_style = args.item_style or item_style.basic,
item_style = args.item_style or require("radical.item_style.basic"),
filter = args.filter ~= false,
show_filter = args.show_filter or false,
filter_string = args.filter_string or "",
@ -336,7 +342,7 @@ local function new(args)
-- data._tmp_menu = nil
data._current_item._tmp_menu = nil
-- data._current_item.selected = false
data.item_style(data,data._current_item,false,false)
data.item_style(data,data._current_item,{})
end
if internal.has_changed and data.style then
data.style(data,{arrow_x=20,margin=internal.margin})

View File

@ -1,5 +1,6 @@
local setmetatable = setmetatable
local print = print
local base = require( "radical.base" )
local module = {
margins = {
@ -10,11 +11,13 @@ local module = {
}
}
local function draw(data,item,is_focussed,is_pressed,col)
if is_focussed or (item._tmp_menu) then
item.widget:set_bg(col or data.bg_focus)
local function draw(data,item,args)
local args,flags = args or {},{}
for _,v in pairs(args) do flags[v] = true end
if flags[base.item_flags.SELECTED] or (item._tmp_menu) then
item.widget:set_bg(args.color or data.bg_focus)
else
item.widget:set_bg(col or nil)
item.widget:set_bg(args.color or nil)
end
end

View File

@ -1,5 +1,7 @@
local setmetatable = setmetatable
local print = print
local pairs=pairs
local base = require( "radical.base" )
local module = {
margins = {
@ -10,11 +12,14 @@ local module = {
}
}
local function draw(data,item,is_focussed,is_pressed,col)
if is_focussed or (item._tmp_menu) then
item.widget:set_bg(col or data.bg_focus)
local function draw(data,item,args)
local args,flags = args or {},{}
for _,v in pairs(args) do print("ici",v);flags[v] = true end
if flags[base.item_flags.SELECTED] or (item._tmp_menu) then
item.widget:set_bg(args.color or data.bg_focus)
else
item.widget:set_bg(col or nil)
item.widget:set_bg(args.color or nil)
end
end

View File

@ -1,4 +1,5 @@
local setmetatable = setmetatable
local base = require( "radical.base" )
local color = require( "gears.color" )
local cairo = require( "lgi" ).cairo
local beautiful = require( "beautiful" )
@ -26,7 +27,10 @@ local function gen(item_height,bg_color,border_color)
return cairo.Pattern.create_for_surface(img)
end
local function draw(data,item,is_focussed,is_pressed,col)
local function draw(data,item,args)
local args,flags = args or {},{}
local col = args.color
for _,v in pairs(args) do flags[v] = true end
local ih = data.item_height
if not focussed or not focussed[ih] then
if not focussed then
@ -41,7 +45,7 @@ local function draw(data,item,is_focussed,is_pressed,col)
alt[col][ih] = gen(ih,color(col),bc)
end
if is_focussed or (item._tmp_menu) then
if flags[base.item_flags.SELECTED] or (item._tmp_menu) then
item.widget:set_bg(focussed[ih])
elseif col then
item.widget:set_bg(alt[col][ih])

View File

@ -1,5 +1,6 @@
local setmetatable = setmetatable
local math = math
local base = require( "radical.base" )
local color = require( "gears.color" )
local cairo = require( "lgi" ).cairo
local print = print
@ -31,7 +32,9 @@ local function gen(item_height,bg_color,border_color)
return cairo.Pattern.create_for_surface(img)
end
local function draw(data,item,is_focussed,is_pressed)
local function draw(data,item,args)
local args,flags = args or {},{}
for _,v in pairs(args) do flags[v] = true end
local ih = data.item_height
if not focussed or not focussed[ih] then
if not focussed then
@ -42,7 +45,7 @@ local function draw(data,item,is_focussed,is_pressed)
default [ih] = gen(ih,data.bg,bc)
end
if is_focussed or (item._tmp_menu) then
if flags[base.item_flags.SELECTED] or (item._tmp_menu) then
item.widget:set_bg(focussed[ih])
else
item.widget:set_bg(default[ih])

View File

@ -56,7 +56,7 @@ end
function module:setup_item(data,item,args)
--Create the background
item.widget = wibox.widget.background()
data.item_style(data,item,false,false)
data.item_style(data,item,{})
item.widget:set_fg(item._private_data.fg)
--Event handling

View File

@ -184,7 +184,7 @@ function module:setup_item(data,item,args)
item.widget = wibox.widget.background()
cache_pixmap(item)
data.item_style(data,item,false,false)
data.item_style(data,item,{})
item.widget:set_fg(item._private_data.fg)
item._internal.has_changed = true

View File

@ -65,12 +65,12 @@ local function new(data)
scroll_w[v] = wibox.widget.background()
scroll_w[v]:set_widget(ib)
scroll_w[v].visible = true
data.item_style(data,{widget=scroll_w[v]},false,false,data.bg_highlight)
data.item_style(data,{widget=scroll_w[v]},{color=data.bg_highlight})
scroll_w[v]:connect_signal("mouse::enter",function()
data.item_style(data,{widget=scroll_w[v]},false,false,data.bg_alternate or beautiful.bg_focus)
data.item_style(data,{widget=scroll_w[v]},{color=data.bg_alternate or beautiful.bg_focus})
end)
scroll_w[v]:connect_signal("mouse::leave",function()
data.item_style(data,{widget=scroll_w[v]},false,false,data.bg_highlight)
data.item_style(data,{widget=scroll_w[v]},{color=data.bg_highlight})
end)
scroll_w[v]:buttons( util.table.join( button({ }, 1, function()
data["scroll_"..v](data)