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) item.widget:set_tooltip(item.tooltip)
-- Draw -- Draw
data.item_style(data,item,false,false) data.item_style(data,item,{})
item.widget:set_fg(item._private_data.fg) item.widget:set_fg(item._private_data.fg)
return bg return bg

View File

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

View File

@ -1,5 +1,6 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local print = print local print = print
local base = require( "radical.base" )
local module = { local module = {
margins = { margins = {
@ -10,11 +11,13 @@ local module = {
} }
} }
local function draw(data,item,is_focussed,is_pressed,col) local function draw(data,item,args)
if is_focussed or (item._tmp_menu) then local args,flags = args or {},{}
item.widget:set_bg(col or data.bg_focus) 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 else
item.widget:set_bg(col or nil) item.widget:set_bg(args.color or nil)
end end
end end

View File

@ -1,5 +1,7 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local print = print local print = print
local pairs=pairs
local base = require( "radical.base" )
local module = { local module = {
margins = { margins = {
@ -10,11 +12,14 @@ local module = {
} }
} }
local function draw(data,item,is_focussed,is_pressed,col) local function draw(data,item,args)
if is_focussed or (item._tmp_menu) then local args,flags = args or {},{}
item.widget:set_bg(col or data.bg_focus) 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 else
item.widget:set_bg(col or nil) item.widget:set_bg(args.color or nil)
end end
end end

View File

@ -1,4 +1,5 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local base = require( "radical.base" )
local color = require( "gears.color" ) local color = require( "gears.color" )
local cairo = require( "lgi" ).cairo local cairo = require( "lgi" ).cairo
local beautiful = require( "beautiful" ) local beautiful = require( "beautiful" )
@ -26,7 +27,10 @@ local function gen(item_height,bg_color,border_color)
return cairo.Pattern.create_for_surface(img) return cairo.Pattern.create_for_surface(img)
end 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 local ih = data.item_height
if not focussed or not focussed[ih] then if not focussed or not focussed[ih] then
if not focussed 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) alt[col][ih] = gen(ih,color(col),bc)
end 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]) item.widget:set_bg(focussed[ih])
elseif col then elseif col then
item.widget:set_bg(alt[col][ih]) item.widget:set_bg(alt[col][ih])

View File

@ -1,5 +1,6 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local math = math local math = math
local base = require( "radical.base" )
local color = require( "gears.color" ) local color = require( "gears.color" )
local cairo = require( "lgi" ).cairo local cairo = require( "lgi" ).cairo
local print = print local print = print
@ -31,7 +32,9 @@ local function gen(item_height,bg_color,border_color)
return cairo.Pattern.create_for_surface(img) return cairo.Pattern.create_for_surface(img)
end 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 local ih = data.item_height
if not focussed or not focussed[ih] then if not focussed or not focussed[ih] then
if not focussed 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) default [ih] = gen(ih,data.bg,bc)
end 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]) item.widget:set_bg(focussed[ih])
else else
item.widget:set_bg(default[ih]) item.widget:set_bg(default[ih])

View File

@ -56,7 +56,7 @@ end
function module:setup_item(data,item,args) function module:setup_item(data,item,args)
--Create the background --Create the background
item.widget = wibox.widget.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) item.widget:set_fg(item._private_data.fg)
--Event handling --Event handling

View File

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

View File

@ -65,12 +65,12 @@ local function new(data)
scroll_w[v] = wibox.widget.background() scroll_w[v] = wibox.widget.background()
scroll_w[v]:set_widget(ib) scroll_w[v]:set_widget(ib)
scroll_w[v].visible = true 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() 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) end)
scroll_w[v]:connect_signal("mouse::leave",function() 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) end)
scroll_w[v]:buttons( util.table.join( button({ }, 1, function() scroll_w[v]:buttons( util.table.join( button({ }, 1, function()
data["scroll_"..v](data) data["scroll_"..v](data)