Partially implement issue #8

This commit is contained in:
Emmanuel Lepage Vallee 2014-02-05 22:48:26 -05:00
parent 8fa38c2a2c
commit c0c57eff16
6 changed files with 35 additions and 17 deletions

View File

@ -180,7 +180,8 @@ Multiple items can have multiple sets of options.
| disable_markup | Disable pango markup in items text | boolean |
| x | X position (absolute) | number |
| y | Y position (absolute) | number |
| sub_menu_on | Show submenu on selection or when clicking | see "sub_menu_on" enum |
| 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 |
###Item options
@ -229,8 +230,8 @@ here is the list:
| remove | Remove the item | the item | --- |
Menu also emit many signals, the syntax is usually `PROPERTY_NAME::changed`. The exeptions are
`item::moved`, `item::swapped`, `item::removed`
Menu also emit many signals, the syntax is usually `PROPERTY_NAME::changed`. The
exeptions are `item::moved`, `item::swapped`, `item::removed`
###Beautiful options

View File

@ -82,7 +82,7 @@ local function setup_buttons(data,item,args)
end
-- Setup sub_menu
if (item.sub_menu_m or item.sub_menu_f) and data.sub_menu_on >= base.sub_menu_on.BUTTON1 and data.sub_menu_on <= base.sub_menu_on.BUTTON3 then
if (item.sub_menu_m or item.sub_menu_f) and data.sub_menu_on >= base.event.BUTTON1 and data.sub_menu_on <= base.event.BUTTON3 then
buttons[data.sub_menu_on] = item.widget:set_menu(item.sub_menu_m or item.sub_menu_f,data.sub_menu_on)
end
@ -105,8 +105,10 @@ end
local function setup_item(data,item,args)
-- Add widgets
data._internal.layout:add(item_layout(item,data,args))
if data.select_on == base.event.HOVER then
item.widget:connect_signal("mouse::enter", function() item.selected = true end)
item.widget:connect_signal("mouse::leave", function() item.selected = false end)
end
-- Setup buttons
setup_buttons(data,item,args)
@ -121,7 +123,7 @@ local function new(args)
args.internal.setup_item = args.internal.setup_item or setup_item
-- args.style = args.style or arrow_style
args.item_style = item_style
args.sub_menu_on = base.sub_menu_on.BUTTON1
args.sub_menu_on = args.sub_menu_on or base.event.BUTTON1
local ret = base(args)
ret:connect_signal("clear::menu",function(_,vis)
ret._internal.layout:reset()

View File

@ -17,12 +17,14 @@ local module = {
PRETTY = 1,
CENTERED = 2,
},
sub_menu_on ={
event ={
NEVER = 0,
BUTTON1 = 1,
BUTTON2 = 2,
BUTTON3 = 3,
SELECTED = 100,
HOVER = 1000,
LEAVE = 1001,
},
item_flags = {
SELECTED = 1,
@ -101,7 +103,7 @@ local function activateKeyboard(data)
end
if (key == 'Return') and data._current_item and data._current_item.button1 then
if data.sub_menu_on == module.sub_menu_on.BUTTON1 then
if data.sub_menu_on == module.event.BUTTON1 then
execute_sub_menu(data,data._current_item)
else
data._current_item.button1()
@ -199,7 +201,7 @@ local function add_item(data,args)
end
data._current_item.selected = false
end
if data.sub_menu_on == module.sub_menu_on.SELECTED and data._current_item ~= item then
if data.sub_menu_on == module.event.SELECTED and data._current_item ~= item then
execute_sub_menu(data,item)
end
data.item_style(data,item,{module.item_flags.SELECTED})
@ -315,7 +317,8 @@ local function new(args)
disable_markup = args.disable_markup or false,
x = args.x or 0,
y = args.y or 0,
sub_menu_on = args.sub_menu_on or module.sub_menu_on.SELECTED,
sub_menu_on = args.sub_menu_on or module.event.SELECTED,
select_on = args.select_on or module.event.HOVER,
},
get_map = {
is_menu = function() return true end,

View File

@ -183,7 +183,7 @@ local function setup_buttons(data,item,args)
end
-- Click to open sub_menu
if not buttons[1] and data.sub_menu_on == base.sub_menu_on.BUTTON1 then
if not buttons[1] and data.sub_menu_on == base.event.BUTTON1 then
buttons[#buttons+1] = button({},1,function() base._execute_sub_menu(data,item) end)
end

View File

@ -6,6 +6,7 @@ local button = require( "awful.button" )
local checkbox = require( "radical.widgets.checkbox" )
local wibox = require( "wibox" )
local item_layout = require("radical.item_layout.icon")
local base = nil
local module = {}
@ -51,8 +52,10 @@ end
local function setup_event(data,item,args)
--Event handling
if data.select_on == base.event.HOVER then
item.widget:connect_signal("mouse::enter", function() item.selected = true end)
item.widget:connect_signal("mouse::leave", function() item.selected = false end)
end
data._internal.layout:add(item)
local buttons = {}
for i=1,10 do
@ -133,6 +136,9 @@ local function item_fit(data,item,...)
end
local function new(data)
if not base then
base = require( "radical.base" )
end
local l = wibox.layout.fixed.horizontal()
l.fit = function(a1,a2,a3)
local result,r2 = wibox.layout.fixed.fit(a1,99999,99999)

View File

@ -4,6 +4,7 @@ local scroll = require( "radical.widgets.scroll" )
local filter = require( "radical.widgets.filter" )
local wibox = require( "wibox" )
local cairo = require( "lgi" ).cairo
local base = nil
local horizontal_item_layout= require( "radical.item_layout.horizontal" )
local module = {}
@ -123,8 +124,10 @@ function module:setup_item(data,item,args)
cache_pixmap(item)
--Event handling
if data.select_on == base.event.HOVER then
item.widget:connect_signal("mouse::enter", function() item.selected = true end)
item.widget:connect_signal("mouse::leave", function() item.selected = false end)
end
data._internal.layout:add(item)
--Be sure to always hide sub menus, even when data.visible is set manually
@ -202,6 +205,9 @@ local function compute_geo(data)
end
local function new(data)
if not base then
base = require( "radical.base" )
end
local l,real_l = wibox.layout.fixed.vertical(),nil
real_l = wibox.layout.fixed.vertical()
if data.max_items then