Add Layout:up/down/left/right()
up() places the next cell above the previous one, and left() places the next cell to the left of the previous one. down() and right() are aliases to row()/col(), for symmetry. Also added are nextX() variants for function.
This commit is contained in:
parent
e64a822de8
commit
b19f0a3bff
1 changed files with 48 additions and 0 deletions
48
layout.lua
48
layout.lua
|
@ -35,10 +35,22 @@ function Layout:nextRow()
|
||||||
return self._x, self._y + self._h + self._pady
|
return self._x, self._y + self._h + self._pady
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Layout.nextDown = Layout.nextRow
|
||||||
|
|
||||||
|
function Layout:nextUp()
|
||||||
|
return self._x, self._y - self._h - self._pady
|
||||||
|
end
|
||||||
|
|
||||||
function Layout:nextCol()
|
function Layout:nextCol()
|
||||||
return self._x + self._w + self._padx, self._y
|
return self._x + self._w + self._padx, self._y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Layout.nextRight = Layout.nextCol
|
||||||
|
|
||||||
|
function Layout:nextLeft()
|
||||||
|
return self._x - self._w - self._padx, self._y
|
||||||
|
end
|
||||||
|
|
||||||
function Layout:push(x,y)
|
function Layout:push(x,y)
|
||||||
self._stack[#self._stack+1] = {
|
self._stack[#self._stack+1] = {
|
||||||
self._x, self._y,
|
self._x, self._y,
|
||||||
|
@ -135,6 +147,22 @@ function Layout:row(w, h)
|
||||||
return x,y,w,h
|
return x,y,w,h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Layout.down = Layout.row
|
||||||
|
|
||||||
|
function Layout:up(w, h)
|
||||||
|
w,h = calc_width_height(self, w, h)
|
||||||
|
local x,y = self._x, self._y - (self._h or 0)
|
||||||
|
|
||||||
|
if not self._isFirstCell then
|
||||||
|
y = y - self._pady
|
||||||
|
end
|
||||||
|
self._isFirstCell = false
|
||||||
|
|
||||||
|
self._y, self._w, self._h = y, w, h
|
||||||
|
|
||||||
|
return x,y,w,h
|
||||||
|
end
|
||||||
|
|
||||||
function Layout:col(w, h)
|
function Layout:col(w, h)
|
||||||
w,h = calc_width_height(self, w, h)
|
w,h = calc_width_height(self, w, h)
|
||||||
|
|
||||||
|
@ -150,6 +178,22 @@ function Layout:col(w, h)
|
||||||
return x,y,w,h
|
return x,y,w,h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Layout.right = Layout.col
|
||||||
|
|
||||||
|
function Layout:left(w, h)
|
||||||
|
w,h = calc_width_height(self, w, h)
|
||||||
|
|
||||||
|
local x,y = self._x - (self._w or 0), self._y
|
||||||
|
|
||||||
|
if not self._isFirstCell then
|
||||||
|
x = x - self._padx
|
||||||
|
end
|
||||||
|
self._isFirstCell = false
|
||||||
|
|
||||||
|
self._x, self._w, self._h = x, w, h
|
||||||
|
|
||||||
|
return x,y,w,h
|
||||||
|
end
|
||||||
|
|
||||||
local function layout_iterator(t, idx)
|
local function layout_iterator(t, idx)
|
||||||
idx = (idx or 1) + 1
|
idx = (idx or 1) + 1
|
||||||
|
@ -323,6 +367,10 @@ return setmetatable({
|
||||||
pop = function(...) return instance:pop(...) end,
|
pop = function(...) return instance:pop(...) end,
|
||||||
row = function(...) return instance:row(...) end,
|
row = function(...) return instance:row(...) end,
|
||||||
col = function(...) return instance:col(...) end,
|
col = function(...) return instance:col(...) end,
|
||||||
|
down = function(...) return instance:down(...) end,
|
||||||
|
up = function(...) return instance:up(...) end,
|
||||||
|
left = function(...) return instance:left(...) end,
|
||||||
|
right = function(...) return instance:right(...) end,
|
||||||
rows = function(...) return instance:rows(...) end,
|
rows = function(...) return instance:rows(...) end,
|
||||||
cols = function(...) return instance:cols(...) end,
|
cols = function(...) return instance:cols(...) end,
|
||||||
}, {__call = function(_,...) return Layout.new(...) end})
|
}, {__call = function(_,...) return Layout.new(...) end})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue