Add :set_menu function to all widgets
This commit is contained in:
parent
55f1b2a0c1
commit
4af6f6387b
|
@ -95,8 +95,15 @@ On top of each styles, menu can also have different layouts to display items:
|
|||
item_style = radical.item_style.classic ,
|
||||
layout = radical.layout.vertical })
|
||||
|
||||
-- To add the menu to a widget:
|
||||
local mytextbox = wibox.widget.textbox()
|
||||
mytextbox:set_menu(m,3) -- 3 = right mouse button, 1 = left mouse button
|
||||
|
||||
```
|
||||
|
||||
Please note that `:set_menu` can also take a lazy-loading function instead of a
|
||||
menu. The second parameter is not mandatory, the default is "1".
|
||||
|
||||
### Tooltip
|
||||
|
||||
Radical also have its own styled tooltip widget. It can be used in menus, but
|
||||
|
|
29
init.lua
29
init.lua
|
@ -1,18 +1,41 @@
|
|||
local base = require( "wibox.widget.base" )
|
||||
local tooltip = require( "radical.tooltip" )
|
||||
local type = type
|
||||
local base = require( "wibox.widget.base" )
|
||||
local tooltip = require( "radical.tooltip" )
|
||||
local aw_button = require( "awful.button" )
|
||||
|
||||
-- Define some wibox.widget extensions
|
||||
local function set_tooltip(self, text)
|
||||
print("HERE",text)
|
||||
if not text then return end
|
||||
self._tooltip = tooltip(self,text)
|
||||
end
|
||||
|
||||
local function set_menu(self,menu,button)
|
||||
if not menu then return end
|
||||
local b,current,bt = button or 1,self:buttons(),aw_button({},b,function(geo)
|
||||
local m = menu
|
||||
if type(menu) == "function" then
|
||||
if self._tmp_menu and self._tmp_menu.visible then
|
||||
self._tmp_menu.visible = false
|
||||
self._tmp_menu = nil
|
||||
return
|
||||
end
|
||||
m = menu(self)
|
||||
end
|
||||
if not m then return end
|
||||
m.parent_geometry = geo
|
||||
m.visible = not m.visible
|
||||
end)
|
||||
for k, v in pairs(bt) do
|
||||
current[type(k) == "number" and (#current+1) or k] = v
|
||||
end
|
||||
end
|
||||
|
||||
-- Do some monkey patching to extend all wibox.widget
|
||||
base._make_widget =base.make_widget
|
||||
base.make_widget = function(...)
|
||||
local ret = base._make_widget(...)
|
||||
ret.set_tooltip = set_tooltip
|
||||
ret.set_menu = set_menu
|
||||
return ret
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue