Fix wrong padding in nested layouts
Previoysly, padding was added before adding a cell, which lead to incorrect and unaligned cell placement in nested layouts. Now padding is only added when at least one cell has been placed before.
This commit is contained in:
parent
5bba68071d
commit
10767cca33
1 changed files with 14 additions and 3 deletions
17
layout.lua
17
layout.lua
|
@ -14,6 +14,7 @@ function Layout:reset(x,y, padx,pady)
|
||||||
self._h = nil
|
self._h = nil
|
||||||
self._widths = {}
|
self._widths = {}
|
||||||
self._heights = {}
|
self._heights = {}
|
||||||
|
self._isFirstCell = true
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
@ -57,6 +58,7 @@ function Layout:pop()
|
||||||
self._padx,self._pady,
|
self._padx,self._pady,
|
||||||
self._w, self._h,
|
self._w, self._h,
|
||||||
self._widths, self._heights = unpack(self._stack[#self._stack])
|
self._widths, self._heights = unpack(self._stack[#self._stack])
|
||||||
|
self._isFirstCell = false
|
||||||
|
|
||||||
self._w, self._h = math.max(w, self._w or 0), math.max(h, self._h or 0)
|
self._w, self._h = math.max(w, self._w or 0), math.max(h, self._h or 0)
|
||||||
|
|
||||||
|
@ -120,20 +122,29 @@ local function calc_width_height(self, w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Layout:row(w, h)
|
function Layout:row(w, h)
|
||||||
self._y = self._y + self._pady
|
|
||||||
w,h = calc_width_height(self, w, h)
|
w,h = calc_width_height(self, w, h)
|
||||||
|
|
||||||
local x,y = self._x, self._y + (self._h or 0)
|
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
|
self._y, self._w, self._h = y, w, h
|
||||||
|
|
||||||
return x,y,w,h
|
return x,y,w,h
|
||||||
end
|
end
|
||||||
|
|
||||||
function Layout:col(w, h)
|
function Layout:col(w, h)
|
||||||
self._x = self._x + self._padx
|
|
||||||
w,h = calc_width_height(self, w, h)
|
w,h = calc_width_height(self, w, h)
|
||||||
|
|
||||||
local x,y = self._x + (self._w or 0), self._y
|
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
|
self._x, self._w, self._h = x, w, h
|
||||||
|
|
||||||
return x,y,w,h
|
return x,y,w,h
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue