removing unnecessary methods and comments
This commit is contained in:
@@ -35,37 +35,28 @@ function EventHandler.new(config, deps)
|
|||||||
|
|
||||||
local self = setmetatable({}, EventHandler)
|
local self = setmetatable({}, EventHandler)
|
||||||
|
|
||||||
-- Store dependencies
|
|
||||||
self._InputEvent = deps.InputEvent
|
self._InputEvent = deps.InputEvent
|
||||||
self._GuiState = deps.GuiState
|
self._GuiState = deps.GuiState
|
||||||
|
|
||||||
-- Event callback
|
|
||||||
self.onEvent = config.onEvent
|
self.onEvent = config.onEvent
|
||||||
|
|
||||||
-- Mouse button state tracking {button -> boolean}
|
|
||||||
self._pressed = config._pressed or {}
|
self._pressed = config._pressed or {}
|
||||||
|
|
||||||
-- Click detection state
|
|
||||||
self._lastClickTime = config._lastClickTime
|
self._lastClickTime = config._lastClickTime
|
||||||
self._lastClickButton = config._lastClickButton
|
self._lastClickButton = config._lastClickButton
|
||||||
self._clickCount = config._clickCount or 0
|
self._clickCount = config._clickCount or 0
|
||||||
|
|
||||||
-- Drag tracking per button {button -> position}
|
|
||||||
self._dragStartX = config._dragStartX or {}
|
self._dragStartX = config._dragStartX or {}
|
||||||
self._dragStartY = config._dragStartY or {}
|
self._dragStartY = config._dragStartY or {}
|
||||||
self._lastMouseX = config._lastMouseX or {}
|
self._lastMouseX = config._lastMouseX or {}
|
||||||
self._lastMouseY = config._lastMouseY or {}
|
self._lastMouseY = config._lastMouseY or {}
|
||||||
|
|
||||||
-- Touch state tracking {touchId -> boolean}
|
|
||||||
self._touchPressed = config._touchPressed or {}
|
self._touchPressed = config._touchPressed or {}
|
||||||
|
|
||||||
-- Hover state
|
|
||||||
self._hovered = config._hovered or false
|
self._hovered = config._hovered or false
|
||||||
|
|
||||||
-- Reference to parent element (set via initialize)
|
|
||||||
self._element = nil
|
self._element = nil
|
||||||
|
|
||||||
-- Scrollbar press tracking flag
|
|
||||||
self._scrollbarPressHandled = false
|
self._scrollbarPressHandled = false
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ function Grid.layoutGridItems(element)
|
|||||||
local cellWidth = (availableWidth - totalColumnGaps) / columns
|
local cellWidth = (availableWidth - totalColumnGaps) / columns
|
||||||
local cellHeight = (availableHeight - totalRowGaps) / rows
|
local cellHeight = (availableHeight - totalRowGaps) / rows
|
||||||
|
|
||||||
-- Get children that participate in grid layout
|
|
||||||
local gridChildren = {}
|
local gridChildren = {}
|
||||||
for _, child in ipairs(element.children) do
|
for _, child in ipairs(element.children) do
|
||||||
if not (child.positioning == Positioning.ABSOLUTE and child._explicitlyAbsolute) then
|
if not (child.positioning == Positioning.ABSOLUTE and child._explicitlyAbsolute) then
|
||||||
@@ -65,14 +64,12 @@ function Grid.layoutGridItems(element)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Place children in grid cells
|
|
||||||
for i, child in ipairs(gridChildren) do
|
for i, child in ipairs(gridChildren) do
|
||||||
-- Calculate row and column (0-indexed for calculation)
|
-- Calculate row and column (0-indexed for calculation)
|
||||||
local index = i - 1
|
local index = i - 1
|
||||||
local col = index % columns
|
local col = index % columns
|
||||||
local row = math.floor(index / columns)
|
local row = math.floor(index / columns)
|
||||||
|
|
||||||
-- Skip if we've exceeded the grid
|
|
||||||
if row >= rows then
|
if row >= rows then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -84,7 +81,6 @@ function Grid.layoutGridItems(element)
|
|||||||
-- Apply alignment within grid cell (default to stretch)
|
-- Apply alignment within grid cell (default to stretch)
|
||||||
local effectiveAlignItems = element.alignItems or AlignItems.STRETCH
|
local effectiveAlignItems = element.alignItems or AlignItems.STRETCH
|
||||||
|
|
||||||
-- Stretch child to fill cell by default
|
|
||||||
-- BORDER-BOX MODEL: Set border-box dimensions, content area adjusts automatically
|
-- BORDER-BOX MODEL: Set border-box dimensions, content area adjusts automatically
|
||||||
if effectiveAlignItems == AlignItems.STRETCH or effectiveAlignItems == "stretch" then
|
if effectiveAlignItems == AlignItems.STRETCH or effectiveAlignItems == "stretch" then
|
||||||
child.x = cellX
|
child.x = cellX
|
||||||
@@ -110,7 +106,6 @@ function Grid.layoutGridItems(element)
|
|||||||
child.x = cellX + cellWidth - childBorderBoxWidth
|
child.x = cellX + cellWidth - childBorderBoxWidth
|
||||||
child.y = cellY + cellHeight - childBorderBoxHeight
|
child.y = cellY + cellHeight - childBorderBoxHeight
|
||||||
else
|
else
|
||||||
-- Default to stretch
|
|
||||||
child.x = cellX
|
child.x = cellX
|
||||||
child.y = cellY
|
child.y = cellY
|
||||||
child._borderBoxWidth = cellWidth
|
child._borderBoxWidth = cellWidth
|
||||||
@@ -122,7 +117,6 @@ function Grid.layoutGridItems(element)
|
|||||||
child.autosizing.height = false
|
child.autosizing.height = false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Layout child's children if it has any
|
|
||||||
if #child.children > 0 then
|
if #child.children > 0 then
|
||||||
child:layoutChildren()
|
child:layoutChildren()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ function GuiState.registerElement(element)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add element to the z-index ordered list
|
|
||||||
table.insert(GuiState._zIndexOrderedElements, element)
|
table.insert(GuiState._zIndexOrderedElements, element)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -81,7 +80,6 @@ end
|
|||||||
---@param y number Screen Y coordinate
|
---@param y number Screen Y coordinate
|
||||||
---@return boolean True if point is inside element bounds
|
---@return boolean True if point is inside element bounds
|
||||||
local function isPointInElement(element, x, y)
|
local function isPointInElement(element, x, y)
|
||||||
-- Get element bounds
|
|
||||||
local bx = element.x
|
local bx = element.x
|
||||||
local by = element.y
|
local by = element.y
|
||||||
local bw = element._borderBoxWidth or (element.width + element.padding.left + element.padding.right)
|
local bw = element._borderBoxWidth or (element.width + element.padding.left + element.padding.right)
|
||||||
@@ -95,7 +93,6 @@ local function isPointInElement(element, x, y)
|
|||||||
|
|
||||||
-- Check if parent clips content (overflow: hidden, scroll, auto)
|
-- Check if parent clips content (overflow: hidden, scroll, auto)
|
||||||
if overflowX == "hidden" or overflowX == "scroll" or overflowX == "auto" or overflowY == "hidden" or overflowY == "scroll" or overflowY == "auto" then
|
if overflowX == "hidden" or overflowX == "scroll" or overflowX == "auto" or overflowY == "hidden" or overflowY == "scroll" or overflowY == "auto" then
|
||||||
-- Check if point is outside parent's clipping region
|
|
||||||
local parentX = current.x + current.padding.left
|
local parentX = current.x + current.padding.left
|
||||||
local parentY = current.y + current.padding.top
|
local parentY = current.y + current.padding.top
|
||||||
local parentW = current.width
|
local parentW = current.width
|
||||||
@@ -109,7 +106,6 @@ local function isPointInElement(element, x, y)
|
|||||||
current = current.parent
|
current = current.parent
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if point is inside element bounds
|
|
||||||
return x >= bx and x <= bx + bw and y >= by and y <= by + bh
|
return x >= bx and x <= bx + bw and y >= by and y <= by + bh
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -139,14 +135,11 @@ function GuiState.getTopElementAt(x, y)
|
|||||||
for i = #GuiState._zIndexOrderedElements, 1, -1 do
|
for i = #GuiState._zIndexOrderedElements, 1, -1 do
|
||||||
local element = GuiState._zIndexOrderedElements[i]
|
local element = GuiState._zIndexOrderedElements[i]
|
||||||
|
|
||||||
-- Check if point is inside this element
|
|
||||||
if isPointInElement(element, x, y) then
|
if isPointInElement(element, x, y) then
|
||||||
-- Return the first interactive ancestor (or the element itself if interactive)
|
|
||||||
local interactive = findInteractiveAncestor(element)
|
local interactive = findInteractiveAncestor(element)
|
||||||
if interactive then
|
if interactive then
|
||||||
return interactive
|
return interactive
|
||||||
end
|
end
|
||||||
-- If no interactive ancestor, return the element itself
|
|
||||||
-- This preserves backward compatibility for non-interactive overlays
|
-- This preserves backward compatibility for non-interactive overlays
|
||||||
return element
|
return element
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,11 +7,8 @@ ImageCache._cache = {}
|
|||||||
---@param path string -- File path to normalize
|
---@param path string -- File path to normalize
|
||||||
---@return string -- Normalized path
|
---@return string -- Normalized path
|
||||||
local function normalizePath(path)
|
local function normalizePath(path)
|
||||||
-- Remove leading/trailing whitespace
|
|
||||||
path = path:match("^%s*(.-)%s*$")
|
path = path:match("^%s*(.-)%s*$")
|
||||||
-- Convert backslashes to forward slashes
|
|
||||||
path = path:gsub("\\", "/")
|
path = path:gsub("\\", "/")
|
||||||
-- Remove redundant slashes
|
|
||||||
path = path:gsub("/+", "/")
|
path = path:gsub("/+", "/")
|
||||||
return path
|
return path
|
||||||
end
|
end
|
||||||
@@ -29,12 +26,10 @@ function ImageCache.load(imagePath, loadImageData)
|
|||||||
|
|
||||||
local normalizedPath = normalizePath(imagePath)
|
local normalizedPath = normalizePath(imagePath)
|
||||||
|
|
||||||
-- Check if already cached
|
|
||||||
if ImageCache._cache[normalizedPath] then
|
if ImageCache._cache[normalizedPath] then
|
||||||
return ImageCache._cache[normalizedPath].image, nil
|
return ImageCache._cache[normalizedPath].image, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Try to load the image
|
|
||||||
local success, imageOrError = pcall(love.graphics.newImage, normalizedPath)
|
local success, imageOrError = pcall(love.graphics.newImage, normalizedPath)
|
||||||
if not success then
|
if not success then
|
||||||
return nil, string.format("Failed to load image '%s': %s", imagePath, tostring(imageOrError))
|
return nil, string.format("Failed to load image '%s': %s", imagePath, tostring(imageOrError))
|
||||||
@@ -43,7 +38,6 @@ function ImageCache.load(imagePath, loadImageData)
|
|||||||
local image = imageOrError
|
local image = imageOrError
|
||||||
local imgData = nil
|
local imgData = nil
|
||||||
|
|
||||||
-- Load ImageData if requested
|
|
||||||
if loadImageData then
|
if loadImageData then
|
||||||
local dataSuccess, dataOrError = pcall(love.image.newImageData, normalizedPath)
|
local dataSuccess, dataOrError = pcall(love.image.newImageData, normalizedPath)
|
||||||
if dataSuccess then
|
if dataSuccess then
|
||||||
@@ -51,7 +45,6 @@ function ImageCache.load(imagePath, loadImageData)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Cache the image
|
|
||||||
ImageCache._cache[normalizedPath] = {
|
ImageCache._cache[normalizedPath] = {
|
||||||
image = image,
|
image = image,
|
||||||
imageData = imgData,
|
imageData = imgData,
|
||||||
@@ -96,7 +89,6 @@ function ImageCache.remove(imagePath)
|
|||||||
|
|
||||||
local normalizedPath = normalizePath(imagePath)
|
local normalizedPath = normalizePath(imagePath)
|
||||||
if ImageCache._cache[normalizedPath] then
|
if ImageCache._cache[normalizedPath] then
|
||||||
-- Release the image
|
|
||||||
local cached = ImageCache._cache[normalizedPath]
|
local cached = ImageCache._cache[normalizedPath]
|
||||||
if cached.image then
|
if cached.image then
|
||||||
cached.image:release()
|
cached.image:release()
|
||||||
@@ -112,7 +104,6 @@ end
|
|||||||
|
|
||||||
--- Clear all cached images
|
--- Clear all cached images
|
||||||
function ImageCache.clear()
|
function ImageCache.clear()
|
||||||
-- Release all images
|
|
||||||
for path, cached in pairs(ImageCache._cache) do
|
for path, cached in pairs(ImageCache._cache) do
|
||||||
if cached.image then
|
if cached.image then
|
||||||
cached.image:release()
|
cached.image:release()
|
||||||
|
|||||||
@@ -6,13 +6,8 @@ local function formatError(module, message)
|
|||||||
return string.format("[FlexLove.%s] %s", module, message)
|
return string.format("[FlexLove.%s] %s", module, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ====================
|
|
||||||
-- ImageDataReader
|
|
||||||
-- ====================
|
|
||||||
|
|
||||||
local ImageDataReader = {}
|
local ImageDataReader = {}
|
||||||
|
|
||||||
--- Load ImageData from a file path
|
|
||||||
---@param imagePath string
|
---@param imagePath string
|
||||||
---@return love.ImageData
|
---@return love.ImageData
|
||||||
function ImageDataReader.loadImageData(imagePath)
|
function ImageDataReader.loadImageData(imagePath)
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ local function formatError(module, message)
|
|||||||
return string.format("[FlexLove.%s] %s", module, message)
|
return string.format("[FlexLove.%s] %s", module, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ====================
|
|
||||||
-- ImageRenderer
|
|
||||||
-- ====================
|
|
||||||
|
|
||||||
---@class ImageRenderer
|
---@class ImageRenderer
|
||||||
local ImageRenderer = {}
|
local ImageRenderer = {}
|
||||||
|
|
||||||
@@ -26,7 +22,6 @@ function ImageRenderer.calculateFit(imageWidth, imageHeight, boundsWidth, bounds
|
|||||||
fitMode = fitMode or "fill"
|
fitMode = fitMode or "fill"
|
||||||
objectPosition = objectPosition or "center center"
|
objectPosition = objectPosition or "center center"
|
||||||
|
|
||||||
-- Validate inputs
|
|
||||||
if imageWidth <= 0 or imageHeight <= 0 or boundsWidth <= 0 or boundsHeight <= 0 then
|
if imageWidth <= 0 or imageHeight <= 0 or boundsWidth <= 0 or boundsHeight <= 0 then
|
||||||
error(formatError("ImageRenderer", "Dimensions must be positive"))
|
error(formatError("ImageRenderer", "Dimensions must be positive"))
|
||||||
end
|
end
|
||||||
@@ -44,7 +39,6 @@ function ImageRenderer.calculateFit(imageWidth, imageHeight, boundsWidth, bounds
|
|||||||
scaleY = 1, -- Scale factor Y
|
scaleY = 1, -- Scale factor Y
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Calculate based on fit mode
|
|
||||||
if fitMode == "fill" then
|
if fitMode == "fill" then
|
||||||
-- Stretch to fill bounds (may distort)
|
-- Stretch to fill bounds (may distort)
|
||||||
result.scaleX = boundsWidth / imageWidth
|
result.scaleX = boundsWidth / imageWidth
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
---@class ThemeManager
|
---@class ThemeManager
|
||||||
---@field theme string? -- Theme name to use
|
---@field theme string?
|
||||||
---@field themeComponent string? -- Component name from theme (e.g., "button", "panel")
|
---@field themeComponent string?
|
||||||
---@field _themeState string -- Current theme state (normal, hover, pressed, active, disabled)
|
---@field _themeState string -- Current theme state (normal, hover, pressed, active, disabled)
|
||||||
---@field disabled boolean -- If true, element is disabled
|
---@field disabled boolean
|
||||||
---@field active boolean -- If true, element is in active state (e.g., focused input)
|
---@field active boolean
|
||||||
---@field disableHighlight boolean -- If true, disable pressed highlight overlay
|
---@field disableHighlight boolean -- If true, disable pressed highlight overlay
|
||||||
---@field scaleCorners number? -- Scale multiplier for 9-patch corners/edges
|
---@field scaleCorners number? -- Scale multiplier for 9-patch corners/edges
|
||||||
---@field scalingAlgorithm string? -- "nearest" or "bilinear" scaling for 9-patch
|
---@field scalingAlgorithm string? -- "nearest" or "bilinear" scaling for 9-patch
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
local ThemeManager = {}
|
local ThemeManager = {}
|
||||||
ThemeManager.__index = ThemeManager
|
ThemeManager.__index = ThemeManager
|
||||||
|
|
||||||
--- Create new ThemeManager instance
|
|
||||||
---@param config table Configuration options
|
---@param config table Configuration options
|
||||||
---@param deps table Dependencies {Theme: Theme module}
|
---@param deps table Dependencies {Theme: Theme module}
|
||||||
---@return ThemeManager
|
---@return ThemeManager
|
||||||
@@ -20,10 +19,8 @@ function ThemeManager.new(config, deps)
|
|||||||
local Theme = deps.Theme
|
local Theme = deps.Theme
|
||||||
local self = setmetatable({}, ThemeManager)
|
local self = setmetatable({}, ThemeManager)
|
||||||
|
|
||||||
-- Store dependency for instance methods
|
|
||||||
self._Theme = Theme
|
self._Theme = Theme
|
||||||
|
|
||||||
-- Theme configuration
|
|
||||||
self.theme = config.theme
|
self.theme = config.theme
|
||||||
self.themeComponent = config.themeComponent
|
self.themeComponent = config.themeComponent
|
||||||
self.disabled = config.disabled or false
|
self.disabled = config.disabled or false
|
||||||
@@ -32,20 +29,17 @@ function ThemeManager.new(config, deps)
|
|||||||
self.scaleCorners = config.scaleCorners
|
self.scaleCorners = config.scaleCorners
|
||||||
self.scalingAlgorithm = config.scalingAlgorithm
|
self.scalingAlgorithm = config.scalingAlgorithm
|
||||||
|
|
||||||
-- Internal state
|
|
||||||
self._themeState = "normal"
|
self._themeState = "normal"
|
||||||
self._element = nil
|
self._element = nil
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Initialize ThemeManager with parent element reference
|
|
||||||
---@param element table The parent Element
|
---@param element table The parent Element
|
||||||
function ThemeManager:initialize(element)
|
function ThemeManager:initialize(element)
|
||||||
self._element = element
|
self._element = element
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Update theme state based on interaction state
|
|
||||||
---@param isHovered boolean Whether element is hovered
|
---@param isHovered boolean Whether element is hovered
|
||||||
---@param isPressed boolean Whether element is pressed
|
---@param isPressed boolean Whether element is pressed
|
||||||
---@param isFocused boolean Whether element is focused
|
---@param isFocused boolean Whether element is focused
|
||||||
@@ -54,7 +48,6 @@ end
|
|||||||
function ThemeManager:updateState(isHovered, isPressed, isFocused, isDisabled)
|
function ThemeManager:updateState(isHovered, isPressed, isFocused, isDisabled)
|
||||||
local newState = "normal"
|
local newState = "normal"
|
||||||
|
|
||||||
-- State priority: disabled > active > pressed > hover > normal
|
|
||||||
if isDisabled or self.disabled then
|
if isDisabled or self.disabled then
|
||||||
newState = "disabled"
|
newState = "disabled"
|
||||||
elseif self.active then
|
elseif self.active then
|
||||||
@@ -69,31 +62,21 @@ function ThemeManager:updateState(isHovered, isPressed, isFocused, isDisabled)
|
|||||||
return newState
|
return newState
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get current theme state
|
|
||||||
---@return string The current theme state
|
---@return string The current theme state
|
||||||
function ThemeManager:getState()
|
function ThemeManager:getState()
|
||||||
return self._themeState
|
return self._themeState
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set theme state directly
|
|
||||||
---@param state string The theme state to set
|
---@param state string The theme state to set
|
||||||
function ThemeManager:setState(state)
|
function ThemeManager:setState(state)
|
||||||
self._themeState = state
|
self._themeState = state
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check if this ThemeManager has a theme component
|
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function ThemeManager:hasThemeComponent()
|
function ThemeManager:hasThemeComponent()
|
||||||
return self.themeComponent ~= nil
|
return self.themeComponent ~= nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the theme component name
|
|
||||||
---@return string?
|
|
||||||
function ThemeManager:getThemeComponent()
|
|
||||||
return self.themeComponent
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Get the theme to use (element-specific or active theme)
|
|
||||||
---@return table? The theme object or nil
|
---@return table? The theme object or nil
|
||||||
function ThemeManager:getTheme()
|
function ThemeManager:getTheme()
|
||||||
if self.theme then
|
if self.theme then
|
||||||
@@ -102,7 +85,6 @@ function ThemeManager:getTheme()
|
|||||||
return self._Theme.getActive()
|
return self._Theme.getActive()
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the component definition from the theme
|
|
||||||
---@return table? The component definition or nil
|
---@return table? The component definition or nil
|
||||||
function ThemeManager:getComponent()
|
function ThemeManager:getComponent()
|
||||||
if not self.themeComponent then
|
if not self.themeComponent then
|
||||||
@@ -117,7 +99,6 @@ function ThemeManager:getComponent()
|
|||||||
return themeToUse.components[self.themeComponent]
|
return themeToUse.components[self.themeComponent]
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the current state's component definition (including state-specific overrides)
|
|
||||||
---@return table? The component definition for current state or nil
|
---@return table? The component definition for current state or nil
|
||||||
function ThemeManager:getStateComponent()
|
function ThemeManager:getStateComponent()
|
||||||
local component = self:getComponent()
|
local component = self:getComponent()
|
||||||
@@ -125,7 +106,6 @@ function ThemeManager:getStateComponent()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check for state-specific override
|
|
||||||
local state = self._themeState
|
local state = self._themeState
|
||||||
if state and state ~= "normal" and component.states and component.states[state] then
|
if state and state ~= "normal" and component.states and component.states[state] then
|
||||||
return component.states[state]
|
return component.states[state]
|
||||||
@@ -134,7 +114,6 @@ function ThemeManager:getStateComponent()
|
|||||||
return component
|
return component
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get property value from theme for current state
|
|
||||||
---@param property string The property name
|
---@param property string The property name
|
||||||
---@return any? The property value or nil
|
---@return any? The property value or nil
|
||||||
function ThemeManager:getStyle(property)
|
function ThemeManager:getStyle(property)
|
||||||
@@ -146,9 +125,8 @@ function ThemeManager:getStyle(property)
|
|||||||
return stateComponent[property]
|
return stateComponent[property]
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get the scaled content padding for current theme state
|
---@param borderBoxWidth number
|
||||||
---@param borderBoxWidth number The element's border box width
|
---@param borderBoxHeight number
|
||||||
---@param borderBoxHeight number The element's border box height
|
|
||||||
---@return table? {left, top, right, bottom} or nil if no contentPadding
|
---@return table? {left, top, right, bottom} or nil if no contentPadding
|
||||||
function ThemeManager:getScaledContentPadding(borderBoxWidth, borderBoxHeight)
|
function ThemeManager:getScaledContentPadding(borderBoxWidth, borderBoxHeight)
|
||||||
if not self.themeComponent then
|
if not self.themeComponent then
|
||||||
@@ -162,7 +140,6 @@ function ThemeManager:getScaledContentPadding(borderBoxWidth, borderBoxHeight)
|
|||||||
|
|
||||||
local component = themeToUse.components[self.themeComponent]
|
local component = themeToUse.components[self.themeComponent]
|
||||||
|
|
||||||
-- Check for state-specific override
|
|
||||||
local state = self._themeState or "normal"
|
local state = self._themeState or "normal"
|
||||||
if state and state ~= "normal" and component.states and component.states[state] then
|
if state and state ~= "normal" and component.states and component.states[state] then
|
||||||
component = component.states[state]
|
component = component.states[state]
|
||||||
@@ -174,7 +151,6 @@ function ThemeManager:getScaledContentPadding(borderBoxWidth, borderBoxHeight)
|
|||||||
|
|
||||||
local contentPadding = component._ninePatchData.contentPadding
|
local contentPadding = component._ninePatchData.contentPadding
|
||||||
|
|
||||||
-- Scale contentPadding to match the actual rendered size
|
|
||||||
local atlasImage = component._loadedAtlas or themeToUse.atlas
|
local atlasImage = component._loadedAtlas or themeToUse.atlas
|
||||||
if atlasImage and type(atlasImage) ~= "string" then
|
if atlasImage and type(atlasImage) ~= "string" then
|
||||||
local originalWidth, originalHeight = atlasImage:getDimensions()
|
local originalWidth, originalHeight = atlasImage:getDimensions()
|
||||||
@@ -192,7 +168,6 @@ function ThemeManager:getScaledContentPadding(borderBoxWidth, borderBoxHeight)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get contentAutoSizingMultiplier from theme
|
|
||||||
---@return number? The multiplier or nil
|
---@return number? The multiplier or nil
|
||||||
function ThemeManager:getContentAutoSizingMultiplier()
|
function ThemeManager:getContentAutoSizingMultiplier()
|
||||||
if not self.themeComponent then
|
if not self.themeComponent then
|
||||||
@@ -204,7 +179,6 @@ function ThemeManager:getContentAutoSizingMultiplier()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- First check if themeComponent has a multiplier
|
|
||||||
if self.themeComponent then
|
if self.themeComponent then
|
||||||
local component = themeToUse.components[self.themeComponent]
|
local component = themeToUse.components[self.themeComponent]
|
||||||
if component and component.contentAutoSizingMultiplier then
|
if component and component.contentAutoSizingMultiplier then
|
||||||
@@ -233,7 +207,6 @@ function ThemeManager:getDefaultFontFamily()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Set theme and component
|
|
||||||
---@param themeName string? The theme name
|
---@param themeName string? The theme name
|
||||||
---@param componentName string? The component name
|
---@param componentName string? The component name
|
||||||
function ThemeManager:setTheme(themeName, componentName)
|
function ThemeManager:setTheme(themeName, componentName)
|
||||||
@@ -241,16 +214,4 @@ function ThemeManager:setTheme(themeName, componentName)
|
|||||||
self.themeComponent = componentName
|
self.themeComponent = componentName
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Get scale corners multiplier
|
|
||||||
---@return number?
|
|
||||||
function ThemeManager:getScaleCorners()
|
|
||||||
return self.scaleCorners
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Get scaling algorithm
|
|
||||||
---@return string?
|
|
||||||
function ThemeManager:getScalingAlgorithm()
|
|
||||||
return self.scalingAlgorithm
|
|
||||||
end
|
|
||||||
|
|
||||||
return ThemeManager
|
return ThemeManager
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
local Units = {}
|
local Units = {}
|
||||||
|
|
||||||
--- Parse a unit value (string or number) into value and unit type
|
|
||||||
---@param value string|number
|
---@param value string|number
|
||||||
---@return number, string -- Returns numeric value and unit type ("px", "%", "vw", "vh")
|
---@return number, string -- Returns numeric value and unit type ("px", "%", "vw", "vh")
|
||||||
function Units.parse(value)
|
function Units.parse(value)
|
||||||
@@ -71,7 +70,6 @@ function Units.getViewport()
|
|||||||
return Gui._cachedViewport.width, Gui._cachedViewport.height
|
return Gui._cachedViewport.width, Gui._cachedViewport.height
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Query viewport dimensions normally
|
|
||||||
if love.graphics and love.graphics.getDimensions then
|
if love.graphics and love.graphics.getDimensions then
|
||||||
return love.graphics.getDimensions()
|
return love.graphics.getDimensions()
|
||||||
else
|
else
|
||||||
@@ -80,9 +78,8 @@ function Units.getViewport()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Apply base scaling to a value
|
|
||||||
---@param value number
|
---@param value number
|
||||||
---@param axis "x"|"y" -- Which axis to scale on
|
---@param axis "x"|"y"
|
||||||
---@param scaleFactors {x:number, y:number}
|
---@param scaleFactors {x:number, y:number}
|
||||||
---@return number
|
---@return number
|
||||||
function Units.applyBaseScale(value, axis, scaleFactors)
|
function Units.applyBaseScale(value, axis, scaleFactors)
|
||||||
@@ -93,7 +90,6 @@ function Units.applyBaseScale(value, axis, scaleFactors)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Resolve units for spacing properties (padding, margin)
|
|
||||||
---@param spacingProps table?
|
---@param spacingProps table?
|
||||||
---@param parentWidth number
|
---@param parentWidth number
|
||||||
---@param parentHeight number
|
---@param parentHeight number
|
||||||
@@ -106,7 +102,6 @@ function Units.resolveSpacing(spacingProps, parentWidth, parentHeight)
|
|||||||
local viewportWidth, viewportHeight = Units.getViewport()
|
local viewportWidth, viewportHeight = Units.getViewport()
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
-- Handle shorthand properties first
|
|
||||||
local vertical = spacingProps.vertical
|
local vertical = spacingProps.vertical
|
||||||
local horizontal = spacingProps.horizontal
|
local horizontal = spacingProps.horizontal
|
||||||
|
|
||||||
@@ -124,7 +119,6 @@ function Units.resolveSpacing(spacingProps, parentWidth, parentHeight)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Handle individual sides
|
|
||||||
for _, side in ipairs({ "top", "right", "bottom", "left" }) do
|
for _, side in ipairs({ "top", "right", "bottom", "left" }) do
|
||||||
local value = spacingProps[side]
|
local value = spacingProps[side]
|
||||||
if value then
|
if value then
|
||||||
@@ -136,7 +130,6 @@ function Units.resolveSpacing(spacingProps, parentWidth, parentHeight)
|
|||||||
result[side] = value
|
result[side] = value
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Use fallbacks
|
|
||||||
if side == "top" or side == "bottom" then
|
if side == "top" or side == "bottom" then
|
||||||
result[side] = vertical or 0
|
result[side] = vertical or 0
|
||||||
else
|
else
|
||||||
@@ -148,9 +141,8 @@ function Units.resolveSpacing(spacingProps, parentWidth, parentHeight)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check if a unit string is valid
|
---@param unitStr string
|
||||||
---@param unitStr string -- Unit string to validate (e.g., "10px", "50%", "20vw")
|
---@return boolean
|
||||||
---@return boolean -- Returns true if unit string is valid
|
|
||||||
function Units.isValid(unitStr)
|
function Units.isValid(unitStr)
|
||||||
if type(unitStr) ~= "string" then
|
if type(unitStr) ~= "string" then
|
||||||
return false
|
return false
|
||||||
@@ -161,7 +153,6 @@ function Units.isValid(unitStr)
|
|||||||
return validUnits[unit] == true
|
return validUnits[unit] == true
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Parse and resolve a unit value in one call
|
|
||||||
---@param value string|number -- Value to parse and resolve
|
---@param value string|number -- Value to parse and resolve
|
||||||
---@param viewportWidth number -- Current viewport width
|
---@param viewportWidth number -- Current viewport width
|
||||||
---@param viewportHeight number -- Current viewport height
|
---@param viewportHeight number -- Current viewport height
|
||||||
|
|||||||
Reference in New Issue
Block a user