Update Flexbox.lua

- Forgot to add getWrap
- Objects do have now the default size instead of using the basis value
- Forgot to update draw handler after something gets changed
This commit is contained in:
Robert Jelic
2023-05-21 17:50:19 +02:00
parent 2d9efbbb5a
commit 2293aacdec

View File

@@ -2,7 +2,7 @@
local function flexObjectPlugin(base, basalt) local function flexObjectPlugin(base, basalt)
local flexGrow = 0 local flexGrow = 0
local flexShrink = 0 local flexShrink = 0
local flexBasis = 12 local flexBasis = 0
local baseWidth, baseHeight = base:getSize() local baseWidth, baseHeight = base:getSize()
@@ -141,7 +141,6 @@ return function(name, basalt)
end end
end end
end end
end end
end end
@@ -167,14 +166,15 @@ return function(name, basalt)
local flexGrow = child:getFlexGrow() local flexGrow = child:getFlexGrow()
local flexShrink = child:getFlexShrink() local flexShrink = child:getFlexShrink()
local baseWidth = child:getFlexBasis() ~= 0 and child:getFlexBasis() or child:getWidth()
if totalFlexGrow > 0 then if totalFlexGrow > 0 then
childWidth = child:getFlexBasis() + flexGrow / totalFlexGrow * remainingSpace childWidth = baseWidth + flexGrow / totalFlexGrow * remainingSpace
else else
childWidth = child:getFlexBasis() childWidth = baseWidth
end end
if remainingSpace < 0 and totalFlexShrink > 0 then if remainingSpace < 0 and totalFlexShrink > 0 then
childWidth = child:getFlexBasis() + flexShrink / totalFlexShrink * remainingSpace childWidth = baseWidth + flexShrink / totalFlexShrink * remainingSpace
end end
child:setPosition(currentX, children.offset or 1) child:setPosition(currentX, children.offset or 1)
@@ -255,14 +255,15 @@ return function(name, basalt)
local flexGrow = child:getFlexGrow() local flexGrow = child:getFlexGrow()
local flexShrink = child:getFlexShrink() local flexShrink = child:getFlexShrink()
local baseHeight = child:getFlexBasis() ~= 0 and child:getFlexBasis() or child:getHeight()
if totalFlexGrow > 0 then if totalFlexGrow > 0 then
childHeight = child:getFlexBasis() + flexGrow / totalFlexGrow * remainingSpace childHeight = baseHeight + flexGrow / totalFlexGrow * remainingSpace
else else
childHeight = child:getFlexBasis() childHeight = baseHeight
end end
if remainingSpace < 0 and totalFlexShrink > 0 then if remainingSpace < 0 and totalFlexShrink > 0 then
childHeight = child:getFlexBasis() + flexShrink / totalFlexShrink * remainingSpace childHeight = baseHeight + flexShrink / totalFlexShrink * remainingSpace
end end
child:setPosition(children.offset, currentY) child:setPosition(children.offset, currentY)
@@ -347,6 +348,7 @@ return function(name, basalt)
setJustifyContent = function(self, value) setJustifyContent = function(self, value)
justifyContent = value justifyContent = value
updateLayout = true updateLayout = true
self:updateDraw()
return self return self
end, end,
@@ -357,6 +359,7 @@ return function(name, basalt)
setDirection = function(self, value) setDirection = function(self, value)
direction = value direction = value
updateLayout = true updateLayout = true
self:updateDraw()
return self return self
end, end,
@@ -367,6 +370,7 @@ return function(name, basalt)
setSpacing = function(self, value) setSpacing = function(self, value)
spacing = value spacing = value
updateLayout = true updateLayout = true
self:updateDraw()
return self return self
end, end,
@@ -377,16 +381,23 @@ return function(name, basalt)
setWrap = function(self, value) setWrap = function(self, value)
wrap = value wrap = value
updateLayout = true updateLayout = true
self:updateDraw()
return self return self
end, end,
getWrap = function(self)
return wrap
end,
updateLayout = function(self) updateLayout = function(self)
updateLayout = true updateLayout = true
self:updateDraw()
end, end,
addBreak = function(self) addBreak = function(self)
table.insert(children, lineBreakFakeObject) table.insert(children, lineBreakFakeObject)
updateLayout = true updateLayout = true
self:updateDraw()
return self return self
end, end,