Add sub_menu_on option
This commit is contained in:
parent
5ff71f7385
commit
4e54b38991
|
@ -125,7 +125,7 @@ Multiple items can have multiple sets of options.
|
||||||
| icon_size | Icon size | number |
|
| icon_size | Icon size | number |
|
||||||
| auto_resize | Resize menu if items are too large | boolean |
|
| auto_resize | Resize menu if items are too large | boolean |
|
||||||
| parent_geometry | Set the menu parent | geometry array |
|
| parent_geometry | Set the menu parent | geometry array |
|
||||||
| arrow_type | Set the arrow type when use arrow style | see "arrow_type" |
|
| arrow_type | Set the arrow type when use arrow style | see "arrow_type" enum |
|
||||||
| visible | Show or hide the menu | boolean |
|
| visible | Show or hide the menu | boolean |
|
||||||
| direction | The direction from which the arrow will point | "left","right","top","bottom" |
|
| direction | The direction from which the arrow will point | "left","right","top","bottom" |
|
||||||
| row | Number of row (in grid layout) | number |
|
| row | Number of row (in grid layout) | number |
|
||||||
|
@ -144,6 +144,7 @@ Multiple items can have multiple sets of options.
|
||||||
| disable_markup | Disable pango markup in items text | boolean |
|
| disable_markup | Disable pango markup in items text | boolean |
|
||||||
| x | X position (absolute) | number |
|
| x | X position (absolute) | number |
|
||||||
| y | Y position (absolute) | number |
|
| y | Y position (absolute) | number |
|
||||||
|
| sub_menu_on | Show submenu on selection or when clicking | see "sub_menu_on" enum |
|
||||||
|
|
||||||
###Item options
|
###Item options
|
||||||
|
|
||||||
|
|
5
bar.lua
5
bar.lua
|
@ -93,6 +93,11 @@ local function create_item(item,data)
|
||||||
m:set_widget(layout)
|
m:set_widget(layout)
|
||||||
|
|
||||||
-- Content
|
-- Content
|
||||||
|
if item.icon then
|
||||||
|
local icon = wibox.widget.imagebox()
|
||||||
|
icon:set_image(item.icon)
|
||||||
|
layout:add(icon)
|
||||||
|
end
|
||||||
local tb = wibox.widget.textbox()
|
local tb = wibox.widget.textbox()
|
||||||
layout:add(tb)
|
layout:add(tb)
|
||||||
item.widget = bg
|
item.widget = bg
|
||||||
|
|
48
base.lua
48
base.lua
|
@ -16,11 +16,13 @@ local module = {
|
||||||
CENTERED = 2,
|
CENTERED = 2,
|
||||||
},
|
},
|
||||||
sub_menu_on ={
|
sub_menu_on ={
|
||||||
SELECTED = 0,
|
NEVER = 0,
|
||||||
CLICKED = 1,
|
BUTTON1 = 1,
|
||||||
NEVER = 2,
|
BUTTON2 = 2,
|
||||||
}
|
BUTTON3 = 3,
|
||||||
}}
|
SELECTED = 100,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
local function filter(data)
|
local function filter(data)
|
||||||
if not data.filter == false then
|
if not data.filter == false then
|
||||||
|
@ -44,6 +46,21 @@ local function filter(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function execute_sub_menu(data,item)
|
||||||
|
if (item._private_data.sub_menu_f or item._private_data.sub_menu_m) then
|
||||||
|
local sub_menu = item._private_data.sub_menu_m or item._private_data.sub_menu_f()
|
||||||
|
if sub_menu and sub_menu.rowcount > 0 then
|
||||||
|
sub_menu.arrow_type = module.arrow_type.NONE
|
||||||
|
sub_menu.parent_item = item
|
||||||
|
sub_menu.parent_geometry = data
|
||||||
|
sub_menu.visible = true
|
||||||
|
item._tmp_menu = sub_menu
|
||||||
|
data._tmp_menu = sub_menu
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
module._execute_sub_menu = execute_sub_menu
|
||||||
|
|
||||||
------------------------------------KEYBOARD HANDLING-----------------------------------
|
------------------------------------KEYBOARD HANDLING-----------------------------------
|
||||||
local function activateKeyboard(data)
|
local function activateKeyboard(data)
|
||||||
if not data then return end
|
if not data then return end
|
||||||
|
@ -75,8 +92,12 @@ local function activateKeyboard(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (key == 'Return') and data._current_item and data._current_item.button1 then
|
if (key == 'Return') and data._current_item and data._current_item.button1 then
|
||||||
data._current_item.button1()
|
if data.sub_menu_on == module.sub_menu_on.BUTTON1 then
|
||||||
data.visible = false
|
execute_sub_menu(data,data._current_item)
|
||||||
|
else
|
||||||
|
data._current_item.button1()
|
||||||
|
data.visible = false
|
||||||
|
end
|
||||||
elseif key == 'Escape' or (key == 'Tab' and data.filter_string == "") then
|
elseif key == 'Escape' or (key == 'Tab' and data.filter_string == "") then
|
||||||
data.visible = false
|
data.visible = false
|
||||||
capi.keygrabber.stop()
|
capi.keygrabber.stop()
|
||||||
|
@ -154,16 +175,8 @@ local function add_item(data,args)
|
||||||
end
|
end
|
||||||
data._current_item.selected = false
|
data._current_item.selected = false
|
||||||
end
|
end
|
||||||
if (private_data.sub_menu_f or private_data.sub_menu_m)and data._current_item ~= item then
|
if data.sub_menu_on == module.sub_menu_on.SELECTED and data._current_item ~= item then
|
||||||
local sub_menu = private_data.sub_menu_m or private_data.sub_menu_f()
|
execute_sub_menu(data,item)
|
||||||
if sub_menu and sub_menu.rowcount > 0 then
|
|
||||||
sub_menu.arrow_type = module.arrow_type.NONE
|
|
||||||
sub_menu.parent_item = item
|
|
||||||
sub_menu.parent_geometry = data
|
|
||||||
sub_menu.visible = true
|
|
||||||
item._tmp_menu = sub_menu
|
|
||||||
data._tmp_menu = sub_menu
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
data.item_style(data,item,true,false)
|
data.item_style(data,item,true,false)
|
||||||
data._current_item = item
|
data._current_item = item
|
||||||
|
@ -274,6 +287,7 @@ local function new(args)
|
||||||
disable_markup = args.disable_markup or false,
|
disable_markup = args.disable_markup or false,
|
||||||
x = args.x or 0,
|
x = args.x or 0,
|
||||||
y = args.y or 0,
|
y = args.y or 0,
|
||||||
|
sub_menu_on = args.sub_menu_on or module.sub_menu_on.SELECTED,
|
||||||
},
|
},
|
||||||
get_map = {
|
get_map = {
|
||||||
is_menu = function() return true end,
|
is_menu = function() return true end,
|
||||||
|
|
13
context.lua
13
context.lua
|
@ -173,7 +173,14 @@ local function setup_item(data,item,args)
|
||||||
buttons[#buttons+1] = button({},i,args["button"..i])
|
buttons[#buttons+1] = button({},i,args["button"..i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not buttons[3] then --Hide on right click
|
|
||||||
|
-- Click to open sub_menu
|
||||||
|
if not buttons[1] and data.sub_menu_on == base.sub_menu_on.BUTTON1 then
|
||||||
|
buttons[#buttons+1] = button({},1,function() base._execute_sub_menu(data,item) end)
|
||||||
|
end
|
||||||
|
|
||||||
|
--Hide on right click
|
||||||
|
if not buttons[3] then
|
||||||
buttons[#buttons+1] = button({},3,function()
|
buttons[#buttons+1] = button({},3,function()
|
||||||
data.visible = false
|
data.visible = false
|
||||||
if data.parent_geometry and data.parent_geometry.is_menu then
|
if data.parent_geometry and data.parent_geometry.is_menu then
|
||||||
|
@ -181,11 +188,15 @@ local function setup_item(data,item,args)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Scroll up
|
||||||
if not buttons[4] then
|
if not buttons[4] then
|
||||||
buttons[#buttons+1] = button({},4,function()
|
buttons[#buttons+1] = button({},4,function()
|
||||||
data:scroll_up()
|
data:scroll_up()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Scroll down
|
||||||
if not buttons[5] then
|
if not buttons[5] then
|
||||||
buttons[#buttons+1] = button({},5,function()
|
buttons[#buttons+1] = button({},5,function()
|
||||||
data:scroll_down()
|
data:scroll_down()
|
||||||
|
|
Loading…
Reference in New Issue