-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVDiv.lua
executable file
·37 lines (31 loc) · 978 Bytes
/
VDiv.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local ContainerBase = require("ContainerBase")
local VDiv = ContainerBase:extend()
VDiv.type="VDiv"
VDiv.baseStyle = {
placement = "fill",
}
setmetatable(VDiv.baseStyle, {__index=ContainerBase.baseStyle})
function VDiv:getContentDimensions()
local maxW = 0
local maxH = 0
for _, W in ipairs(self.items) do
local w, h = W:getMinDimensions()
maxW = math.max(maxW, w)
maxH = math.max(maxH, h)
end
return maxW, maxH * #self.items + self.style.gap * (#self.items - 1)
end
function VDiv:calculateGeometry(x, y, w, h)
ContainerBase.calculateGeometry(self, x, y, w, h)
local slots = self:getSlots()
local xB, yB, wB, hB = self:getContentBox()
local gap = self.style.gap
local cellH = (hB+gap) / slots - gap
local cellW = wB
local i = 0
for _, W in ipairs(self.items) do
W:calculateGeometry(xB, yB+i*(cellH+gap), cellW, cellH*W.style.span)
i = i + W.style.span
end
end
return VDiv