Add partial dynamic overlay support

This will require a better event API to be useful, including issue #10
This commit is contained in:
Emmanuel Lepage Vallee 2014-02-12 23:09:55 -05:00
parent 76623695e6
commit 9205d9f27a
6 changed files with 37 additions and 13 deletions

View File

@ -184,6 +184,7 @@ Multiple items can have multiple sets of options.
| y | Y position (absolute) | number |
| sub_menu_on | Show submenu on selection or when clicking | see "event" enum |
| select_on | The event used to trigger item selection | see "event" enum |
| overlay | A layer on top of the item | function(data,item,cr,w,h) |
###Item options
@ -211,6 +212,7 @@ Multiple items can have multiple sets of options.
| button3 | Right mouse button action | function |
| button4 | Scroll up action | function |
| button5 | Scroll down action | function |
| overlay | See menu.overlay | function |
###Common methods

View File

@ -27,14 +27,17 @@ local module = {
LEAVE = 1001,
},
item_flags = {
NONE = 0,
SELECTED = 1, -- Single item selected
HOVERED = 2, -- Mouse hover
PRESSED = 3, -- Mouse pressed
URGENT = 4, -- Need attention
USED = 5, -- Common flag
DISABLED = 6, -- Cannot be interacted with
CHECKED = 7, -- When checkbox isn't enough
NONE = 0 ,
SELECTED = 1 , -- Single item selected [[FOCUS]]
HOVERED = 2 , -- Mouse hover
PRESSED = 3 , -- Mouse pressed
URGENT = 4 , -- Need attention
USED = 5 , -- Common flag
DISABLED = 6 , -- Cannot be interacted with
CHECKED = 7 , -- When checkbox isn't enough
ALTERNATE = 8 ,
HIGHLIGHT = 9 ,
HEADER = 10,
-- Implementation defined flags
USR1 = 101,
@ -167,7 +170,8 @@ local function add_item(data,args)
tooltip = args.tooltip or nil ,
item_style = args.item_style or nil ,
item_layout = args.item_layout or nil ,
selected = false,
selected = false ,
overlay = args.overlay or data.overlay or nil ,
},
force_private = {
visible = true,
@ -336,6 +340,7 @@ local function new(args)
y = args.y or 0,
sub_menu_on = args.sub_menu_on or module.event.SELECTED,
select_on = args.select_on or module.event.HOVER,
overlay = args.overlay or nil,
},
get_map = {
is_menu = function() return true end,

View File

@ -28,12 +28,14 @@ local state = {
local cache = setmetatable({}, { __mode = 'k' })
local function create_item(t,s)
local item = instances[s]:add_item { text = t.name, icon = tag.geticon(t), button1 = function()
local menu = instances[s]
if not menu then return end
local item = menu:add_item { text = t.name, icon = tag.geticon(t), button1 = function()
tag.viewonly(t)
end}
item._internal.set_map.used = function(value)
local item_style = item.item_style or instances[s].item_style
item_style(instances[s],item,{value and radical.base.item_flags.USED or nil,item.selected and 1 or nil})
local item_style = item.item_style or menu.item_style
item_style(menu,item,{value and radical.base.item_flags.USED or nil,item.selected and 1 or nil})
end
item._internal.screen = s
cache[t] = item
@ -96,6 +98,7 @@ local function init()
item.icon = tag.geticon(t)
end
end)
is_init = true
end
local function new(s)

View File

@ -119,7 +119,10 @@ local function new(screen)
fg = beautiful.fg_normal,
bg_focus = beautiful.taglist_bg_image_selected2 or beautiful.bg_focus,
bg_hover = beautiful.menu_bg_focus,
disable_markup = true
disable_markup = true,
overlay = function(data,item,cd,w,h)
print("foo!")
end
}
-- Clear the menu and repopulate it

View File

@ -196,10 +196,17 @@ local function create_item(item,data,args)
-- Set widget
item.widget = bg
bg._item = item
-- Tooltip
item.widget:set_tooltip(item.tooltip)
-- Overlay
item._internal.set_map.overlay = function(value)
item._private_data.overlay = value
item.widget:emit_signal("widget::updated")
end
-- Draw
local item_style = item.item_style or data.item_style
item_style(data,item,{})

View File

@ -28,6 +28,10 @@ local function suffix_draw(self, w, cr, width, height)
cr:close_path()
cr:clip()
wibox.widget.background.draw(self, w, cr, width, height)
local overlay = self._item and self._item.overlay
if overlay then
overlay(self._item._menu,self._item,cr,width,height)
end
cr:restore()
end