Merge pull request #737 from Elv13/minor_widget_enhancements

wibox.widget: Minor enhancements
This commit is contained in:
Emmanuel Lepage Vallée 2016-03-04 04:24:34 -05:00
commit 249a3f7ce0
3 changed files with 20 additions and 4 deletions

View File

@ -164,9 +164,17 @@ function fixed:swap_widgets(widget1, widget2, recursive)
local idx1, l1 = self:index(widget1, recursive) local idx1, l1 = self:index(widget1, recursive)
local idx2, l2 = self:index(widget2, recursive) local idx2, l2 = self:index(widget2, recursive)
if idx1 and l1 and idx2 and l2 then if idx1 and l1 and idx2 and l2 and (l1.set or l1.set_widget) and (l2.set or l2.set_widget) then
l1:set(idx1, widget2) if l1.set then
l2:set(idx2, widget1) l1:set(idx1, widget2)
elseif l1.set_widget then
l1:set_widget(widget2)
end
if l2.set then
l2:set(idx2, widget1)
elseif l2.set_widget then
l2:set_widget(widget1)
end
return true return true
end end

View File

@ -215,6 +215,14 @@ function ratio:set_ratio(index, percent)
self:emit_signal("widget::layout_changed") self:emit_signal("widget::layout_changed")
end end
--- The the ratio at `index`
-- @tparam number index The widget index to query
-- @treturn number The index (between 0 and 1)
function ratio:get_ratio(index)
if not index then return end
return self._ratios[index]
end
--- Set the ratio of "widget" --- Set the ratio of "widget"
-- @param widget The widget to ajust -- @param widget The widget to ajust
-- @tparam number percent An floating point value between 0 and 1 -- @tparam number percent An floating point value between 0 and 1

View File

@ -460,7 +460,7 @@ function base.make_widget_declarative(args)
rawset(w, "get_children_by_id", get_children_by_id) rawset(w, "get_children_by_id", get_children_by_id)
mt.__tostring = function() mt.__tostring = function()
return string.format("%s (%s)", id, orig_string) return string.format("%s (%s)", id or w.widget_name or "N/A", orig_string)
end end
return setmetatable(w, mt) return setmetatable(w, mt)