sonic-bluestreak/sonic-bluestreak.love/birb/modules/gui/elements/composite.lua

35 lines
1,013 B
Lua
Raw Permalink Normal View History

2021-11-25 10:46:15 +01: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.gui.elements[child.name]
childElement.x = self.x + child.relx
childElement.y = self.y + child.rely
childElement.isVisible = self.isVisible
childElement.depth = self.depth
end
end
return CompositeElement