From fc2d5c862afedc0c62dd5f3d60e8a0705e0b4cbd Mon Sep 17 00:00:00 2001 From: TotoEnF5 Date: Tue, 25 Mar 2025 14:25:33 +0100 Subject: [PATCH] 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` --- layout/container.lua | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/layout/container.lua b/layout/container.lua index 4fe5375..53cdc62 100644 --- a/layout/container.lua +++ b/layout/container.lua @@ -1,8 +1,8 @@ -local path = string.sub(..., 1, string.len(...) - string.len(".container")) -local layout = require(path..'.layout') +local path = string.sub(..., 1, string.len(...) - string.len(".container")) +local layout = require(path .. '.layout') ---@class Container -local container = {} +local container = {} container.__index = container ---Positions an element within a container @@ -14,7 +14,7 @@ function container.new(halign, valign) halign = halign or 'left', valign = valign or 'top', }, container) - + return layout(self, self.draw) end @@ -23,11 +23,11 @@ local function alignLeft(x, wroot, wchild) end local function alignCenter(x, wroot, wchild) - return x+(wroot/2-wchild/2) + return x + (wroot / 2 - wchild / 2) end local function alignRight(x, wroot, wchild) - return x+(wroot-wchild) + return x + (wroot - wchild) end @@ -53,23 +53,22 @@ end function container:draw(x, y, width, height, children, hpad, vpad, alignX) local w, h = children[1]:getSize() - local x, y - if self.halign =='stretch' then + if self.halign == 'stretch' then w = width x = x else - x = alignHandlerX(self.halign, containerX, containerWidth, w) + x = alignHandlerX(self.halign, x, width, w) end - if self.valign =='stretch' then - h = h + if self.valign == 'stretch' then + h = height y = y else - y = alignHandlerY(self.valign, containerY, containerHeight, h) + y = alignHandlerY(self.valign, y, height, h) end children[1]:draw(x, y, w, h) end -return container \ No newline at end of file +return container