Fix minor bugs

* Add hide() method to hide a menu and all sub menu (compared to set_visible)
* Add option to have sub_menu arrows
* Fix selected::changed not being emited in some cases
* Remove duplicated code from notification layout
This commit is contained in:
Emmanuel Lepage Vallee 2014-08-08 02:02:37 -04:00
parent 7e4b6ef81e
commit f3fb27f464
9 changed files with 30 additions and 60 deletions

View File

@ -192,6 +192,7 @@ Multiple items can have multiple sets of options.
| overlay | A layer on top of the item | function(data,item,cr,w,h) |
| opacity | Make this menu translucent (require a compositor) | number (0 to 1) |
| icon_transformation | Hijack the icon drawing function | function(icon,data,item) |
| disable_submenu_icon| Do not show the submenu icon (arrow) | boolean |
###Item options

21
bar.lua
View File

@ -24,14 +24,14 @@ local function set_position(self)
end
-- Draw the menu background
-- local function bg_draw(self, w, cr, width, height)
-- cr:save()
-- cr:set_source(color(self._data.bg))
-- cr:rectangle(0,0,width,height)
-- cr:fill()
-- cr:restore()
-- wibox.layout.margin.draw(self, w, cr, width, height)
-- end
local function bg_draw(self, w, cr, width, height)
cr:save()
cr:set_source(color(self._data.bg))
cr:rectangle(0,0,width,height)
cr:fill()
cr:restore()
self._draw(self, w, cr, width, height)
end
local function proxy_draw(_,...)
local l = _._internal and _._internal.layout or _
@ -48,7 +48,10 @@ local function setup_drawable(data)
local private_data = internal.private_data
internal.layout = internal.layout_func or wibox.layout.fixed.horizontal()
internal.layout._draw = internal.layout.draw
internal.layout.draw = bg_draw
internal.layout._data = data
--Getters
data.get_x = function() return 0 end
data.get_y = function() return 0 end

View File

@ -305,6 +305,7 @@ local function new(args)
filter_underlay_style = args.filter_underlay_style or nil,
filter_underlay_color = args.filter_underlay_color,
filter_placeholder = args.filter_placeholder or "",
disable_submenu_icon = args.disable_submenu_icon or false
},
force_private = {
parent = true,

View File

@ -218,14 +218,7 @@ local function setup_buttons(data,item,args)
--Hide on right click
if not buttons[3] then
buttons[3] = function()
data.visible = false
if data.parent_geometry and data.parent_geometry.is_menu then
local parent = data.parent_geometry
while parent do
parent.visible = false
parent = parent.parent_geometry and parent.parent_geometry.is_menu and parent.parent_geometry
end
end
data:hide()
end
end

View File

@ -129,7 +129,7 @@ local function new_item(data,args)
autogen_signals = true,
})
item._private_data = private_data
item._internal = {}
item._internal = args._internal or {}
theme.setup_item_colors(data,item,args)
item.get_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 --Hack around missing :fit call for last item
@ -174,6 +174,7 @@ local function new_item(data,args)
local current_item = data._current_item
if current_item and current_item ~= item or force then
current_item.state[module.item_flags.SELECTED] = nil
current_item:emit_signal("selected::changed",false)
hide_sub_menu(current_item,data)
end

View File

@ -49,10 +49,6 @@ end
-- Setup the item icon
function module:setup_icon(item,data)
local icon = wibox.widget.imagebox()
icon.fit = function(...)
local w,h = wibox.widget.imagebox.fit(...)
return w+3,h
end
icon._data = data
icon._item = item
icon.set_image = module.set_icon
@ -99,7 +95,7 @@ end
-- Create sub_menu arrows
local sub_arrow = nil
function module:setup_sub_menu_arrow(item,data)
if item._private_data.sub_menu_f or item._private_data.sub_menu_m then
if (item._private_data.sub_menu_f or item._private_data.sub_menu_m) and not data.disable_submenu_icon then
if not sub_arrow then
sub_arrow = wibox.widget.imagebox() --TODO, make global
sub_arrow.fit = function(box, w, h) return sub_arrow._image:get_width(),item.height end
@ -197,6 +193,10 @@ local function create_item(item,data,args)
-- Icon
local icon = module:setup_icon(item,data)
icon.fit = function(...)
local w,h = wibox.widget.imagebox.fit(...)
return w+3,h
end
layout:add(icon)
-- Prefix

View File

@ -68,14 +68,9 @@ local function create_item(item,data,args)
l:add(args.prefix_widget)
end
local icon = wibox.widget.imagebox()
local icon = horizontal.setup_icon(horizontal,item,data)
icon.fit = function(...) return icon_fit(data,...) end
icon.draw = icon_draw
icon._data = data
icon.set_image = horizontal.set_icon
if args.icon then
icon:set_image(args.icon)
end
l:add(icon)
l:add(text_w)

View File

@ -7,6 +7,7 @@ local checkbox = require( "radical.widgets.checkbox" )
local fkey = require( "radical.widgets.fkey" )
local underlay = require( "radical.widgets.underlay" )
local theme = require( "radical.theme" )
local horizontal= require( "radical.item.layout.horizontal")
local module = {}
@ -37,35 +38,6 @@ function module.paint_underlay(data,item,cr,width,height)
cr:restore()
end
-- Apply icon transformation
function module.set_icon(self,image)
if self._data.icon_transformation then
self._item._original_icon = image
image = self._data.icon_transformation(image,self._data,self._item)
end
wibox.widget.imagebox.set_image(self,image)
end
-- Setup the item icon
function module:setup_icon(item,data)
local icon = wibox.widget.imagebox()
icon.fit = function(...)
local w,h = wibox.widget.imagebox.fit(...)
return w+3,h
end
icon._data = data
icon._item = item
icon.set_image = module.set_icon
if item.icon then
icon:set_image(item.icon)
end
item.set_icon = function (_,value)
icon:set_image(value)
end
return icon
end
-- Show the checkbox
function module:setup_checked(item,data)
if item.checkable then
@ -197,7 +169,11 @@ local function create_item(item,data,args)
end
-- Icon
local icon = module:setup_icon(item,data)
local icon = horizontal.setup_icon(horizontal,item,data)
icon.fit = function(...)
local w,h = wibox.widget.imagebox.fit(...)
return w+3,h
end
layout:add(icon)
-- Prefix

View File

@ -61,7 +61,7 @@ local function draw(item,args)
local state = item.state or {}
local current_state = state._current_key or nil
local state_name = base.colors_by_id[current_state]
local state_name = current_state and base.colors_by_id[current_state] or "normal"
if current_state == base.item_flags.SELECTED or (item._tmp_menu) then
item.widget:set_bg(focussed[ih])