More style/colors oriented refactoring
This commit is contained in:
parent
fabd52d1a6
commit
95ed8b26c4
24
base.lua
24
base.lua
|
@ -35,11 +35,12 @@ local module = {
|
||||||
SELECTED = 3 , -- Single item selected [[FOCUS]]
|
SELECTED = 3 , -- Single item selected [[FOCUS]]
|
||||||
PRESSED = 4 , -- Mouse pressed
|
PRESSED = 4 , -- Mouse pressed
|
||||||
HOVERED = 5 , -- Mouse hover
|
HOVERED = 5 , -- Mouse hover
|
||||||
USED = 6 , -- Common flag
|
CHANGED = 6 , -- The item changed, need attention
|
||||||
CHECKED = 7 , -- When checkbox isn't enough
|
USED = 7 , -- Common flag
|
||||||
ALTERNATE = 8 ,
|
CHECKED = 8 , -- When checkbox isn't enough
|
||||||
HIGHLIGHT = 9 ,
|
ALTERNATE = 9 ,
|
||||||
HEADER = 10,
|
HIGHLIGHT = 10 ,
|
||||||
|
HEADER = 11,
|
||||||
|
|
||||||
-- Implementation defined flags
|
-- Implementation defined flags
|
||||||
USR1 = 101,
|
USR1 = 101,
|
||||||
|
@ -61,6 +62,7 @@ theme.register_color(module.item_flags.URGENT , "urgent" , "urgent" , t
|
||||||
theme.register_color(module.item_flags.SELECTED , "focus" , "focus" , true )
|
theme.register_color(module.item_flags.SELECTED , "focus" , "focus" , true )
|
||||||
theme.register_color(module.item_flags.PRESSED , "pressed" , "pressed" , true )
|
theme.register_color(module.item_flags.PRESSED , "pressed" , "pressed" , true )
|
||||||
theme.register_color(module.item_flags.HOVERED , "hover" , "hover" , true )
|
theme.register_color(module.item_flags.HOVERED , "hover" , "hover" , true )
|
||||||
|
theme.register_color(module.item_flags.CHANGED , "changed" , "changed" , true )
|
||||||
theme.register_color(module.item_flags.USED , "used" , "used" , true )
|
theme.register_color(module.item_flags.USED , "used" , "used" , true )
|
||||||
theme.register_color(module.item_flags.CHECKED , "checked" , "checked" , true )
|
theme.register_color(module.item_flags.CHECKED , "checked" , "checked" , true )
|
||||||
theme.register_color(module.item_flags.ALTERNATE , "alternate" , "alternate" , true )
|
theme.register_color(module.item_flags.ALTERNATE , "alternate" , "alternate" , true )
|
||||||
|
@ -163,7 +165,7 @@ local function add_item(data,args)
|
||||||
if args.selected == true then
|
if args.selected == true then
|
||||||
item.selected = true
|
item.selected = true
|
||||||
end
|
end
|
||||||
|
item.index = data.rowcount
|
||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -323,7 +325,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,{})
|
data.item_style(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})
|
||||||
|
@ -432,6 +434,7 @@ local function new(args)
|
||||||
end
|
end
|
||||||
if idx1 and idx2 then
|
if idx1 and idx2 then
|
||||||
internal.items[idx1],internal.items[idx2] = internal.items[idx2],internal.items[idx1]
|
internal.items[idx1],internal.items[idx2] = internal.items[idx2],internal.items[idx1]
|
||||||
|
item1.index,item2.index = idx2,idx1
|
||||||
data:emit_signal("item::swapped",item1,item2,idx1,idx2)
|
data:emit_signal("item::swapped",item1,item2,idx1,idx2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -454,7 +457,11 @@ local function new(args)
|
||||||
end
|
end
|
||||||
if idx ~= idx1 then
|
if idx ~= idx1 then
|
||||||
table.insert(internal.items,idx1,table.remove(internal.items,idx))
|
table.insert(internal.items,idx1,table.remove(internal.items,idx))
|
||||||
|
item.index = idx
|
||||||
data:emit_signal("item::moved",item,idx,idx1)
|
data:emit_signal("item::moved",item,idx,idx1)
|
||||||
|
for i=idx,idx1 do
|
||||||
|
internal.items[i][1].index = i
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -471,6 +478,9 @@ local function new(args)
|
||||||
if idx1 then
|
if idx1 then
|
||||||
table.remove(internal.items,idx1)
|
table.remove(internal.items,idx1)
|
||||||
data:emit_signal("item::removed",item,idx1)
|
data:emit_signal("item::removed",item,idx1)
|
||||||
|
for i=idx1,#internal.items do
|
||||||
|
internal.items[i][1].index = i
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
4
box.lua
4
box.lua
|
@ -5,6 +5,7 @@ local capi = { mouse = mouse, screen = screen }
|
||||||
|
|
||||||
local function set_position(data)
|
local function set_position(data)
|
||||||
local s = data.screen or capi.mouse.screen
|
local s = data.screen or capi.mouse.screen
|
||||||
|
s = s > capi.screen.count() and 1 or s
|
||||||
local geom = capi.screen[s].geometry
|
local geom = capi.screen[s].geometry
|
||||||
data.wibox.x = geom.x + (geom.width/2) - data.width/2
|
data.wibox.x = geom.x + (geom.width/2) - data.width/2
|
||||||
data.wibox.y = geom.y + (geom.height/2) - data.height/2
|
data.wibox.y = geom.y + (geom.height/2) - data.height/2
|
||||||
|
@ -15,8 +16,7 @@ local function new(args)
|
||||||
args.internal = args.internal or {}
|
args.internal = args.internal or {}
|
||||||
args.arrow_type = base.arrow_type.NONE
|
args.arrow_type = base.arrow_type.NONE
|
||||||
args.internal.set_position = args.internal.set_position or set_position
|
args.internal.set_position = args.internal.set_position or set_position
|
||||||
local ret = context(args)
|
return context(args)
|
||||||
return ret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, { __call = function(_, ...) return new(...) end })
|
return setmetatable({}, { __call = function(_, ...) return new(...) end })
|
||||||
|
|
|
@ -78,15 +78,14 @@ local function new_item(data,args)
|
||||||
local item,set_map,get_map,private_data = object({
|
local item,set_map,get_map,private_data = object({
|
||||||
private_data = {
|
private_data = {
|
||||||
text = args.text or "" ,
|
text = args.text or "" ,
|
||||||
height = args.height or beautiful.menu_height or 30 ,
|
height = args.height or data.item_height or beautiful.menu_height or 30 ,
|
||||||
width = args.width or nil ,
|
width = args.width or nil ,
|
||||||
icon = args.icon or nil ,
|
icon = args.icon or nil ,
|
||||||
prefix = args.prefix or "" ,
|
prefix = args.prefix or "" ,
|
||||||
suffix = args.suffix or "" ,
|
suffix = args.suffix or "" ,
|
||||||
bg = args.bg or nil ,
|
bg = args.bg or nil ,
|
||||||
fg = args.fg or data.fg or beautiful.menu_fg_normal or beautiful.fg_normal ,
|
fg = args.fg or data.fg , --TODO don't do this
|
||||||
fg_focus = args.fg_focus or data.fg_focus or beautiful.menu_fg_focus or beautiful.fg_focus ,
|
border_color= args.border_color or data.border_color ,
|
||||||
bg_focus = args.bg_focus or data.bg_focus or beautiful.menu_bg_focus or beautiful.bg_focus ,
|
|
||||||
bg_prefix = args.bg_prefix or data.bg_prefix ,
|
bg_prefix = args.bg_prefix or data.bg_prefix ,
|
||||||
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_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 ,
|
sub_menu_f = (args.sub_menu and type(args.sub_menu) == "function") and args.sub_menu or nil ,
|
||||||
|
@ -94,15 +93,15 @@ local function new_item(data,args)
|
||||||
checked = args.checked or false ,
|
checked = args.checked or false ,
|
||||||
underlay = args.underlay or nil ,
|
underlay = args.underlay or nil ,
|
||||||
tooltip = args.tooltip or nil ,
|
tooltip = args.tooltip or nil ,
|
||||||
item_style = args.item_style or nil ,
|
style = args.style or data.item_style ,
|
||||||
item_layout = args.item_layout or nil ,
|
item_layout = args.item_layout or nil ,
|
||||||
selected = false ,
|
selected = false ,
|
||||||
overlay = args.overlay or data.overlay or nil ,
|
overlay = args.overlay or data.overlay or nil ,
|
||||||
state = theme.init_state() ,
|
|
||||||
},
|
},
|
||||||
force_private = {
|
force_private = {
|
||||||
visible = true,
|
visible = true,
|
||||||
selected = true,
|
selected = true,
|
||||||
|
index = true,
|
||||||
},
|
},
|
||||||
get_map = {
|
get_map = {
|
||||||
y = function() return (args.y and args.y >= 0) and args.y or data.height - (data.margins.top or data.border_width) - data.item_height end, --Hack around missing :fit call for last item
|
y = function() return (args.y and args.y >= 0) and args.y or data.height - (data.margins.top or data.border_width) - data.item_height end, --Hack around missing :fit call for last item
|
||||||
|
@ -112,7 +111,15 @@ local function new_item(data,args)
|
||||||
autogen_signals = true,
|
autogen_signals = true,
|
||||||
})
|
})
|
||||||
item._private_data = private_data
|
item._private_data = private_data
|
||||||
item._internal = {get_map=get_map,set_map=set_map}
|
item._internal = {get_map=get_map,set_map=set_map}
|
||||||
|
theme.setup_item_colors(data,item,args)
|
||||||
|
item.get_bg = function()
|
||||||
|
return data.bg
|
||||||
|
end
|
||||||
|
item.get_fg = function()
|
||||||
|
return data.fg
|
||||||
|
end
|
||||||
|
item.state = theme.init_state(item)
|
||||||
|
|
||||||
for i=1,10 do
|
for i=1,10 do
|
||||||
item["button"..i] = args["button"..i]
|
item["button"..i] = args["button"..i]
|
||||||
|
@ -134,7 +141,7 @@ local function new_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,{})
|
data.item_style(item,{})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local current_item = data._current_item
|
local current_item = data._current_item
|
||||||
|
@ -145,14 +152,14 @@ local function new_item(data,args)
|
||||||
current_item._tmp_menu = nil
|
current_item._tmp_menu = nil
|
||||||
data._tmp_menu = nil
|
data._tmp_menu = nil
|
||||||
end
|
end
|
||||||
data.item_style(data,current_item,{})
|
data.item_style(current_item,{})
|
||||||
current_item.selected = false
|
current_item.selected = false
|
||||||
end
|
end
|
||||||
if data.sub_menu_on == module.event.SELECTED and current_item ~= item then
|
if data.sub_menu_on == module.event.SELECTED and current_item ~= item then
|
||||||
module.execute_sub_menu(data,item)
|
module.execute_sub_menu(data,item)
|
||||||
end
|
end
|
||||||
item.state[module.item_flags.SELECTED] = true
|
item.state[module.item_flags.SELECTED] = true
|
||||||
data.item_style(data,item,{})
|
data.item_style(item,{})
|
||||||
data._current_item = item
|
data._current_item = item
|
||||||
end
|
end
|
||||||
return item
|
return item
|
||||||
|
|
|
@ -87,7 +87,7 @@ function module:setup_hover(item,data)
|
||||||
item._internal.set_map.hover = function(value)
|
item._internal.set_map.hover = function(value)
|
||||||
local item_style = item.item_style or data.item_style
|
local item_style = item.item_style or data.item_style
|
||||||
item.state[5] = value and true or nil
|
item.state[5] = value and true or nil
|
||||||
item_style(data,item,{})
|
item_style(item,{})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -250,18 +250,22 @@ local function create_item(item,data,args)
|
||||||
item.widget:emit_signal("widget::updated")
|
item.widget:emit_signal("widget::updated")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Draw
|
|
||||||
local item_style = item.item_style or data.item_style
|
|
||||||
item_style(data,item,{})
|
|
||||||
item.widget:set_fg(item._private_data.fg)
|
|
||||||
|
|
||||||
item._internal.text_w = tb
|
item._internal.text_w = tb
|
||||||
item._internal.icon_w = icon
|
item._internal.icon_w = icon
|
||||||
item._internal.margin_w = m
|
item._internal.margin_w = m
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
local item_style = item.item_style or data.item_style
|
||||||
|
item_style(item,{})
|
||||||
|
item.widget:set_fg(item._private_data.fg)
|
||||||
|
|
||||||
-- Setup events
|
-- Setup events
|
||||||
module.setup_event(data,item)
|
module.setup_event(data,item)
|
||||||
|
|
||||||
|
if item.buttons then
|
||||||
|
bg:buttons(item.buttons)
|
||||||
|
end
|
||||||
|
|
||||||
return bg
|
return bg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ module.get_end_arrow = function(args)
|
||||||
local img = cairo.ImageSurface(cairo.Format.ARGB32, width+(args.padding or 0), height)
|
local img = cairo.ImageSurface(cairo.Format.ARGB32, width+(args.padding or 0), height)
|
||||||
local cr = cairo.Context(img)
|
local cr = cairo.Context(img)
|
||||||
cr:set_source(color(args.bg_color or beautiful.bg_normal))
|
cr:set_source(color(args.bg_color or beautiful.bg_normal))
|
||||||
|
cr:set_antialias(cairo.ANTIALIAS_NONE)
|
||||||
cr:new_path()
|
cr:new_path()
|
||||||
if (args.direction == "left") then
|
if (args.direction == "left") then
|
||||||
cr:move_to(0,width+(args.padding or 0))
|
cr:move_to(0,width+(args.padding or 0))
|
||||||
|
@ -58,6 +59,7 @@ module.get_beg_arrow = function(args)
|
||||||
local img = cairo.ImageSurface(cairo.Format.ARGB32, width, height)
|
local img = cairo.ImageSurface(cairo.Format.ARGB32, width, height)
|
||||||
local cr = cairo.Context(img)
|
local cr = cairo.Context(img)
|
||||||
cr:set_source(color(args.bg_color or beautiful.fg_normal))
|
cr:set_source(color(args.bg_color or beautiful.fg_normal))
|
||||||
|
cr:set_antialias(cairo.ANTIALIAS_NONE)
|
||||||
cr:new_path()
|
cr:new_path()
|
||||||
if (args.direction == "left") then
|
if (args.direction == "left") then
|
||||||
cr:move_to(0,width)
|
cr:move_to(0,width)
|
||||||
|
@ -101,7 +103,7 @@ local function get_prev(data,item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function draw(data,item,args)
|
local function draw(item,args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
if item.widget.draw ~= draw_real then
|
if item.widget.draw ~= draw_real then
|
||||||
item.widget.draw = draw_real
|
item.widget.draw = draw_real
|
||||||
|
@ -120,19 +122,22 @@ local function draw(data,item,args)
|
||||||
|
|
||||||
local prev_item = get_prev(data,item)
|
local prev_item = get_prev(data,item)
|
||||||
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
||||||
if prev_item and prev_item.widget.next_color ~= (args.color or data.bg_focus) then
|
if prev_item and prev_item.widget.next_color ~= (args.color) then
|
||||||
prev_item.widget.next_color = args.color or data.bg_focus
|
prev_item.widget.next_color = args.color
|
||||||
prev_item.widget:emit_signal("widget::updated")
|
prev_item.widget:emit_signal("widget::updated")
|
||||||
end
|
end
|
||||||
item.widget:set_bg(args.color or data.bg_focus)
|
item.widget:set_fg(item["fg_focus"])
|
||||||
|
item.widget:set_bg(args.color)
|
||||||
elseif state_name then --TODO untested, most likely broken
|
elseif state_name then --TODO untested, most likely broken
|
||||||
item.widget:set_bg(args.color or item["bg_"..state_name] or data["bg_"..state_name])
|
item.widget:set_bg(args.color or item["bg_"..state_name])
|
||||||
|
item.widget:set_fg( item["fg_"..state_name])
|
||||||
else
|
else
|
||||||
if prev_item and prev_item.widget.next_color ~= hcode[color_idx] then
|
if prev_item and prev_item.widget.next_color ~= hcode[color_idx] then
|
||||||
prev_item.widget.next_color = hcode[color_idx]
|
prev_item.widget.next_color = hcode[color_idx]
|
||||||
prev_item.widget:emit_signal("widget::updated")
|
prev_item.widget:emit_signal("widget::updated")
|
||||||
end
|
end
|
||||||
item.widget:set_bg(args.color or hcode[color_idx])
|
item.widget:set_bg(args.color or hcode[color_idx])
|
||||||
|
item.widget:set_fg(item["fg_normal"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ local function widget_draw(self, w, cr, width, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function draw(data,item,args)
|
local function draw(item,args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
|
||||||
if not item.widget._overlay_init then
|
if not item.widget._overlay_init then
|
||||||
|
@ -85,11 +85,14 @@ local function draw(data,item,args)
|
||||||
local state_name = base.colors_by_id[current_state]
|
local state_name = base.colors_by_id[current_state]
|
||||||
|
|
||||||
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
||||||
item.widget:set_bg(args.color or data.bg_focus)
|
item.widget:set_bg(args.color or item.bg_focus)
|
||||||
|
item.widget:set_fg(item["fg_focus"])
|
||||||
elseif state_name then
|
elseif state_name then
|
||||||
item.widget:set_bg(args.color or item["bg_"..state_name] or data["bg_"..state_name])
|
item.widget:set_bg(args.color or item["bg_"..state_name])
|
||||||
|
item.widget:set_fg( item["fg_"..state_name])
|
||||||
else
|
else
|
||||||
item.widget:set_bg(args.color or nil)
|
item.widget:set_bg(args.color or nil)
|
||||||
|
item.widget:set_fg(item["fg"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ local function suffix_draw(self, w, cr, width, height)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function draw(data,item,args)
|
local function draw(item,args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
|
||||||
item.widget.draw = suffix_draw
|
item.widget.draw = suffix_draw
|
||||||
|
@ -45,11 +45,14 @@ local function draw(data,item,args)
|
||||||
local current_state = state._current_key or nil
|
local current_state = state._current_key or nil
|
||||||
local state_name = base.colors_by_id[current_state]
|
local state_name = base.colors_by_id[current_state]
|
||||||
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
||||||
item.widget:set_bg(args.color or item.bg_focus or data.bg_focus)
|
item.widget:set_bg(args.color or item.bg_focus)
|
||||||
|
item.widget:set_fg(item.fg_focus)
|
||||||
elseif state_name then
|
elseif state_name then
|
||||||
item.widget:set_bg(args.color or item["bg_"..state_name] or data["bg_"..state_name])
|
item.widget:set_bg(args.color or item["bg_"..state_name])
|
||||||
|
item.widget:set_fg( item["fg_"..state_name])
|
||||||
else
|
else
|
||||||
item.widget:set_bg(args.color or nil)
|
item.widget:set_bg(args.color or nil)
|
||||||
|
-- item.widget:set_fg(item["fg"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ local function widget_draw23(self, w, cr, width, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function draw(data,item,args)
|
local function draw(item,args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
|
||||||
if not item.widget._overlay_init and not item.widget._draw then
|
if not item.widget._overlay_init and not item.widget._draw then
|
||||||
|
@ -34,11 +34,14 @@ local function draw(data,item,args)
|
||||||
local state_name = base.colors_by_id[current_state]
|
local state_name = base.colors_by_id[current_state]
|
||||||
|
|
||||||
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
||||||
item.widget:set_bg(args.color or data.bg_focus)
|
item.widget:set_bg(item.bg_focus)
|
||||||
|
item.widget:set_fg(item.fg_focus)
|
||||||
elseif state_name then
|
elseif state_name then
|
||||||
item.widget:set_bg(args.color or item["bg_"..state_name] or data["bg_"..state_name])
|
item.widget:set_bg(args.color or item["bg_"..state_name])
|
||||||
|
item.widget:set_fg( item["fg_"..state_name])
|
||||||
else
|
else
|
||||||
item.widget:set_bg(args.color or nil)
|
item.widget:set_bg(args.color or nil)
|
||||||
|
-- item.widget:set_fg(item["fg_normal"] or data["fg_normal"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ local function widget_draw(self, w, cr, width, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function draw(data,item,args)
|
local function draw(item,args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local col = args.color
|
local col = args.color
|
||||||
|
|
||||||
|
@ -45,14 +45,14 @@ local function draw(data,item,args)
|
||||||
item.widget._overlay_init = true
|
item.widget._overlay_init = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local ih = data.item_height
|
local ih = 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
|
||||||
focussed,default,alt={},{},{}
|
focussed,default,alt={},{},{}
|
||||||
end
|
end
|
||||||
local bc = data.border_color
|
local bc = item.border_color
|
||||||
focussed[ih] = gen(ih,data.bg_focus,bc)
|
focussed[ih] = gen(ih,item.bg_focus,bc)
|
||||||
default [ih] = gen(ih,data.bg,bc)
|
default [ih] = gen(ih,item.bg,bc)
|
||||||
end
|
end
|
||||||
if col and (not alt[col] or not alt[col][ih]) then
|
if col and (not alt[col] or not alt[col][ih]) then
|
||||||
alt[col] = alt[col] or {}
|
alt[col] = alt[col] or {}
|
||||||
|
@ -60,15 +60,18 @@ local function draw(data,item,args)
|
||||||
end
|
end
|
||||||
|
|
||||||
local state = item.state or {}
|
local state = item.state or {}
|
||||||
-- local current_state = state._current_key or nil --TODO
|
local current_state = state._current_key or nil
|
||||||
-- local state_name = base.colors_by_id[current_state]
|
local state_name = base.colors_by_id[current_state]
|
||||||
|
|
||||||
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
||||||
item.widget:set_bg(focussed[ih])
|
item.widget:set_bg(focussed[ih])
|
||||||
|
item.widget:set_fg(item["fg_focus"])
|
||||||
elseif col then
|
elseif col then
|
||||||
item.widget:set_bg(alt[col][ih])
|
item.widget:set_bg(alt[col][ih])
|
||||||
|
item.widget:set_fg(item["fg_"..state_name])
|
||||||
else
|
else
|
||||||
item.widget:set_bg(default[ih])
|
item.widget:set_bg(default[ih])
|
||||||
|
-- item.widget:set_fg(item["fg_normal"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ local function widget_draw(self, w, cr, width, height)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function draw(data,item,args)
|
local function draw(item,args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
|
||||||
if not item.widget._overlay_init then
|
if not item.widget._overlay_init then
|
||||||
|
@ -49,14 +49,14 @@ local function draw(data,item,args)
|
||||||
item.widget._overlay_init = true
|
item.widget._overlay_init = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local ih = data.item_height
|
local ih = 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
|
||||||
focussed,default={},{}
|
focussed,default={},{}
|
||||||
end
|
end
|
||||||
local bc = data.border_color
|
local bc = item.border_color
|
||||||
focussed[ih] = gen(ih,data.bg_focus,bc)
|
focussed[ih] = gen(ih,item.bg_focus,bc)
|
||||||
default [ih] = gen(ih,data.bg,bc)
|
default [ih] = gen(ih,item.bg,bc)
|
||||||
end
|
end
|
||||||
|
|
||||||
local state = item.state or {}
|
local state = item.state or {}
|
||||||
|
@ -65,10 +65,13 @@ local function draw(data,item,args)
|
||||||
|
|
||||||
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
|
||||||
item.widget:set_bg(focussed[ih])
|
item.widget:set_bg(focussed[ih])
|
||||||
|
item.widget:set_fg(item["fg_focus"])
|
||||||
elseif state_name then --TODO incomplete
|
elseif state_name then --TODO incomplete
|
||||||
item.widget:set_bg(args.color or item["bg_"..state_name] or data["bg_"..state_name])
|
item.widget:set_bg(args.color or item["bg_"..state_name])
|
||||||
|
item.widget:set_fg( item["fg_"..state_name])
|
||||||
else
|
else
|
||||||
item.widget:set_bg(default[ih])
|
item.widget:set_bg(default[ih])
|
||||||
|
item.widget:set_fg(item["fg_normal"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ function module:setup_item(data,item,args)
|
||||||
|
|
||||||
-- Set widget
|
-- Set widget
|
||||||
item.widget = bg
|
item.widget = bg
|
||||||
data.item_style(data,item,{})
|
data.item_style(item,{})
|
||||||
setup_event(data,item,args)
|
setup_event(data,item,args)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -177,7 +177,7 @@ function module:setup_item(data,item,args)
|
||||||
|
|
||||||
-- Apply item style
|
-- Apply item style
|
||||||
local item_style = item.item_style or data.item_style
|
local item_style = item.item_style or data.item_style
|
||||||
item_style(data,item,{})
|
item_style(item,{})
|
||||||
|
|
||||||
item.widget:emit_signal("widget::updated")
|
item.widget:emit_signal("widget::updated")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
local math = math
|
local math = math
|
||||||
|
local rawget,rawset=rawget,rawset
|
||||||
local beautiful = require( "beautiful" )
|
local beautiful = require( "beautiful" )
|
||||||
|
|
||||||
local module = {
|
local module = {
|
||||||
|
@ -19,14 +20,16 @@ local function change_data(tab, key,value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rawset(tab,"_current_key",win ~= math.huge and win or nil)
|
rawset(tab,"_current_key",win ~= math.huge and win or nil)
|
||||||
|
tab._item:style()
|
||||||
elseif value and (rawget(tab,"_current_key") or math.huge) > key then
|
elseif value and (rawget(tab,"_current_key") or math.huge) > key then
|
||||||
rawset(tab,"_current_key",key)
|
rawset(tab,"_current_key",key)
|
||||||
|
tab._item:style()
|
||||||
end
|
end
|
||||||
tab._real_table[key] = value
|
tab._real_table[key] = value
|
||||||
end
|
end
|
||||||
function module.init_state()
|
function module.init_state(item)
|
||||||
local mt = {__newindex = change_data,__index=return_data}
|
local mt = {__newindex = change_data,__index=return_data}
|
||||||
return setmetatable({_real_table={}},mt)
|
return setmetatable({_real_table={},_item=item},mt)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Util to help match colors to states
|
-- Util to help match colors to states
|
||||||
|
@ -38,11 +41,31 @@ end
|
||||||
function module.setup_colors(data,args)
|
function module.setup_colors(data,args)
|
||||||
local priv = data._internal.private_data
|
local priv = data._internal.private_data
|
||||||
for k,v in pairs(theme_colors) do
|
for k,v in pairs(theme_colors) do
|
||||||
priv["fg_"..k] = args["fg_"..k] or beautiful["menu_fg_"..v.beautiful_name] or beautiful["fg_"..v.beautiful_name] or (v.fallback and "#ff0000")
|
priv["fg_"..k] = args["fg_"..k] or beautiful["menu_fg_"..v.beautiful_name] or beautiful["fg_"..v.beautiful_name] or (v.fallback and beautiful.fg_normal)
|
||||||
priv["bg_"..k] = args["bg_"..k] or beautiful["menu_bg_"..v.beautiful_name] or beautiful["bg_"..v.beautiful_name] or (v.fallback and "#00ff00")
|
priv["bg_"..k] = args["bg_"..k] or beautiful["menu_bg_"..v.beautiful_name] or beautiful["bg_"..v.beautiful_name] or (v.fallback and beautiful.bg_normal)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function module.setup_item_colors(data,item,args)
|
||||||
|
local priv = item._private_data
|
||||||
|
for k,v in pairs(theme_colors) do
|
||||||
|
if args["fg_"..k] then
|
||||||
|
priv["fg_"..k] = args["fg_"..k]
|
||||||
|
else
|
||||||
|
rawset(item,"get_fg_"..k,function()
|
||||||
|
return data["fg_"..k]
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
if args["bg_"..k] then
|
||||||
|
priv["bg_"..k] = args["bg_"..k]
|
||||||
|
else
|
||||||
|
rawset(item,"get_bg_"..k, function()
|
||||||
|
return data["bg_"..k]
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return setmetatable(module, { __call = function(_, ...) return new(...) 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;
|
|
@ -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]},{color=data.bg_highlight})
|
data.item_style({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]},{color=data.bg_alternate or beautiful.bg_focus})
|
data.item_style({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]},{color=data.bg_highlight})
|
data.item_style({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)
|
||||||
|
|
Loading…
Reference in New Issue