format
This commit is contained in:
59
FlexLove.lua
59
FlexLove.lua
@@ -1,5 +1,5 @@
|
|||||||
--[[
|
--[[
|
||||||
FlexLove - Flexible UI Library for LÖVE Framework
|
FlexLove - UI Library for LÖVE Framework 'based' on flexbox
|
||||||
VERSION: 1.0.0
|
VERSION: 1.0.0
|
||||||
LICENSE: MIT
|
LICENSE: MIT
|
||||||
For full documentation, see README.md
|
For full documentation, see README.md
|
||||||
@@ -17,18 +17,6 @@ local function formatError(module, message)
|
|||||||
return string.format("[FlexLove.%s] %s", module, message)
|
return string.format("[FlexLove.%s] %s", module, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Safe function call wrapper with error handling
|
|
||||||
---@param fn function -- Function to call
|
|
||||||
---@param errorContext string? -- Optional context for error message
|
|
||||||
---@return boolean success, any result -- Returns success status and result or error message
|
|
||||||
local function safecall(fn, errorContext)
|
|
||||||
local success, result = pcall(fn)
|
|
||||||
if not success and errorContext then
|
|
||||||
print(formatError("Core", errorContext .. ": " .. tostring(result)))
|
|
||||||
end
|
|
||||||
return success, result
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ====================
|
-- ====================
|
||||||
-- Color System
|
-- Color System
|
||||||
-- ====================
|
-- ====================
|
||||||
@@ -774,7 +762,12 @@ function Theme.new(definition)
|
|||||||
middleRight = { x = left + centerWidth + offsetX, y = top + offsetY, w = right, h = centerHeight },
|
middleRight = { x = left + centerWidth + offsetX, y = top + offsetY, w = right, h = centerHeight },
|
||||||
bottomLeft = { x = offsetX, y = top + centerHeight + offsetY, w = left, h = bottom },
|
bottomLeft = { x = offsetX, y = top + centerHeight + offsetY, w = left, h = bottom },
|
||||||
bottomCenter = { x = left + offsetX, y = top + centerHeight + offsetY, w = centerWidth, h = bottom },
|
bottomCenter = { x = left + offsetX, y = top + centerHeight + offsetY, w = centerWidth, h = bottom },
|
||||||
bottomRight = { x = left + centerWidth + offsetX, y = top + centerHeight + offsetY, w = right, h = bottom },
|
bottomRight = {
|
||||||
|
x = left + centerWidth + offsetX,
|
||||||
|
y = top + centerHeight + offsetY,
|
||||||
|
w = right,
|
||||||
|
h = bottom,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1118,9 +1111,11 @@ function NineSlice.draw(component, atlas, x, y, width, height, opacity)
|
|||||||
local scaledData
|
local scaledData
|
||||||
|
|
||||||
if scalingAlgorithm == "nearest" then
|
if scalingAlgorithm == "nearest" then
|
||||||
scaledData = ImageScaler.scaleNearest(atlasData, region.x, region.y, region.w, region.h, targetWidth, targetHeight)
|
scaledData =
|
||||||
|
ImageScaler.scaleNearest(atlasData, region.x, region.y, region.w, region.h, targetWidth, targetHeight)
|
||||||
else
|
else
|
||||||
scaledData = ImageScaler.scaleBilinear(atlasData, region.x, region.y, region.w, region.h, targetWidth, targetHeight)
|
scaledData =
|
||||||
|
ImageScaler.scaleBilinear(atlasData, region.x, region.y, region.w, region.h, targetWidth, targetHeight)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Convert to image and cache
|
-- Convert to image and cache
|
||||||
@@ -1160,10 +1155,18 @@ function NineSlice.draw(component, atlas, x, y, width, height, opacity)
|
|||||||
-- TOP/BOTTOM EDGES (stretch horizontally, scale vertically)
|
-- TOP/BOTTOM EDGES (stretch horizontally, scale vertically)
|
||||||
if adjustedContentWidth > 0 then
|
if adjustedContentWidth > 0 then
|
||||||
local topCenterScaled = getScaledRegion("topCenter", regions.topCenter, regions.topCenter.w, scaledTop)
|
local topCenterScaled = getScaledRegion("topCenter", regions.topCenter, regions.topCenter.w, scaledTop)
|
||||||
local bottomCenterScaled = getScaledRegion("bottomCenter", regions.bottomCenter, regions.bottomCenter.w, scaledBottom)
|
local bottomCenterScaled =
|
||||||
|
getScaledRegion("bottomCenter", regions.bottomCenter, regions.bottomCenter.w, scaledBottom)
|
||||||
|
|
||||||
love.graphics.draw(topCenterScaled, x + scaledLeft, y, 0, adjustedScaleX, 1)
|
love.graphics.draw(topCenterScaled, x + scaledLeft, y, 0, adjustedScaleX, 1)
|
||||||
love.graphics.draw(bottomCenterScaled, x + scaledLeft, y + scaledTop + adjustedContentHeight, 0, adjustedScaleX, 1)
|
love.graphics.draw(
|
||||||
|
bottomCenterScaled,
|
||||||
|
x + scaledLeft,
|
||||||
|
y + scaledTop + adjustedContentHeight,
|
||||||
|
0,
|
||||||
|
adjustedScaleX,
|
||||||
|
1
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- LEFT/RIGHT EDGES (stretch vertically, scale horizontally)
|
-- LEFT/RIGHT EDGES (stretch vertically, scale horizontally)
|
||||||
@@ -1177,7 +1180,15 @@ function NineSlice.draw(component, atlas, x, y, width, height, opacity)
|
|||||||
|
|
||||||
-- CENTER (stretch both dimensions, no scaling)
|
-- CENTER (stretch both dimensions, no scaling)
|
||||||
if adjustedContentWidth > 0 and adjustedContentHeight > 0 then
|
if adjustedContentWidth > 0 and adjustedContentHeight > 0 then
|
||||||
love.graphics.draw(atlas, makeQuad(regions.middleCenter), x + scaledLeft, y + scaledTop, 0, adjustedScaleX, adjustedScaleY)
|
love.graphics.draw(
|
||||||
|
atlas,
|
||||||
|
makeQuad(regions.middleCenter),
|
||||||
|
x + scaledLeft,
|
||||||
|
y + scaledTop,
|
||||||
|
0,
|
||||||
|
adjustedScaleX,
|
||||||
|
adjustedScaleY
|
||||||
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Original rendering logic (no scaling)
|
-- Original rendering logic (no scaling)
|
||||||
@@ -4508,7 +4519,6 @@ Gui.Theme = Theme
|
|||||||
Gui.ImageDataReader = ImageDataReader
|
Gui.ImageDataReader = ImageDataReader
|
||||||
Gui.NinePatchParser = NinePatchParser
|
Gui.NinePatchParser = NinePatchParser
|
||||||
|
|
||||||
-- Export individual enums for convenience
|
|
||||||
return {
|
return {
|
||||||
GUI = Gui,
|
GUI = Gui,
|
||||||
Gui = Gui,
|
Gui = Gui,
|
||||||
@@ -4520,13 +4530,4 @@ return {
|
|||||||
ImageDataReader = ImageDataReader,
|
ImageDataReader = ImageDataReader,
|
||||||
NinePatchParser = NinePatchParser,
|
NinePatchParser = NinePatchParser,
|
||||||
enums = enums,
|
enums = enums,
|
||||||
-- Export individual enums at top level
|
|
||||||
Positioning = Positioning,
|
|
||||||
FlexDirection = FlexDirection,
|
|
||||||
JustifyContent = JustifyContent,
|
|
||||||
AlignItems = AlignItems,
|
|
||||||
AlignSelf = AlignSelf,
|
|
||||||
AlignContent = AlignContent,
|
|
||||||
FlexWrap = FlexWrap,
|
|
||||||
TextAlign = TextAlign,
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user