Add :set_tooltip() method to all wibox.widgets

This commit is contained in:
Emmanuel Lepage Vallee 2014-01-04 16:51:50 -05:00
parent 4e54b38991
commit 55f1b2a0c1
7 changed files with 63 additions and 20 deletions

View File

@ -65,9 +65,9 @@ be created by beautiful themes. The current ones are:
Arrow also have a few types:
* radical.base.NONE
* radical.base.PRETTY
* radical.base.CENTERED
* radical.base.arrow_type.NONE
* radical.base.arrow_type.PRETTY
* radical.base.arrow_type.CENTERED
### Item style
@ -97,6 +97,18 @@ On top of each styles, menu can also have different layouts to display items:
```
### Tooltip
Radical also have its own styled tooltip widget. It can be used in menus, but
also in every widgets using the `set_tooltip` method:
```lua
local mytextbox = wibox.widget.textbox()
mytextbox:set_tooltip("foo bar")
```
## Options
Radical offer a (very, very) wide range of options to allow the creation of rich
@ -164,6 +176,7 @@ Multiple items can have multiple sets of options.
| underlay | Text to render at the far-right of the item | string |
| prefix_widget | Widget to append at the begenning of the item| widget |
| suffix_widget | Widget to append at the end of the item | widget |
| tooltip | A tooltip shown on the side or bottom | string |
| button1 | Left mouse button action | function |
| button2 | Mid mouse button action | function |
| button3 | Right mouse button action | function |

View File

@ -103,6 +103,9 @@ local function create_item(item,data)
item.widget = bg
tb:set_text("bob")
-- Tooltip
item.widget:set_tooltip(item.tooltip)
-- Draw
data.item_style(data,item,false,false)
item.widget:set_fg(item._private_data.fg)

View File

@ -135,8 +135,9 @@ local function add_item(data,args)
sub_menu_f = (args.sub_menu and type(args.sub_menu) == "function") and args.sub_menu or nil,
selected = false,
checkable = args.checkable or (args.checked ~= nil) or false,
checked = args.checked or false,
checked = args.checked or false,
underlay = args.underlay or nil,
tooltip = args.tooltip or nil,
},
force_private = {
visible = true,

View File

@ -203,6 +203,7 @@ local function setup_item(data,item,args)
end)
end
item.widget:buttons( util.table.join(unpack(buttons)))
item.widget:set_tooltip(item.tooltip)
end
local function new(args)

View File

@ -1,14 +1,33 @@
local base = require( "wibox.widget.base" )
local tooltip = require( "radical.tooltip" )
-- 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
-- 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
return ret
end
return {
layout = require( "radical.layout" ),
object = require( "radical.object" ),
base = require( "radical.base" ),
radial = require( "radical.radial" ),
context = require( "radical.context" ),
embed = require( "radical.embed" ),
box = require( "radical.box" ),
bar = require( "radical.bar" ),
style = require( "radical.style" ),
item_style = require( "radical.item_style" ),
widgets = require( "radical.widgets" ),
tooltip = require( "radical.tooltip" )
}
layout = require( "radical.layout" ),
object = require( "radical.object" ),
base = require( "radical.base" ),
radial = require( "radical.radial" ),
context = require( "radical.context" ),
embed = require( "radical.embed" ),
box = require( "radical.box" ),
bar = require( "radical.bar" ),
style = require( "radical.style" ),
item_style = require( "radical.item_style" ),
widgets = require( "radical.widgets" ),
tooltip = tooltip
}
-- kate: space-indent on; indent-width 2; replace-tabs on;

View File

@ -190,6 +190,9 @@ function module:setup_item(data,item,args)
icon:set_image(value)
end
item._internal.set_map.text(item._private_data.text)
-- Setup tooltip
item.widget:set_tooltip(item.tooltip)
end
--Get preferred item geometry

View File

@ -225,7 +225,7 @@ function module:setup_item(data,item,args)
-- end
end
end
item._internal.set_map.f_key = function(value)
item._internal.has_changed = true
item._internal.f_key = value
@ -236,17 +236,20 @@ function module:setup_item(data,item,args)
end)
end
item._internal.get_map.f_key = function() return item._internal.f_key end
item._internal.set_map.icon = function (value)
icon:set_image(value)
end
item._internal.set_map.text(item._private_data.text)
if data._internal.scroll_w and data.rowcount > data.max_items then
data._internal.scroll_w.visible = true
data._internal.scroll_w["up"]:emit_signal("widget::updated")
data._internal.scroll_w["down"]:emit_signal("widget::updated")
end
-- Setup tooltip
item.widget:set_tooltip(item.tooltip)
end
local function compute_geo(data)