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
|
return dirty
|
||||||
end
|
end
|
||||||
|
|
||||||
function List:getHeight()
|
local function maxOrSum(shouldSum, values, getValue)
|
||||||
local h = 0
|
if shouldSum then
|
||||||
for _,v in ipairs(self.children) do
|
local sum = 0
|
||||||
h = h + v:getHeight()
|
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
|
end
|
||||||
return h
|
end
|
||||||
|
|
||||||
|
function List:getHeight()
|
||||||
|
return maxOrSum(self:isVertical(), self.elements, function(e) return e:getHeight() end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function List:getWidth()
|
function List:getWidth()
|
||||||
local w = 0
|
return maxOrSum(self:isHorizontal(), self.elements, function(e) return e:getWidth() end)
|
||||||
for _,v in ipairs(self.children) do
|
|
||||||
w = w + v:getWidth()
|
|
||||||
end
|
|
||||||
return w
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function List:findById(id)
|
function List:findById(id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user