91 lines
2.3 KiB
Lua
91 lines
2.3 KiB
Lua
local Tilers = {}
|
|
local inspect = require("inspect")
|
|
|
|
local dirs = {
|
|
left = function(m, w, h, stack, r, gap)
|
|
local masterBase = {
|
|
w = w * r - gap/2,
|
|
h = h,
|
|
x = m.left,
|
|
y = m.top
|
|
}
|
|
local childBase = {
|
|
w = (w * (1-r)) - gap/2,
|
|
h = (masterBase.h / (#stack-1)) - gap + gap / (#stack-1),
|
|
x = masterBase.x + masterBase.w + gap,
|
|
y = m.top
|
|
}
|
|
local childOffset = {
|
|
x = 0, y = childBase.h + gap
|
|
}
|
|
return masterBase, childBase, childOffset
|
|
end,
|
|
top = function(m, w, h, stack, r, gap)
|
|
local masterBase = {
|
|
w = w,
|
|
h = h * r - gap,
|
|
x = m.left,
|
|
y = m.top
|
|
}
|
|
local childBase = {
|
|
w = (masterBase.w / (#stack-1)) - gap + gap / (#stack-1),
|
|
h = (h * (1-r)) - gap,
|
|
x = m.left,
|
|
y = masterBase.y + masterBase.h + gap,
|
|
}
|
|
local childOffset = {
|
|
x = childBase.w + gap, y = 0
|
|
}
|
|
return masterBase, childBase, childOffset
|
|
end
|
|
}
|
|
dirs.right = function(...)
|
|
local masterBase, childBase, childOffset = dirs.left(...)
|
|
masterBase.x, childBase.x = childBase.x, masterBase.x
|
|
masterBase.w, childBase.w = childBase.w, masterBase.w
|
|
return masterBase, childBase, childOffset
|
|
end
|
|
dirs.bottom = function(...)
|
|
local masterBase, childBase, childOffset = dirs.top(...)
|
|
masterBase.y, childBase.y = childBase.y, masterBase.y
|
|
masterBase.h, childBase.h = childBase.h, masterBase.h
|
|
return masterBase, childBase, childOffset
|
|
end
|
|
|
|
local function makeTiler(getOff)
|
|
return {
|
|
r = 0.5,
|
|
tile = function(self, stack, monitor)
|
|
local m = monitor.margins
|
|
local w = monitor.width - m.left - m.right
|
|
local h = monitor.height - m.top - m.bottom
|
|
if #stack == 1 then
|
|
stack[1]:setGeometry(m.left, m.top, w, h)
|
|
elseif #stack >= 2 then
|
|
local masterBase, childBase, childOffset = getOff(m, w, h, stack, self.r, self.gap)
|
|
stack[1]:setGeometry(masterBase.x, masterBase.y, masterBase.w, masterBase.h)
|
|
for i=2,#stack do
|
|
stack[i]:setGeometry(childBase.x, childBase.y, childBase.w, childBase.h)
|
|
childBase.x = childBase.x + childOffset.x
|
|
childBase.y = childBase.y + childOffset.y
|
|
end
|
|
end
|
|
end,
|
|
setGap = function(self, gap)
|
|
assert(type(gap) == "number")
|
|
self.gap = gap
|
|
end,
|
|
gap = 0
|
|
}
|
|
end
|
|
|
|
Tilers = {
|
|
masterTop = makeTiler(dirs.top),
|
|
masterLeft = makeTiler(dirs.left),
|
|
masterRight = makeTiler(dirs.right),
|
|
masterBottom = makeTiler(dirs.bottom),
|
|
}
|
|
|
|
return Tilers
|
|
|
|
|