From 9148c48dd16b994e5fc3dc5ebe80bfe2d5d33a7d Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Thu, 20 Feb 2014 22:29:40 -0500 Subject: [PATCH] Fix issue #7 --- base.lua | 20 ++++++++++++-------- item_layout/horizontal.lua | 1 + item_style/arrow_alt.lua | 7 ++++--- item_style/arrow_prefix.lua | 9 +++++---- item_style/arrow_single.lua | 9 +++++---- item_style/basic.lua | 6 +++--- item_style/classic.lua | 7 ++++--- item_style/rounded.lua | 7 ++++--- 8 files changed, 38 insertions(+), 28 deletions(-) diff --git a/base.lua b/base.lua index 646e922..add8086 100644 --- a/base.lua +++ b/base.lua @@ -172,6 +172,7 @@ local function add_item(data,args) item_layout = args.item_layout or nil , selected = false , overlay = args.overlay or data.overlay or nil , + state = {} , }, force_private = { visible = true, @@ -211,19 +212,22 @@ local function add_item(data,args) data.item_style(data,item,{}) return end - if data._current_item and data._current_item ~= item then - if data._current_item._tmp_menu then - data._current_item._tmp_menu.visible = false - data._current_item._tmp_menu = nil + local current_item = data._current_item + if current_item and current_item ~= item then + current_item.state[module.item_flags.SELECTED] = nil + if current_item._tmp_menu then + current_item._tmp_menu.visible = false + current_item._tmp_menu = nil data._tmp_menu = nil - data.item_style(data,data._current_item,{}) end - data._current_item.selected = false + data.item_style(data,current_item,{}) + current_item.selected = false end - if data.sub_menu_on == module.event.SELECTED and data._current_item ~= item then + if data.sub_menu_on == module.event.SELECTED and current_item ~= item then execute_sub_menu(data,item) end - data.item_style(data,item,{module.item_flags.SELECTED}) + item.state[module.item_flags.SELECTED] = true + data.item_style(data,item,{}) data._current_item = item end if args.selected == true then diff --git a/item_layout/horizontal.lua b/item_layout/horizontal.lua index 466276c..7bf7920 100644 --- a/item_layout/horizontal.lua +++ b/item_layout/horizontal.lua @@ -86,6 +86,7 @@ end function module:setup_hover(item,data) item._internal.set_map.hover = function(value) local item_style = item.item_style or data.item_style + item.state[2] = value and true or nil item_style(data,item,{value and 2--[[HOVER]] or nil,item.selected and 1 or nil}) end end diff --git a/item_style/arrow_alt.lua b/item_style/arrow_alt.lua index 6177e3b..c965de1 100644 --- a/item_style/arrow_alt.lua +++ b/item_style/arrow_alt.lua @@ -102,8 +102,7 @@ local function get_prev(data,item) end local function draw(data,item,args) - local args,flags = args or {},{} - for _,v in pairs(args) do flags[v] = true end + local args = args or {} if item.widget.draw ~= draw_real then item.widget.draw = draw_real item.widget:emit_signal("widget::updated") @@ -115,8 +114,10 @@ local function draw(data,item,args) local prev_color = item.widget.next_color item.widget.next_color = hcode[next_idx] + local state = item.state or {} + local prev_item = get_prev(data,item) - if flags[base.item_flags.SELECTED] or (item._tmp_menu) then + if 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 prev_item.widget.next_color = args.color or data.bg_focus prev_item.widget:emit_signal("widget::updated") diff --git a/item_style/arrow_prefix.lua b/item_style/arrow_prefix.lua index 24cf204..26dddcc 100644 --- a/item_style/arrow_prefix.lua +++ b/item_style/arrow_prefix.lua @@ -54,8 +54,7 @@ local function widget_draw(self, w, cr, width, height) end local function draw(data,item,args) - local args,flags = args or {},{} - for _,v in pairs(args) do flags[v] = true end + local args = args or {} if not item.widget._overlay_init then item.widget._drawprefix = item.widget.draw @@ -81,9 +80,11 @@ local function draw(data,item,args) item._internal.align.third.draw = suffix_draw end - if flags[base.item_flags.SELECTED] or (item._tmp_menu) then + local state = item.state or {} + + if state[base.item_flags.SELECTED] or (item._tmp_menu) then item.widget:set_bg(args.color or data.bg_focus) - elseif flags[base.item_flags.HOVERED] then + elseif state[base.item_flags.HOVERED] then item.widget:set_bg(args.color or data.bg_hover) else item.widget:set_bg(args.color or nil) diff --git a/item_style/arrow_single.lua b/item_style/arrow_single.lua index ad5f8fe..ff88f81 100644 --- a/item_style/arrow_single.lua +++ b/item_style/arrow_single.lua @@ -37,14 +37,15 @@ end local function draw(data,item,args) - local args,flags = args or {},{} - for _,v in pairs(args) do flags[v] = true end + local args = args or {} item.widget.draw = suffix_draw - if flags[base.item_flags.SELECTED] or (item._tmp_menu) then + local state = item.state or {} + + if state[base.item_flags.SELECTED] or (item._tmp_menu) then item.widget:set_bg(args.color or data.bg_focus) - elseif flags[base.item_flags.HOVERED] then + elseif state[base.item_flags.HOVERED] then item.widget:set_bg(args.color or data.bg_hover) else item.widget:set_bg(args.color or nil) diff --git a/item_style/basic.lua b/item_style/basic.lua index c062797..685fb09 100644 --- a/item_style/basic.lua +++ b/item_style/basic.lua @@ -21,8 +21,7 @@ local function widget_draw23(self, w, cr, width, height) end local function draw(data,item,args) - local args,flags = args or {},{} - for _,v in pairs(args) do flags[v] = true end + local args = args or {} if not item.widget._overlay_init and not item.widget._draw then item.widget.__drawbasic = item.widget.draw @@ -30,8 +29,9 @@ local function draw(data,item,args) item.widget._overlay_init = true end + local state = item.state or {} - if flags[base.item_flags.SELECTED] or (item._tmp_menu) then + if state[base.item_flags.SELECTED] or (item._tmp_menu) then item.widget:set_bg(args.color or data.bg_focus) else item.widget:set_bg(args.color or nil) diff --git a/item_style/classic.lua b/item_style/classic.lua index eb581c0..b33ad71 100644 --- a/item_style/classic.lua +++ b/item_style/classic.lua @@ -36,9 +36,8 @@ local function widget_draw(self, w, cr, width, height) end local function draw(data,item,args) - local args,flags = args or {},{} + local args = args or {} local col = args.color - for _,v in pairs(args) do flags[v] = true end if not item.widget._overlay_init then item.widget._draw2 = item.widget.draw @@ -60,7 +59,9 @@ local function draw(data,item,args) alt[col][ih] = gen(ih,color(col),bc) end - if flags[base.item_flags.SELECTED] or (item._tmp_menu) then + local state = item.state or {} + + if state[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]) diff --git a/item_style/rounded.lua b/item_style/rounded.lua index 0b70791..baa1287 100644 --- a/item_style/rounded.lua +++ b/item_style/rounded.lua @@ -41,8 +41,7 @@ local function widget_draw(self, w, cr, width, height) end local function draw(data,item,args) - local args,flags = args or {},{} - for _,v in pairs(args) do flags[v] = true end + local args = args or {} if not item.widget._overlay_init then item.widget._drawrounded = item.widget.draw @@ -60,7 +59,9 @@ local function draw(data,item,args) default [ih] = gen(ih,data.bg,bc) end - if flags[base.item_flags.SELECTED] or (item._tmp_menu) then + local state = item.state or {} + + if state[base.item_flags.SELECTED] or (item._tmp_menu) then item.widget:set_bg(focussed[ih]) else item.widget:set_bg(default[ih])