:destroy fix for frame's with childrens with reactive properties
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
local PropertySystem = require("propertySystem")
|
local PropertySystem = require("propertySystem")
|
||||||
local uuid = require("libraries/utils").uuid
|
local uuid = require("libraries/utils").uuid
|
||||||
|
local errorManager = require("errorManager")
|
||||||
---@configDescription The base class for all UI elements in Basalt.
|
---@configDescription The base class for all UI elements in Basalt.
|
||||||
|
|
||||||
--- The base class for all UI elements in Basalt. This class provides basic properties and event handling functionality.
|
--- The base class for all UI elements in Basalt. This class provides basic properties and event handling functionality.
|
||||||
@@ -252,6 +253,9 @@ end
|
|||||||
--- Destroys the element and cleans up all references
|
--- Destroys the element and cleans up all references
|
||||||
--- @shortDescription Destroys the element and cleans up all references
|
--- @shortDescription Destroys the element and cleans up all references
|
||||||
function BaseElement:destroy()
|
function BaseElement:destroy()
|
||||||
|
self._destroyed = true
|
||||||
|
self:removeAllObservers()
|
||||||
|
self:setFocused(false)
|
||||||
for event in pairs(self._registeredEvents) do
|
for event in pairs(self._registeredEvents) do
|
||||||
self:listenEvent(event, false)
|
self:listenEvent(event, false)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ end
|
|||||||
--- @return boolean boolean the child is visible
|
--- @return boolean boolean the child is visible
|
||||||
function Container:isChildVisible(child)
|
function Container:isChildVisible(child)
|
||||||
if(child.get("visible") == false)then return false end
|
if(child.get("visible") == false)then return false end
|
||||||
|
if(child._destroyed)then return false end
|
||||||
local containerW, containerH = self.get("width"), self.get("height")
|
local containerW, containerH = self.get("width"), self.get("height")
|
||||||
local offsetX, offsetY = self.get("offsetX"), self.get("offsetY")
|
local offsetX, offsetY = self.get("offsetX"), self.get("offsetY")
|
||||||
|
|
||||||
@@ -273,7 +274,7 @@ end
|
|||||||
function Container:unregisterChildEvent(child, eventName)
|
function Container:unregisterChildEvent(child, eventName)
|
||||||
if self._values.childrenEvents[eventName] then
|
if self._values.childrenEvents[eventName] then
|
||||||
for i, listener in ipairs(self._values.childrenEvents[eventName]) do
|
for i, listener in ipairs(self._values.childrenEvents[eventName]) do
|
||||||
if listener == child then
|
if listener.get("id") == child.get("id") then
|
||||||
table.remove(self._values.childrenEvents[eventName], i)
|
table.remove(self._values.childrenEvents[eventName], i)
|
||||||
self._values.eventListenerCount[eventName] = self._values.eventListenerCount[eventName] - 1
|
self._values.eventListenerCount[eventName] = self._values.eventListenerCount[eventName] - 1
|
||||||
|
|
||||||
@@ -300,7 +301,8 @@ end
|
|||||||
--- @return Container self The container instance
|
--- @return Container self The container instance
|
||||||
function Container:removeChild(child)
|
function Container:removeChild(child)
|
||||||
for i,v in ipairs(self._values.children) do
|
for i,v in ipairs(self._values.children) do
|
||||||
if v == child then
|
if v.get("id") == child.get("id") then
|
||||||
|
self.basalt.LOGGER.debug("Removing child: "..child:getType())
|
||||||
table.remove(self._values.children, i)
|
table.remove(self._values.children, i)
|
||||||
child.parent = nil
|
child.parent = nil
|
||||||
break
|
break
|
||||||
@@ -676,11 +678,14 @@ end
|
|||||||
|
|
||||||
--- @private
|
--- @private
|
||||||
function Container:destroy()
|
function Container:destroy()
|
||||||
for _, child in ipairs(self._values.children) do
|
if not self:isType("BaseFrame") then
|
||||||
child:destroy()
|
self.set("childrenSorted", false)
|
||||||
|
VisualElement.destroy(self)
|
||||||
|
return self
|
||||||
|
else
|
||||||
|
errorManager.header = "Basalt Error"
|
||||||
|
errorManager.error("Cannot destroy a BaseFrame.")
|
||||||
end
|
end
|
||||||
VisualElement.destroy(self)
|
|
||||||
return self
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Container
|
return Container
|
||||||
@@ -405,7 +405,7 @@ end
|
|||||||
|
|
||||||
--- Removes all observers from a property
|
--- Removes all observers from a property
|
||||||
--- @shortDescription Removes all observers from a property
|
--- @shortDescription Removes all observers from a property
|
||||||
--- @param name string The name of the property
|
--- @param name? string The name of the property
|
||||||
--- @return table self The PropertySystem
|
--- @return table self The PropertySystem
|
||||||
function PropertySystem:removeAllObservers(name)
|
function PropertySystem:removeAllObservers(name)
|
||||||
if name then
|
if name then
|
||||||
|
|||||||
Reference in New Issue
Block a user