diff --git a/gfx/list.lua b/gfx/list.lua index f8c46aa..82ac390 100644 --- a/gfx/list.lua +++ b/gfx/list.lua @@ -77,20 +77,28 @@ function List:draw() return dirty end -function List:getHeight() - local h = 0 - for _,v in ipairs(self.children) do - h = h + v:getHeight() +local function maxOrSum(shouldSum, values, getValue) + if shouldSum then + local sum = 0 + for _,v in ipairs(values) do + sum = sum + getValue(v) + end + return sum + else + local max = 0 + for _,v in ipairs(values) do + max = math.max(max, getValue(v)) + end + return max end - return h +end + +function List:getHeight() + return maxOrSum(self:isVertical(), self.elements, function(e) return e:getHeight() end) end function List:getWidth() - local w = 0 - for _,v in ipairs(self.children) do - w = w + v:getWidth() - end - return w + return maxOrSum(self:isHorizontal(), self.elements, function(e) return e:getWidth() end) end function List:findById(id)