Grid CalculateSize() fix #21

This commit is contained in:
João Lopes 2023-02-03 17:30:39 +00:00
parent bb5a21b39b
commit 09f1b941ca
2 changed files with 13 additions and 4 deletions

View File

@ -412,6 +412,7 @@ function newobject:Center()
local base = loveframes.base local base = loveframes.base
local parent = self.parent local parent = self.parent
if self.CalculateSize then self:CalculateSize() end
if parent == base then if parent == base then
local width = love.graphics.getWidth() local width = love.graphics.getWidth()
local height = love.graphics.getHeight() local height = love.graphics.getHeight()

View File

@ -70,8 +70,7 @@ function newobject:update(dt)
local prevwidth = self.prevwidth local prevwidth = self.prevwidth
local prevheight = self.prevheight local prevheight = self.prevheight
self.width = (self.columns * self.cellwidth) + (self.columns * (self.cellpadding * 2)) self:CalculateSize()
self.height = (self.rows * self.cellheight) + (self.rows * (self.cellpadding * 2))
if self.width ~= prevwidth or self.height ~= prevheight then if self.width ~= prevwidth or self.height ~= prevheight then
local onsizechanged = self.OnSizeChanged local onsizechanged = self.OnSizeChanged
@ -92,6 +91,15 @@ function newobject:update(dt)
end end
--[[---------------------------------------------------------
- func: CalculateSize()
- desc: calculate the object size
--]]---------------------------------------------------------
function newobject:CalculateSize()
self.width = (self.columns * self.cellwidth) + (self.columns * (self.cellpadding * 2))
self.height = (self.rows * self.cellheight) + (self.rows * (self.cellpadding * 2))
end
function newobject:_update_children_position() function newobject:_update_children_position()
for k, v in ipairs(self.children) do for k, v in ipairs(self.children) do
local rs, cs = self:GetCellSpanSize(v.gridrow, v.gridcolumn) local rs, cs = self:GetCellSpanSize(v.gridrow, v.gridcolumn)