Allow lenient Container dimensions

This commit is contained in:
Gabriel Tofvesson 2024-10-12 07:35:29 +02:00
parent 9ac62319fd
commit 3a46e08f37

View File

@ -4,6 +4,40 @@ local Element = require("gfx.element")
local Container = Prop.attach(Element:new(), Children)
function Container:getHeight()
if self:isStrict() then
return Element.getHeight(self)
end
local max = 0
for _,child in self:_iterateChildren() do
max = math.max(max, child:getY() + child:getHeight())
end
return max
end
function Container:getWidth()
if self:isStrict() then
return Element.getWidth(self)
end
local max = 0
for _,child in self:_iterateChildren() do
max = math.max(max, child:getX() + child:getWidth())
end
return max
end
function Container:isStrict()
return self.strict == true
end
function Container:setStrict(strict)
local needReload = (not not self.strict) ~= strict
self.strict = strict
if needReload then
self:_reload()
end
end
function Container:_reload()
Element._reload(self)