214 lines
17 KiB
Lua
214 lines
17 KiB
Lua
--=====================================--
|
|
-- only used for types with lua_ls, if you're using a different LSP (or none), you can remove this file --
|
|
--=====================================--
|
|
|
|
--=====================================--
|
|
-- For Animation.lua
|
|
--=====================================--
|
|
---@class AnimationProps
|
|
---@field duration number -- Duration in seconds
|
|
---@field start table -- Starting values (can contain: width, height, opacity, x, y, gap, imageOpacity, backgroundColor, borderColor, textColor, padding, margin, cornerRadius, transform, etc.)
|
|
---@field final table -- Final values (same properties as start)
|
|
---@field easing string? -- Easing function name: "linear", "easeInQuad", "easeOutQuad", "easeInOutQuad", "easeInCubic", "easeOutCubic", "easeInOutCubic", "easeInQuart", "easeOutQuart", "easeInExpo", "easeOutExpo" (default: "linear")
|
|
---@field onStart fun(animation:Animation, element:Element?)? -- Called when animation starts
|
|
---@field onUpdate fun(animation:Animation, element:Element?, progress:number)? -- Called each frame with progress (0-1)
|
|
---@field onComplete fun(animation:Animation, element:Element?)? -- Called when animation completes
|
|
---@field onCancel fun(animation:Animation, element:Element?)? -- Called when animation is cancelled
|
|
---@field transform table? -- Additional transform properties (legacy support)
|
|
---@field transition table? -- Transition properties (legacy support)
|
|
local AnimationProps = {}
|
|
|
|
---@class TransformProps
|
|
---@field scale {x?:number, y?:number}?
|
|
---@field rotate number?
|
|
---@field translate {x?:number, y?:number}?
|
|
---@field skew {x?:number, y?:number}?
|
|
|
|
---@class TransitionProps
|
|
---@field duration number?
|
|
---@field easing string?
|
|
|
|
--=====================================--
|
|
-- For Element.lua
|
|
--=====================================--
|
|
---@class ElementProps
|
|
---@field id string? -- Unique identifier for the element (auto-generated in immediate mode if not provided)
|
|
---@field parent Element? -- Parent element for hierarchical structure
|
|
---@field x number|string? -- X coordinate of the element (default: 0)
|
|
---@field y number|string? -- Y coordinate of the element (default: 0)
|
|
---@field z number? -- Z-index for layering (default: 0)
|
|
---@field width number|string? -- Width of the element (default: calculated automatically)
|
|
---@field height number|string? -- Height of the element (default: calculated automatically)
|
|
---@field top number|string? -- Offset from top edge (CSS-style positioning)
|
|
---@field right number|string? -- Offset from right edge (CSS-style positioning)
|
|
---@field bottom number|string? -- Offset from bottom edge (CSS-style positioning)
|
|
---@field left number|string? -- Offset from left edge (CSS-style positioning)
|
|
---@field border Border? -- Border configuration for the element
|
|
---@field borderColor Color? -- Color of the border (default: black)
|
|
---@field opacity number? -- Element opacity 0-1 (default: 1)
|
|
---@field visibility "visible"|"hidden"? -- Element visibility (default: "visible")
|
|
---@field backgroundColor Color? -- Background color (default: transparent)
|
|
---@field cornerRadius number|{topLeft:number?, topRight:number?, bottomLeft:number?, bottomRight:number?}? -- Corner radius: number (all corners) or table for individual corners (default: 0)
|
|
---@field gap number|string? -- Space between children elements (default: 0)
|
|
---@field padding number|string|{top:number|string?, right:number|string?, bottom:number|string?, left:number|string?, horizontal:number|string?, vertical:number|string?}? -- Padding around children: single value for all sides or table for individual sides (default: {top=0, right=0, bottom=0, left=0})
|
|
---@field margin number|string|{top:number|string?, right:number|string?, bottom:number|string?, left:number|string?, horizontal:number|string?, vertical:number|string?}? -- Margin around element: single value for all sides or table for individual sides (default: {top=0, right=0, bottom=0, left=0})
|
|
---@field text string? -- Text content to display (default: nil)
|
|
---@field textAlign TextAlign? -- Alignment of the text content (default: START)
|
|
---@field textColor Color? -- Color of the text content (default: black or theme text color)
|
|
---@field textSize number|string? -- Font size: number (px), string with units ("2vh", "10%"), or preset ("xxs"|"xs"|"sm"|"md"|"lg"|"xl"|"xxl"|"3xl"|"4xl") (default: "md" or 12px)
|
|
---@field minTextSize number? -- Minimum text size in pixels for auto-scaling
|
|
---@field maxTextSize number? -- Maximum text size in pixels for auto-scaling
|
|
---@field fontFamily string? -- Font family name from theme or path to font file (default: theme default or system default, inherits from parent)
|
|
---@field autoScaleText boolean? -- Whether text should auto-scale with window size (default: true)
|
|
---@field positioning Positioning? -- Layout positioning mode: "absolute"|"relative"|"flex"|"grid" (default: RELATIVE)
|
|
---@field flexDirection FlexDirection? -- Direction of flex layout: "horizontal"|"vertical"|"row"|"column" (row→horizontal, column→vertical, default: HORIZONTAL)
|
|
---@field justifyContent JustifyContent? -- Alignment of items along main axis (default: FLEX_START)
|
|
---@field alignItems AlignItems? -- Alignment of items along cross axis (default: STRETCH)
|
|
---@field alignContent AlignContent? -- Alignment of lines in multi-line flex containers (default: STRETCH)
|
|
---@field flexWrap FlexWrap? -- Whether children wrap to multiple lines: "nowrap"|"wrap"|"wrap-reverse" (default: NOWRAP)
|
|
---@field justifySelf JustifySelf? -- Alignment of the item itself along main axis (default: AUTO)
|
|
---@field alignSelf AlignSelf? -- Alignment of the item itself along cross axis (default: AUTO)
|
|
---@field onEvent fun(element:Element, event:InputEvent)? -- Callback function for interaction events
|
|
---@field onEventDeferred boolean? -- Whether onEvent callback should be deferred until after canvases are released (default: false)
|
|
---@field onFocus fun(element:Element)? -- Callback when element receives focus
|
|
---@field onFocusDeferred boolean? -- Whether onFocus callback should be deferred (default: false)
|
|
---@field onBlur fun(element:Element)? -- Callback when element loses focus
|
|
---@field onBlurDeferred boolean? -- Whether onBlur callback should be deferred (default: false)
|
|
---@field onTextInput fun(element:Element, text:string)? -- Callback when text is input
|
|
---@field onTextInputDeferred boolean? -- Whether onTextInput callback should be deferred (default: false)
|
|
---@field onTextChange fun(element:Element, text:string)? -- Callback when text content changes
|
|
---@field onTextChangeDeferred boolean? -- Whether onTextChange callback should be deferred (default: false)
|
|
---@field onEnter fun(element:Element)? -- Callback when Enter key is pressed
|
|
---@field onEnterDeferred boolean? -- Whether onEnter callback should be deferred (default: false)
|
|
---@field transform TransformProps? -- Transform properties for animations and styling
|
|
---@field transition TransitionProps? -- Transition settings for animations
|
|
---@field gridRows number? -- Number of rows in the grid (default: 1)
|
|
---@field gridColumns number? -- Number of columns in the grid (default: 1)
|
|
---@field columnGap number|string? -- Gap between grid columns (default: 0)
|
|
---@field rowGap number|string? -- Gap between grid rows (default: 0)
|
|
---@field theme string? -- Theme name to use (e.g., "space", "metal"). Defaults to theme from flexlove.init()
|
|
---@field themeComponent string? -- Theme component to use (e.g., "panel", "button", "input"). If nil, no theme is applied
|
|
---@field disabled boolean? -- Whether the element is disabled (default: false)
|
|
---@field active boolean? -- Whether the element is active/focused (for inputs, default: false)
|
|
---@field disableHighlight boolean? -- Whether to disable the pressed state highlight overlay (default: false, or true when using themeComponent)
|
|
---@field themeStateLock boolean|string? -- Lock theme state: true/"default" = lock to base state, false = normal behavior, string = specific state ("hover", "pressed", "active", "disabled") (default: false)
|
|
---@field contentAutoSizingMultiplier {width:number?, height:number?}? -- Multiplier for auto-sized content dimensions (default: sourced from theme or {1, 1})
|
|
---@field scaleCorners number? -- Scale multiplier for 9-patch corners/edges. E.g., 2 = 2x size (overrides theme setting)
|
|
---@field scalingAlgorithm "nearest"|"bilinear"? -- Scaling algorithm for 9-patch corners: "nearest" (sharp/pixelated) or "bilinear" (smooth) (overrides theme setting)
|
|
---@field contentBlur {radius:number, quality:number?}? -- Blur the element's content including children (radius: pixels, quality: 1-10, default(quality): 5)
|
|
---@field backdropBlur {radius:number, quality:number?}? -- Blur content behind the element (radius: pixels, quality: 1-10, default(quality): 5)
|
|
---@field editable boolean? -- Whether the element is editable (default: false)
|
|
---@field multiline boolean? -- Whether the element supports multiple lines (default: false)
|
|
---@field textWrap boolean|"word"|"char"? -- Text wrapping mode (default: false for single-line, "word" for multi-line)
|
|
---@field maxLines number? -- Maximum number of lines (default: nil)
|
|
---@field maxLength number? -- Maximum text length in characters (default: nil)
|
|
---@field placeholder string? -- Placeholder text when empty (default: nil)
|
|
---@field passwordMode boolean? -- Whether to display text as password (default: false, disables multiline)
|
|
---@field inputType "text"|"number"|"email"|"url"? -- Input type for validation (default: "text")
|
|
---@field textOverflow "clip"|"ellipsis"|"scroll"? -- Text overflow behavior (default: "clip")
|
|
---@field scrollable boolean? -- Whether text is scrollable (default: false for single-line, true for multi-line)
|
|
---@field autoGrow boolean? -- Whether element auto-grows with text (default: false for single-line, true for multi-line)
|
|
---@field selectOnFocus boolean? -- Whether to select all text on focus (default: false)
|
|
---@field cursorColor Color? -- Cursor color (default: nil, uses textColor)
|
|
---@field selectionColor Color? -- Selection background color (default: nil, uses theme or default)
|
|
---@field cursorBlinkRate number? -- Cursor blink rate in seconds (default: 0.5)
|
|
---@field overflow "visible"|"hidden"|"scroll"|"auto"? -- Overflow behavior (default: "hidden")
|
|
---@field overflowX "visible"|"hidden"|"scroll"|"auto"? -- X-axis overflow (overrides overflow)
|
|
---@field overflowY "visible"|"hidden"|"scroll"|"auto"? -- Y-axis overflow (overrides overflow)
|
|
---@field scrollbarWidth number? -- Width of scrollbar track in pixels (default: 12)
|
|
---@field scrollbarColor Color? -- Scrollbar thumb color (default: Color.new(0.5, 0.5, 0.5, 0.8))
|
|
---@field scrollbarTrackColor Color? -- Scrollbar track color (default: Color.new(0.2, 0.2, 0.2, 0.5))
|
|
---@field scrollbarRadius number? -- Corner radius for scrollbar (default: 6)
|
|
---@field scrollbarPadding number? -- Padding between scrollbar and edge (default: 2)
|
|
---@field scrollSpeed number? -- Pixels per wheel notch (default: 20)
|
|
---@field smoothScrollEnabled boolean? -- Enable smooth scrolling animation for wheel events (default: false)
|
|
---@field scrollBarStyle string? -- Scrollbar style name from theme (selects from theme.scrollbars, default: uses first scrollbar or fallback rendering)
|
|
---@field scrollbarKnobOffset number|{x:number, y:number}|{horizontal:number, vertical:number}? -- Offset for scrollbar knob/handle position in pixels (number for both axes, or table for per-axis control, default: 0, adds to theme offset)
|
|
---@field hideScrollbars boolean|{vertical:boolean, horizontal:boolean}? -- Hide scrollbars (boolean for both, or table for individual control, default: false)
|
|
---@field imagePath string? -- Path to image file (auto-loads via ImageCache)
|
|
---@field image love.Image? -- Image object to display
|
|
---@field objectFit "fill"|"contain"|"cover"|"scale-down"|"none"? -- Image fit mode (default: "fill")
|
|
---@field objectPosition string? -- Image position like "center center", "top left", "50% 50%" (default: "center center")
|
|
---@field imageOpacity number? -- Image opacity 0-1 (default: 1, combines with element opacity)
|
|
---@field imageRepeat "no-repeat"|"repeat"|"repeat-x"|"repeat-y"|"space"|"round"? -- Image repeat/tiling mode (default: "no-repeat")
|
|
---@field imageTint Color? -- Color to tint the image (default: nil/white, no tint)
|
|
---@field onImageLoad fun(element:Element, image:love.Image)? -- Callback when image loads successfully
|
|
---@field onImageLoadDeferred boolean? -- Whether onImageLoad callback should be deferred (default: false)
|
|
---@field onImageError fun(element:Element, error:string)? -- Callback when image fails to load
|
|
---@field onImageErrorDeferred boolean? -- Whether onImageError callback should be deferred (default: false)
|
|
---@field _scrollX number? -- Internal: scroll X position (restored in immediate mode)
|
|
---@field _scrollY number? -- Internal: scroll Y position (restored in immediate mode)
|
|
---@field userdata table? -- User-defined data storage for custom properties
|
|
local ElementProps = {}
|
|
|
|
---@class Border
|
|
---@field top boolean
|
|
---@field right boolean
|
|
---@field bottom boolean
|
|
---@field left boolean
|
|
local Border = {}
|
|
|
|
---@class TransformProps
|
|
---@field rotate number? Rotation in radians (default: 0)
|
|
---@field scaleX number? X-axis scale (default: 1)
|
|
---@field scaleY number? Y-axis scale (default: 1)
|
|
---@field translateX number? X translation in pixels (default: 0)
|
|
---@field translateY number? Y translation in pixels (default: 0)
|
|
---@field skewX number? X-axis skew in radians (default: 0)
|
|
---@field skewY number? Y-axis skew in radians (default: 0)
|
|
---@field originX number? Transform origin X (0-1, default: 0.5)
|
|
---@field originY number? Transform origin Y (0-1, default: 0.5)
|
|
local TransformProps
|
|
|
|
--=====================================--
|
|
-- For FlexLove.init()
|
|
--=====================================--
|
|
---@class FlexLoveConfig
|
|
---@field baseScale {width:number?, height:number?}? -- Base resolution for responsive scaling (default: nil, no scaling)
|
|
---@field theme string|table? -- Theme name (string) or ThemeDefinition (table) to use (default: nil, no theme)
|
|
---@field immediateMode boolean? -- Enable immediate mode (React-like, recreates UI each frame) vs retained mode (default: false)
|
|
---@field autoFrameManagement boolean? -- Automatically call beginFrame/endFrame (default: false)
|
|
---@field stateRetentionFrames number? -- Number of frames to retain unused state in immediate mode (default: 60)
|
|
---@field maxStateEntries number? -- Maximum number of state entries before forcing cleanup (default: 1000)
|
|
---@field includeStackTrace boolean? -- Include stack traces in error messages (default: true)
|
|
---@field reportingLogLevel LOG_LEVEL? -- Error log level: 1: critical, 2: error, 3: warn, 4: info, 5: debug/all (default: 3:warn)
|
|
---@field errorLogTarget string? -- Error log target: "console", "file", "both" (default: "console")
|
|
---@field errorLogFile string? -- Path to error log file (default: "flexlove_errors.log")
|
|
---@field errorLogMaxSize number? -- Maximum error log file size in bytes (default: 1048576, 1MB)
|
|
---@field maxErrorLogFiles number? -- Maximum number of rotated error log files (default: 5)
|
|
---@field errorLogRotateEnabled boolean? -- Enable error log rotation (default: true)
|
|
---@field performanceMonitoring boolean? -- Enable performance monitoring (default: true)
|
|
---@field performanceHudKey string? -- Key to toggle performance HUD (default: "f3")
|
|
---@field performanceHudPosition {x:number, y:number}? -- Position of performance HUD (default: {x=10, y=10})
|
|
---@field performanceWarningThreshold number? -- Frame time warning threshold in ms (default: 13.0)
|
|
---@field performanceCriticalThreshold number? -- Frame time critical threshold in ms (default: 16.67)
|
|
---@field performanceLogToConsole boolean? -- Log performance metrics to console (default: false)
|
|
---@field performanceWarnings boolean? -- Enable performance warnings (default: false)
|
|
---@field memoryProfiling boolean? -- Enable memory profiling (default: false, auto-enabled in immediate mode)
|
|
---@field gcStrategy string? -- Garbage collection strategy: "auto", "periodic", "manual", "disabled" (default: "auto")
|
|
---@field gcMemoryThreshold number? -- Memory threshold in MB before forcing GC (default: 100)
|
|
---@field gcInterval number? -- Frames between GC steps in periodic mode (default: 60)
|
|
---@field gcStepSize number? -- Work units per GC step, higher = more aggressive (default: 200)
|
|
---@field immediateModeBlurOptimizations boolean? -- Cache blur canvases in immediate mode to avoid re-rendering each frame (default: true)
|
|
local FlexLoveConfig = {}
|
|
|
|
--=====================================--
|
|
-- For State Persistence
|
|
--=====================================--
|
|
---@class ElementStateData
|
|
---@field _focused boolean?
|
|
---@field eventHandler table? -- EventHandler state
|
|
---@field textEditor table? -- TextEditor state
|
|
---@field scrollManager table? -- ScrollManager state
|
|
---@field blur BlurCacheData? -- Blur cache invalidation data
|
|
|
|
---@class BlurCacheData
|
|
---@field _blurX number
|
|
---@field _blurY number
|
|
---@field _blurWidth number
|
|
---@field _blurHeight number
|
|
---@field _backdropBlurRadius number?
|
|
---@field _backdropBlurQuality number?
|
|
---@field _contentBlurRadius number?
|
|
---@field _contentBlurQuality number?
|