Fix composite widgets with top level container

When wrapping container widgets to create reusable composite widgets,
`drill` will be called twice on the same widget definition. The first
call happens within the wrapping function and applies the children
widgets fine. The second call happens when the composite widget is used,
but since there are no children widgets defined, the call to
`set_children` sets the existing child to `nil` instead.

Fixes #3213.

Signed-off-by: Lucas Schwiderski <lucas@lschwiderski.de>
This commit is contained in:
Lucas Schwiderski 2021-03-10 19:39:47 +01:00
parent aba1cf398f
commit 7bc3ec4c35
No known key found for this signature in database
GPG Key ID: AA12679AAA6DF4D8
1 changed files with 23 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