margin
This commit is contained in:
29
FlexLove.lua
29
FlexLove.lua
@@ -567,14 +567,14 @@ function Window:layoutChildren()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Position children
|
-- Position children
|
||||||
local currentPos = spacing
|
local currentPos = spacing
|
||||||
for _, child in ipairs(self.children) do
|
for _, child in ipairs(self.children) do
|
||||||
if child.positioning == Positioning.ABSOLUTE then
|
if child.positioning == Positioning.ABSOLUTE then
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
if self.flexDirection == FlexDirection.VERTICAL then
|
if self.flexDirection == FlexDirection.VERTICAL then
|
||||||
child.x = currentPos
|
child.x = currentPos + self.mx
|
||||||
child.y = 0
|
child.y = 0
|
||||||
|
|
||||||
-- Apply alignment to vertical axis (alignItems)
|
-- Apply alignment to vertical axis (alignItems)
|
||||||
@@ -599,9 +599,9 @@ function Window:layoutChildren()
|
|||||||
child.height = self.height
|
child.height = self.height
|
||||||
end
|
end
|
||||||
|
|
||||||
currentPos = currentPos + (child.width or 0) + self.gap
|
currentPos = currentPos + (child.width or 0) + self.gap + self.mx * 2
|
||||||
else
|
else
|
||||||
child.y = currentPos
|
child.y = currentPos + self.my
|
||||||
-- Apply alignment to horizontal axis (alignItems)
|
-- Apply alignment to horizontal axis (alignItems)
|
||||||
if self.alignItems == AlignItems.FLEX_START then
|
if self.alignItems == AlignItems.FLEX_START then
|
||||||
--nothing, currentPos is all
|
--nothing, currentPos is all
|
||||||
@@ -624,7 +624,7 @@ function Window:layoutChildren()
|
|||||||
child.width = self.width
|
child.width = self.width
|
||||||
end
|
end
|
||||||
|
|
||||||
currentPos = currentPos + (child.height or 0) + self.gap
|
currentPos = currentPos + (child.height or 0) + self.gap + self.my * 2
|
||||||
end
|
end
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
@@ -794,7 +794,7 @@ function Window:resize(newGameWidth, newGameHeight)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Calculate auto width based on children
|
--- Calculate auto width based on children
|
||||||
function Window:calculateAutoWidth()
|
function Window:calculateAutoWidth()
|
||||||
if self.autosizing == false then
|
if self.autosizing == false then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -815,11 +815,12 @@ function Window:calculateAutoWidth()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.width = maxWidth + (self.px * 2)
|
-- Add window's own px padding and mx margins to the final width
|
||||||
|
self.width = maxWidth + (self.px * 2) + (self.mx * 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Calculate auto height based on children
|
--- Calculate auto height based on children
|
||||||
function Window:calculateAutoHeight()
|
function Window:calculateAutoHeight()
|
||||||
if self.autosizing == false then
|
if self.autosizing == false then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -839,8 +840,8 @@ function Window:calculateAutoHeight()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add window's own py padding to the final height
|
-- Add window's own py padding and my margins to the final height
|
||||||
self.height = maxHeight + (self.py * 2)
|
self.height = maxHeight + (self.py * 2) + (self.my * 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Update window size to fit children automatically
|
--- Update window size to fit children automatically
|
||||||
@@ -1097,12 +1098,12 @@ function Button:resize(ratioW, ratioH)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param newText string
|
---@param newText string
|
||||||
---@param autoresize boolean? --default: false
|
---@param autoresize boolean? --default: false
|
||||||
function Button:updateText(newText, autoresize)
|
function Button:updateText(newText, autoresize)
|
||||||
self.text = newText or self.text
|
self.text = newText or self.text
|
||||||
if autoresize then
|
if autoresize then
|
||||||
self.width = self:calculateTextWidth() + self.px
|
self.width = self:calculateTextWidth() + (self.px * 2)
|
||||||
self.height = self:calculateTextHeight() + self.py
|
self.height = self:calculateTextHeight() + (self.py * 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If autosizing is enabled, recalculate size after text update
|
-- If autosizing is enabled, recalculate size after text update
|
||||||
|
|||||||
Reference in New Issue
Block a user