#41 Add recursive component removing on druid:remove

This commit is contained in:
Insality 2020-05-08 00:12:48 +03:00
parent bb565432f3
commit 92f95f77d1
2 changed files with 24 additions and 0 deletions

View File

@ -138,6 +138,22 @@ function Component.get_druid(self)
end end
--- Return true, if current component is child of another component
-- @function component:is_child_of
-- @treturn bool True, if current component is child of another
function Component.is_child_of(self, component)
return self:get_context() == component
end
--- Return component name
-- @function component:get_name
-- @treturn string The component name
function Component.get_name(self)
return self._component.name
end
--- Setup component context and his style table --- Setup component context and his style table
-- @function component:setup_component -- @function component:setup_component
-- @tparam druid_instance table The parent druid instance -- @tparam druid_instance table The parent druid instance

View File

@ -170,6 +170,14 @@ end
function Druid.remove(self, component) function Druid.remove(self, component)
local all_components = self.components[const.ALL] local all_components = self.components[const.ALL]
-- Recursive remove all children of component
for i = 1, #all_components do
local inst = all_components[i]
if inst:is_child_of(component) then
self:remove(inst)
end
end
for i = #all_components, 1, -1 do for i = #all_components, 1, -1 do
if all_components[i] == component then if all_components[i] == component then
if component.on_remove then if component.on_remove then