2021-08-30 14:11:08 +02:00
|
|
|
local Parent = require "birb.modules.gui.elements.parent"
|
|
|
|
local CompositeElement = Parent:extend()
|
|
|
|
|
|
|
|
function CompositeElement:new(name, x, y, childrenList)
|
|
|
|
self.children = {}
|
|
|
|
self:addChildren(childrenList)
|
|
|
|
CompositeElement.super.new(self, name, x, y, 1, 1)
|
|
|
|
self.isVisible = true
|
|
|
|
end
|
|
|
|
|
|
|
|
function CompositeElement:addChildren(list)
|
|
|
|
for _, childData in ipairs(list) do
|
|
|
|
self:addChild(childData[1], childData[2], childData[3])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function CompositeElement:addChild(children, relx, rely)
|
|
|
|
local child = {}
|
|
|
|
child.name = children.name
|
|
|
|
child.relx = relx
|
|
|
|
child.rely = rely
|
|
|
|
table.insert(self.children, child)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CompositeElement:update(dt)
|
|
|
|
for _, child in ipairs(self.children) do
|
|
|
|
local childElement = self.getGui().elements[child.name]
|
|
|
|
childElement.x = self.x + child.relx
|
|
|
|
childElement.y = self.y + child.rely
|
|
|
|
childElement.isVisible = self.isVisible
|
2021-08-31 10:56:43 +02:00
|
|
|
childElement.depth = self.depth
|
2021-08-30 14:11:08 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return CompositeElement
|