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
|
||||
LICENSE: MIT
|
||||
For full documentation, see README.md
|
||||
@@ -17,18 +17,6 @@ local function formatError(module, message)
|
||||
return string.format("[FlexLove.%s] %s", module, message)
|
||||
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
|
||||
-- ====================
|
||||
@@ -774,7 +762,12 @@ function Theme.new(definition)
|
||||
middleRight = { x = left + centerWidth + offsetX, y = top + offsetY, w = right, h = centerHeight },
|
||||
bottomLeft = { x = offsetX, y = top + centerHeight + offsetY, w = left, 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
|
||||
@@ -1118,9 +1111,11 @@ function NineSlice.draw(component, atlas, x, y, width, height, opacity)
|
||||
local scaledData
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
-- 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)
|
||||
if adjustedContentWidth > 0 then
|
||||
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(bottomCenterScaled, x + scaledLeft, y + scaledTop + adjustedContentHeight, 0, adjustedScaleX, 1)
|
||||
love.graphics.draw(
|
||||
bottomCenterScaled,
|
||||
x + scaledLeft,
|
||||
y + scaledTop + adjustedContentHeight,
|
||||
0,
|
||||
adjustedScaleX,
|
||||
1
|
||||
)
|
||||
end
|
||||
|
||||
-- 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)
|
||||
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
|
||||
else
|
||||
-- Original rendering logic (no scaling)
|
||||
@@ -4508,7 +4519,6 @@ Gui.Theme = Theme
|
||||
Gui.ImageDataReader = ImageDataReader
|
||||
Gui.NinePatchParser = NinePatchParser
|
||||
|
||||
-- Export individual enums for convenience
|
||||
return {
|
||||
GUI = Gui,
|
||||
Gui = Gui,
|
||||
@@ -4520,13 +4530,4 @@ return {
|
||||
ImageDataReader = ImageDataReader,
|
||||
NinePatchParser = NinePatchParser,
|
||||
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