declare default for lsp
This commit is contained in:
32
FlexLove.lua
32
FlexLove.lua
@@ -8,10 +8,10 @@ local Color = {}
|
|||||||
Color.__index = Color
|
Color.__index = Color
|
||||||
|
|
||||||
--- Create a new color instance
|
--- Create a new color instance
|
||||||
---@param r number?
|
---@param r number? -- Default: 0
|
||||||
---@param g number?
|
---@param g number? -- Default: 0
|
||||||
---@param b number?
|
---@param b number? -- Default: 0
|
||||||
---@param a number? -- default 1
|
---@param a number? -- Default: 1
|
||||||
---@return Color
|
---@return Color
|
||||||
function Color.new(r, g, b, a)
|
function Color.new(r, g, b, a)
|
||||||
local self = setmetatable({}, Color)
|
local self = setmetatable({}, Color)
|
||||||
@@ -700,7 +700,7 @@ function Element.new(props)
|
|||||||
if type(props.textSize) == "string" then
|
if type(props.textSize) == "string" then
|
||||||
local value, unit = Units.parse(props.textSize)
|
local value, unit = Units.parse(props.textSize)
|
||||||
self.units.textSize = { value = value, unit = unit }
|
self.units.textSize = { value = value, unit = unit }
|
||||||
|
|
||||||
-- Resolve textSize based on unit type
|
-- Resolve textSize based on unit type
|
||||||
if unit == "%" or unit == "vh" then
|
if unit == "%" or unit == "vh" then
|
||||||
-- Percentage and vh are relative to viewport height
|
-- Percentage and vh are relative to viewport height
|
||||||
@@ -722,14 +722,14 @@ function Element.new(props)
|
|||||||
if props.textSize <= 0 then
|
if props.textSize <= 0 then
|
||||||
error("textSize must be greater than 0, got: " .. tostring(props.textSize))
|
error("textSize must be greater than 0, got: " .. tostring(props.textSize))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Pixel textSize value
|
-- Pixel textSize value
|
||||||
if self.autoScaleText then
|
if self.autoScaleText then
|
||||||
-- Convert pixel value to viewport units for auto-scaling
|
-- Convert pixel value to viewport units for auto-scaling
|
||||||
-- Calculate what percentage of viewport height this represents
|
-- Calculate what percentage of viewport height this represents
|
||||||
local vhValue = (props.textSize / viewportHeight) * 100
|
local vhValue = (props.textSize / viewportHeight) * 100
|
||||||
self.units.textSize = { value = vhValue, unit = "vh" }
|
self.units.textSize = { value = vhValue, unit = "vh" }
|
||||||
self.textSize = props.textSize -- Initial size is the specified pixel value
|
self.textSize = props.textSize -- Initial size is the specified pixel value
|
||||||
else
|
else
|
||||||
-- Apply base scaling to pixel text sizes (no auto-scaling)
|
-- Apply base scaling to pixel text sizes (no auto-scaling)
|
||||||
self.textSize = Gui.baseScale and (props.textSize * scaleY) or props.textSize
|
self.textSize = Gui.baseScale and (props.textSize * scaleY) or props.textSize
|
||||||
@@ -752,17 +752,17 @@ function Element.new(props)
|
|||||||
-- Apply min/max constraints (also scaled)
|
-- Apply min/max constraints (also scaled)
|
||||||
local minSize = self.minTextSize and (Gui.baseScale and (self.minTextSize * scaleY) or self.minTextSize)
|
local minSize = self.minTextSize and (Gui.baseScale and (self.minTextSize * scaleY) or self.minTextSize)
|
||||||
local maxSize = self.maxTextSize and (Gui.baseScale and (self.maxTextSize * scaleY) or self.maxTextSize)
|
local maxSize = self.maxTextSize and (Gui.baseScale and (self.maxTextSize * scaleY) or self.maxTextSize)
|
||||||
|
|
||||||
if minSize and self.textSize < minSize then
|
if minSize and self.textSize < minSize then
|
||||||
self.textSize = minSize
|
self.textSize = minSize
|
||||||
end
|
end
|
||||||
if maxSize and self.textSize > maxSize then
|
if maxSize and self.textSize > maxSize then
|
||||||
self.textSize = maxSize
|
self.textSize = maxSize
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Protect against too-small text sizes (minimum 1px)
|
-- Protect against too-small text sizes (minimum 1px)
|
||||||
if self.textSize < 1 then
|
if self.textSize < 1 then
|
||||||
self.textSize = 1 -- Minimum 1px
|
self.textSize = 1 -- Minimum 1px
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Store original spacing values for proper resize handling
|
-- Store original spacing values for proper resize handling
|
||||||
@@ -1707,24 +1707,24 @@ function Element:recalculateUnits(newViewportWidth, newViewportHeight)
|
|||||||
if maxSize and self.textSize > maxSize then
|
if maxSize and self.textSize > maxSize then
|
||||||
self.textSize = maxSize
|
self.textSize = maxSize
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Protect against too-small text sizes (minimum 1px)
|
-- Protect against too-small text sizes (minimum 1px)
|
||||||
if self.textSize < 1 then
|
if self.textSize < 1 then
|
||||||
self.textSize = 1 -- Minimum 1px
|
self.textSize = 1 -- Minimum 1px
|
||||||
end
|
end
|
||||||
elseif self.units.textSize.unit == "px" and self.units.textSize.value and Gui.baseScale then
|
elseif self.units.textSize.unit == "px" and self.units.textSize.value and Gui.baseScale then
|
||||||
-- Reapply base scaling to pixel text sizes
|
-- Reapply base scaling to pixel text sizes
|
||||||
self.textSize = self.units.textSize.value * scaleY
|
self.textSize = self.units.textSize.value * scaleY
|
||||||
|
|
||||||
-- Protect against too-small text sizes (minimum 1px)
|
-- Protect against too-small text sizes (minimum 1px)
|
||||||
if self.textSize < 1 then
|
if self.textSize < 1 then
|
||||||
self.textSize = 1 -- Minimum 1px
|
self.textSize = 1 -- Minimum 1px
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Final protection: ensure textSize is always at least 1px (catches all edge cases)
|
-- Final protection: ensure textSize is always at least 1px (catches all edge cases)
|
||||||
if self.text and self.textSize and self.textSize < 1 then
|
if self.text and self.textSize and self.textSize < 1 then
|
||||||
self.textSize = 1 -- Minimum 1px
|
self.textSize = 1 -- Minimum 1px
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Recalculate gap if using viewport or percentage units
|
-- Recalculate gap if using viewport or percentage units
|
||||||
|
|||||||
Reference in New Issue
Block a user