fix uninitialized variables in container layout
variables `x` and `y` shadowed the parameters, and `containerX`, `containerY`, `containerWidth` and `containerHeight` were used without being initialized. they could be replaced by the parameters `width` and `height`
This commit is contained in:
parent
cac01a34c9
commit
fc2d5c862a
@ -1,8 +1,8 @@
|
|||||||
local path = string.sub(..., 1, string.len(...) - string.len(".container"))
|
local path = string.sub(..., 1, string.len(...) - string.len(".container"))
|
||||||
local layout = require(path..'.layout')
|
local layout = require(path .. '.layout')
|
||||||
|
|
||||||
---@class Container
|
---@class Container
|
||||||
local container = {}
|
local container = {}
|
||||||
container.__index = container
|
container.__index = container
|
||||||
|
|
||||||
---Positions an element within a container
|
---Positions an element within a container
|
||||||
@ -14,7 +14,7 @@ function container.new(halign, valign)
|
|||||||
halign = halign or 'left',
|
halign = halign or 'left',
|
||||||
valign = valign or 'top',
|
valign = valign or 'top',
|
||||||
}, container)
|
}, container)
|
||||||
|
|
||||||
return layout(self, self.draw)
|
return layout(self, self.draw)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -23,11 +23,11 @@ local function alignLeft(x, wroot, wchild)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function alignCenter(x, wroot, wchild)
|
local function alignCenter(x, wroot, wchild)
|
||||||
return x+(wroot/2-wchild/2)
|
return x + (wroot / 2 - wchild / 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function alignRight(x, wroot, wchild)
|
local function alignRight(x, wroot, wchild)
|
||||||
return x+(wroot-wchild)
|
return x + (wroot - wchild)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -53,23 +53,22 @@ end
|
|||||||
|
|
||||||
function container:draw(x, y, width, height, children, hpad, vpad, alignX)
|
function container:draw(x, y, width, height, children, hpad, vpad, alignX)
|
||||||
local w, h = children[1]:getSize()
|
local w, h = children[1]:getSize()
|
||||||
local x, y
|
|
||||||
|
|
||||||
if self.halign =='stretch' then
|
if self.halign == 'stretch' then
|
||||||
w = width
|
w = width
|
||||||
x = x
|
x = x
|
||||||
else
|
else
|
||||||
x = alignHandlerX(self.halign, containerX, containerWidth, w)
|
x = alignHandlerX(self.halign, x, width, w)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.valign =='stretch' then
|
if self.valign == 'stretch' then
|
||||||
h = h
|
h = height
|
||||||
y = y
|
y = y
|
||||||
else
|
else
|
||||||
y = alignHandlerY(self.valign, containerY, containerHeight, h)
|
y = alignHandlerY(self.valign, y, height, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
children[1]:draw(x, y, w, h)
|
children[1]:draw(x, y, w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
return container
|
return container
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user