consolidate invalid requires
This commit is contained in:
127
FlexLove.lua
127
FlexLove.lua
@@ -1,11 +1,120 @@
|
|||||||
local Color = require("game.utils.color")
|
-- Utility class for color handling
|
||||||
local enums = require("game.utils.enums")
|
---@class Color
|
||||||
local FlexDirection = enums.FlexDirection
|
---@field r number
|
||||||
local JustifyContent = enums.JustifyContent
|
---@field g number
|
||||||
local AlignContent = enums.AlignContent
|
---@field b number
|
||||||
local AlignItems = enums.AlignItems
|
---@field a number
|
||||||
local Positioning = enums.Positioning
|
local Color = {}
|
||||||
local TextAlign = enums.TextAlign
|
Color.__index = Color
|
||||||
|
|
||||||
|
--- Create a new color instance
|
||||||
|
---@param r number
|
||||||
|
---@param g number
|
||||||
|
---@param b number
|
||||||
|
---@param a number? -- default 1
|
||||||
|
---@return Color
|
||||||
|
function Color.new(r, g, b, a)
|
||||||
|
local self = setmetatable({}, Color)
|
||||||
|
self.r = r or 0
|
||||||
|
self.g = g or 0
|
||||||
|
self.b = b or 0
|
||||||
|
self.a = a or 1
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Convert hex string to color
|
||||||
|
---@param hex string -- e.g. "#RRGGBB" or "#RRGGBBAA"
|
||||||
|
---@return Color
|
||||||
|
function Color.fromHex(hex)
|
||||||
|
local hex = hex:gsub("#", "")
|
||||||
|
if #hex == 6 then
|
||||||
|
local r = tonumber("0x" .. hex:sub(1, 2))
|
||||||
|
local g = tonumber("0x" .. hex:sub(3, 4))
|
||||||
|
local b = tonumber("0x" .. hex:sub(5, 6))
|
||||||
|
return Color.new(r, g, b, 1)
|
||||||
|
elseif #hex == 8 then
|
||||||
|
local r = tonumber("0x" .. hex:sub(1, 2))
|
||||||
|
local g = tonumber("0x" .. hex:sub(3, 4))
|
||||||
|
local b = tonumber("0x" .. hex:sub(5, 6))
|
||||||
|
local a = tonumber("0x" .. hex:sub(7, 8)) / 255
|
||||||
|
return Color.new(r, g, b, a)
|
||||||
|
else
|
||||||
|
error("Invalid hex string")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Convert color to hex string
|
||||||
|
---@return string
|
||||||
|
function Color:toHex()
|
||||||
|
local r = math.floor(self.r * 255)
|
||||||
|
local g = math.floor(self.g * 255)
|
||||||
|
local b = math.floor(self.b * 255)
|
||||||
|
local a = math.floor(self.a * 255)
|
||||||
|
if self.a ~= 1 then
|
||||||
|
return string.format("#%02X%02X%02X%02X", r, g, b, a)
|
||||||
|
else
|
||||||
|
return string.format("#%02X%02X%02X", r, g, b)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return number r, number g, number b, number a
|
||||||
|
function Color:toRGBA()
|
||||||
|
return self.r, self.g, self.b, self.a
|
||||||
|
end
|
||||||
|
|
||||||
|
local enums
|
||||||
|
|
||||||
|
--- @enum TextAlign
|
||||||
|
enums.TextAlign = {
|
||||||
|
START = "start",
|
||||||
|
CENTER = "center",
|
||||||
|
END = "end",
|
||||||
|
JUSTIFY = "justify",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- @enum Positioning
|
||||||
|
enums.Positioning = {
|
||||||
|
ABSOLUTE = "absolute",
|
||||||
|
FLEX = "flex",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- @enum FlexDirection
|
||||||
|
enums.FlexDirection = {
|
||||||
|
HORIZONTAL = "horizontal",
|
||||||
|
VERTICAL = "vertical",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- @enum JustifyContent
|
||||||
|
enums.JustifyContent = {
|
||||||
|
FLEX_START = "flex-start",
|
||||||
|
CENTER = "center",
|
||||||
|
SPACE_AROUND = "space-around",
|
||||||
|
FLEX_END = "flex-end",
|
||||||
|
SPACE_EVENLY = "space-evenly",
|
||||||
|
SPACE_BETWEEN = "space-between",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- @enum AlignItems
|
||||||
|
enums.AlignItems = {
|
||||||
|
STRETCH = "stretch",
|
||||||
|
FLEX_START = "flex-start",
|
||||||
|
FLEX_END = "flex-end",
|
||||||
|
CENTER = "center",
|
||||||
|
BASELINE = "baseline",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- @enum AlignContent
|
||||||
|
enums.AlignContent = {
|
||||||
|
STRETCH = "stretch",
|
||||||
|
FLEX_START = "flex-start",
|
||||||
|
FLEX_END = "flex-end",
|
||||||
|
CENTER = "center",
|
||||||
|
SPACE_BETWEEN = "space-between",
|
||||||
|
SPACE_AROUND = "space-around",
|
||||||
|
}
|
||||||
|
|
||||||
|
local Positioning, FlexDirection, JustifyContent, AlignContent, AlignItems, TextAlign =
|
||||||
|
enums.Positioning, enums.FlexDirection, enums.JustifyContent, enums.AlignContent, enums.AlignItems, enums.TextAlign
|
||||||
|
|
||||||
--- Top level GUI manager
|
--- Top level GUI manager
|
||||||
local Gui = { topWindows = {} }
|
local Gui = { topWindows = {} }
|
||||||
@@ -720,4 +829,4 @@ end
|
|||||||
|
|
||||||
Gui.Button = Button
|
Gui.Button = Button
|
||||||
Gui.Window = Window
|
Gui.Window = Window
|
||||||
return Gui
|
return Gui, Color, enums
|
||||||
|
|||||||
Reference in New Issue
Block a user