-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHDiv.lua
executable file
·37 lines (31 loc) · 980 Bytes
/
HDiv.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 HDiv = ContainerBase:extend()
HDiv.type = "HDiv"
HDiv.baseStyle = {
placement = "fill",
}
setmetatable(HDiv.baseStyle, {__index=ContainerBase.baseStyle})
function HDiv: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 * #self.items + self.style.gap*(#self.items - 1), maxH
end
function HDiv:calculateGeometry(x, y, w, h)
ContainerBase.calculateGeometry(self, x, y, w, h)
local slots = self:getSlots()
local gap = self.style.gap
local xB, yB, wB, hB = self:getContentBox()
local cellW = (wB+gap) / slots - gap
local cellH = hB
local i = 0
for _, W in ipairs(self.items) do
W:calculateGeometry(xB+i*(cellW + gap), yB, cellW*W.style.span, cellH)
i = i + W.style.span
end
end
return HDiv