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:
parent
7e4b6ef81e
commit
f3fb27f464
|
@ -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) |
|
| 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) |
|
| opacity | Make this menu translucent (require a compositor) | number (0 to 1) |
|
||||||
| icon_transformation | Hijack the icon drawing function | function(icon,data,item) |
|
| icon_transformation | Hijack the icon drawing function | function(icon,data,item) |
|
||||||
|
| disable_submenu_icon| Do not show the submenu icon (arrow) | boolean |
|
||||||
|
|
||||||
###Item options
|
###Item options
|
||||||
|
|
||||||
|
|
21
bar.lua
21
bar.lua
|
@ -24,14 +24,14 @@ local function set_position(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Draw the menu background
|
-- Draw the menu background
|
||||||
-- local function bg_draw(self, w, cr, width, height)
|
local function bg_draw(self, w, cr, width, height)
|
||||||
-- cr:save()
|
cr:save()
|
||||||
-- cr:set_source(color(self._data.bg))
|
cr:set_source(color(self._data.bg))
|
||||||
-- cr:rectangle(0,0,width,height)
|
cr:rectangle(0,0,width,height)
|
||||||
-- cr:fill()
|
cr:fill()
|
||||||
-- cr:restore()
|
cr:restore()
|
||||||
-- wibox.layout.margin.draw(self, w, cr, width, height)
|
self._draw(self, w, cr, width, height)
|
||||||
-- end
|
end
|
||||||
|
|
||||||
local function proxy_draw(_,...)
|
local function proxy_draw(_,...)
|
||||||
local l = _._internal and _._internal.layout or _
|
local l = _._internal and _._internal.layout or _
|
||||||
|
@ -48,7 +48,10 @@ local function setup_drawable(data)
|
||||||
local private_data = internal.private_data
|
local private_data = internal.private_data
|
||||||
|
|
||||||
internal.layout = internal.layout_func or wibox.layout.fixed.horizontal()
|
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
|
--Getters
|
||||||
data.get_x = function() return 0 end
|
data.get_x = function() return 0 end
|
||||||
data.get_y = function() return 0 end
|
data.get_y = function() return 0 end
|
||||||
|
|
1
base.lua
1
base.lua
|
@ -305,6 +305,7 @@ local function new(args)
|
||||||
filter_underlay_style = args.filter_underlay_style or nil,
|
filter_underlay_style = args.filter_underlay_style or nil,
|
||||||
filter_underlay_color = args.filter_underlay_color,
|
filter_underlay_color = args.filter_underlay_color,
|
||||||
filter_placeholder = args.filter_placeholder or "",
|
filter_placeholder = args.filter_placeholder or "",
|
||||||
|
disable_submenu_icon = args.disable_submenu_icon or false
|
||||||
},
|
},
|
||||||
force_private = {
|
force_private = {
|
||||||
parent = true,
|
parent = true,
|
||||||
|
|
|
@ -218,14 +218,7 @@ local function setup_buttons(data,item,args)
|
||||||
--Hide on right click
|
--Hide on right click
|
||||||
if not buttons[3] then
|
if not buttons[3] then
|
||||||
buttons[3] = function()
|
buttons[3] = function()
|
||||||
data.visible = false
|
data:hide()
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,7 @@ local function new_item(data,args)
|
||||||
autogen_signals = true,
|
autogen_signals = true,
|
||||||
})
|
})
|
||||||
item._private_data = private_data
|
item._private_data = private_data
|
||||||
item._internal = {}
|
item._internal = args._internal or {}
|
||||||
theme.setup_item_colors(data,item,args)
|
theme.setup_item_colors(data,item,args)
|
||||||
item.get_y = function()
|
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
|
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
|
local current_item = data._current_item
|
||||||
if current_item and current_item ~= item or force then
|
if current_item and current_item ~= item or force then
|
||||||
current_item.state[module.item_flags.SELECTED] = nil
|
current_item.state[module.item_flags.SELECTED] = nil
|
||||||
|
current_item:emit_signal("selected::changed",false)
|
||||||
hide_sub_menu(current_item,data)
|
hide_sub_menu(current_item,data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,10 +49,6 @@ end
|
||||||
-- Setup the item icon
|
-- Setup the item icon
|
||||||
function module:setup_icon(item,data)
|
function module:setup_icon(item,data)
|
||||||
local icon = wibox.widget.imagebox()
|
local icon = wibox.widget.imagebox()
|
||||||
icon.fit = function(...)
|
|
||||||
local w,h = wibox.widget.imagebox.fit(...)
|
|
||||||
return w+3,h
|
|
||||||
end
|
|
||||||
icon._data = data
|
icon._data = data
|
||||||
icon._item = item
|
icon._item = item
|
||||||
icon.set_image = module.set_icon
|
icon.set_image = module.set_icon
|
||||||
|
@ -99,7 +95,7 @@ end
|
||||||
-- Create sub_menu arrows
|
-- Create sub_menu arrows
|
||||||
local sub_arrow = nil
|
local sub_arrow = nil
|
||||||
function module:setup_sub_menu_arrow(item,data)
|
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
|
if not sub_arrow then
|
||||||
sub_arrow = wibox.widget.imagebox() --TODO, make global
|
sub_arrow = wibox.widget.imagebox() --TODO, make global
|
||||||
sub_arrow.fit = function(box, w, h) return sub_arrow._image:get_width(),item.height end
|
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
|
-- Icon
|
||||||
local icon = module:setup_icon(item,data)
|
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)
|
layout:add(icon)
|
||||||
|
|
||||||
-- Prefix
|
-- Prefix
|
||||||
|
|
|
@ -68,14 +68,9 @@ local function create_item(item,data,args)
|
||||||
l:add(args.prefix_widget)
|
l:add(args.prefix_widget)
|
||||||
end
|
end
|
||||||
|
|
||||||
local icon = wibox.widget.imagebox()
|
local icon = horizontal.setup_icon(horizontal,item,data)
|
||||||
icon.fit = function(...) return icon_fit(data,...) end
|
icon.fit = function(...) return icon_fit(data,...) end
|
||||||
icon.draw = icon_draw
|
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(icon)
|
||||||
l:add(text_w)
|
l:add(text_w)
|
||||||
|
|
|
@ -7,6 +7,7 @@ local checkbox = require( "radical.widgets.checkbox" )
|
||||||
local fkey = require( "radical.widgets.fkey" )
|
local fkey = require( "radical.widgets.fkey" )
|
||||||
local underlay = require( "radical.widgets.underlay" )
|
local underlay = require( "radical.widgets.underlay" )
|
||||||
local theme = require( "radical.theme" )
|
local theme = require( "radical.theme" )
|
||||||
|
local horizontal= require( "radical.item.layout.horizontal")
|
||||||
|
|
||||||
local module = {}
|
local module = {}
|
||||||
|
|
||||||
|
@ -37,35 +38,6 @@ function module.paint_underlay(data,item,cr,width,height)
|
||||||
cr:restore()
|
cr:restore()
|
||||||
end
|
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
|
-- Show the checkbox
|
||||||
function module:setup_checked(item,data)
|
function module:setup_checked(item,data)
|
||||||
if item.checkable then
|
if item.checkable then
|
||||||
|
@ -197,7 +169,11 @@ local function create_item(item,data,args)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Icon
|
-- 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)
|
layout:add(icon)
|
||||||
|
|
||||||
-- Prefix
|
-- Prefix
|
||||||
|
|
|
@ -61,7 +61,7 @@ local function draw(item,args)
|
||||||
|
|
||||||
local state = item.state or {}
|
local state = item.state or {}
|
||||||
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 = current_state and base.colors_by_id[current_state] or "normal"
|
||||||
|
|
||||||
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])
|
||||||
|
|
Loading…
Reference in New Issue