Update Flexbox.lua

- fixed small offset calculation bug
This commit is contained in:
Robert Jelic
2023-05-19 18:55:11 +02:00
parent 67a408a4c8
commit cfec78f6f7

View File

@@ -61,6 +61,7 @@ return function(name, basalt)
setPosition = function(self) end, setPosition = function(self) end,
setSize = function(self) end, setSize = function(self) end,
}) })
lineBreakFakeObject:setFlexBasis(0)
local function sortChildren(self) local function sortChildren(self)
if(wrap=="nowrap")then if(wrap=="nowrap")then
@@ -112,10 +113,10 @@ return function(name, basalt)
lineOffset = lineOffset + lineSize + spacing lineOffset = lineOffset + lineSize + spacing
lineSize = direction == "row" and v:getHeight() or v:getWidth() lineSize = direction == "row" and v:getHeight() or v:getWidth()
index = index + 1 index = index + 1
usedSize = 0 usedSize = objSize + spacing
sortedChildren[index] = {offset=lineOffset, v} sortedChildren[index] = {offset=lineOffset, v}
else else
usedSize = usedSize + objSize usedSize = usedSize + objSize + spacing
table.insert(sortedChildren[index], v) table.insert(sortedChildren[index], v)
end end
end end
@@ -157,7 +158,6 @@ return function(name, basalt)
child:setPosition(currentX, children.offset or 1) child:setPosition(currentX, children.offset or 1)
child:setSize(childWidth, child:getHeight()) child:setSize(childWidth, child:getHeight())
basalt.log(children.offset)
currentX = currentX + childWidth + spacing currentX = currentX + childWidth + spacing
end end
end end
@@ -381,7 +381,8 @@ return function(name, basalt)
for k, _ in pairs(basalt.getObjects()) do for k, _ in pairs(basalt.getObjects()) do
object["add" .. k] = function(self, name) object["add" .. k] = function(self, name)
local child = flexObjectPlugin(base["add" .. k](self, name), basalt) local baseChild = base["add" .. k](self, name)
local child = flexObjectPlugin(baseChild, basalt)
table.insert(children, child) table.insert(children, child)
updateLayout = true updateLayout = true
return child return child