Merge pull request #3284 from sclu1034/issue/3213

Fix composite widgets with top level container
This commit is contained in:
Emmanuel Lepage Vallée 2021-03-28 16:00:16 -07:00 committed by GitHub
commit 13e8408562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 21 deletions

View File

@ -533,32 +533,34 @@ local function drill(ids, content)
end end
end end
-- Add all widgets. if widgets and max > 0 then
for k = 1, max do -- Add all widgets.
-- ipairs cannot be used on sparse tables. for k = 1, max do
local v, id2, e = widgets[k], id, nil -- ipairs cannot be used on sparse tables.
if v then local v, id2, e = widgets[k], id, nil
-- It is another declarative container, parse it. if v then
if (not v.is_widget) and (v.widget or v.layout) then -- It is another declarative container, parse it.
e, id2 = drill(ids, v) if (not v.is_widget) and (v.widget or v.layout) then
widgets[k] = e e, id2 = drill(ids, v)
elseif (not v.is_widget) and is_callable(v) then widgets[k] = e
widgets[k] = v() elseif (not v.is_widget) and is_callable(v) then
end widgets[k] = v()
base.check_widget(widgets[k]) end
base.check_widget(widgets[k])
-- Place the widget in the access table. -- Place the widget in the access table.
if id2 then if id2 then
l [id2] = e l [id2] = e
ids[id2] = ids[id2] or {} ids[id2] = ids[id2] or {}
table.insert(ids[id2], e) table.insert(ids[id2], e)
end
end end
end end
end
-- Replace all children (if any) with the new ones. -- Replace all children (if any) with the new ones.
if widgets then
l:set_children(widgets) l:set_children(widgets)
end end
return l, id return l, id
end end

View File

@ -3,13 +3,60 @@
-- @copyright 2017 Uli Schlachter -- @copyright 2017 Uli Schlachter
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
local base = require('wibox.widget.base')
local margin = require("wibox.container.margin") local margin = require("wibox.container.margin")
local imagebox = require("wibox.widget.imagebox")
local utils = require("wibox.test_utils") local utils = require("wibox.test_utils")
describe("wibox.container.margin", function() describe("wibox.container.margin", function()
it("common interfaces", function() it("common interfaces", function()
utils.test_container(margin()) utils.test_container(margin())
end) end)
describe("composite widgets", function()
it("can be wrapped with child", function()
local widget_name = "test_widget"
local new = function()
local ret = base.make_widget_declarative {
{
id = "img",
widget = imagebox,
},
widget = margin,
}
ret.widget_name = widget_name
return ret
end
local widget = base.make_widget_declarative {
widget = new,
}
assert.is.equal(
widget_name,
widget.widget_name,
"Widget name doesn't match"
)
local children = widget:get_children()
assert.is_not.Nil(children, "Widget doesn't have children")
assert.is.equal(
1,
#children,
"Widget should have exactly one child"
)
assert.is.True(
children[1].is_widget,
"Child widget should be a valid widget"
)
assert.is.equal(
widget.img,
children[1],
"Child widget should match the id accessor"
)
end)
end)
end) end)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80