wibox.widget: Minor enhancements
* Better widget names when using the declarative syntax * Add ratio.get_ratio to avoid using the private API * Also support `set_widget` when swapping widgets
This commit is contained in:
parent
7c7295a282
commit
78ed3abe1a
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue