Compute sum of List element dims on-axis and max of cross-axis
This commit is contained in:
parent
18a4d8efb9
commit
1d29de8ace
28
gfx/list.lua
28
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user