diff --git a/src/elements/BaseElement.lua b/src/elements/BaseElement.lua index 6907cc6..d29ec60 100644 --- a/src/elements/BaseElement.lua +++ b/src/elements/BaseElement.lua @@ -31,22 +31,23 @@ BaseElement.defineProperty(BaseElement, "name", {default = "", type = "string"}) --- @property eventCallbacks table BaseElement The event callbacks for the element BaseElement.defineProperty(BaseElement, "eventCallbacks", {default = {}, type = "table"}) - +---@private function BaseElement.defineEvent(class, eventName, requiredEvent) if not rawget(class, '_eventConfigs') then class._eventConfigs = {} end - + class._eventConfigs[eventName] = { requires = requiredEvent and requiredEvent or eventName } end +---@private function BaseElement.registerEventCallback(class, callbackName, ...) local methodName = callbackName:match("^on") and callbackName or "on"..callbackName local events = {...} local mainEvent = events[1] - + class[methodName] = function(self, ...) for _, sysEvent in ipairs(events) do if not self._registeredEvents[sysEvent] then @@ -58,22 +59,19 @@ function BaseElement.registerEventCallback(class, callbackName, ...) end end ---- Creates a new BaseElement instance --- @shortDescription Creates a new BaseElement instance ---- @param props table The properties to initialize the element with ---- @param basalt table The basalt instance --- @return table The newly created BaseElement instance ---- @usage local element = BaseElement.new() +---@private function BaseElement.new() local self = setmetatable({}, BaseElement):__init() return self end ---- Initializes the BaseElement instance --- @shortDescription Initializes the BaseElement instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return table self The initialized instance +---@protected function BaseElement:init(props, basalt) self._props = props self._values.id = uuid() @@ -112,9 +110,9 @@ function BaseElement:init(props, basalt) return self end ---- Post initialization --- @shortDescription Post initialization --- @return table self The BaseElement instance +---@protected function BaseElement:postInit() if(self._props)then for k,v in pairs(self._props)do @@ -197,11 +195,11 @@ function BaseElement:fireEvent(event, ...) return self end ---- Handles all events --- @shortDescription Handles all events --- @param event string The event to handle --- @vararg any The arguments for the event --- @return boolean? handled Whether the event was handled +--- @protected function BaseElement:dispatchEvent(event, ...) if self[event] then return self[event](self, ...) @@ -209,11 +207,11 @@ function BaseElement:dispatchEvent(event, ...) return self:handleEvent(event, ...) end ---- The default event handler for all events --- @shortDescription The default event handler for all events --- @param event string The event to handle --- @vararg any The arguments for the event --- @return boolean? handled Whether the event was handled +--- @protected function BaseElement:handleEvent(event, ...) return false end diff --git a/src/elements/BaseFrame.lua b/src/elements/BaseFrame.lua index ee2361a..fac1eed 100644 --- a/src/elements/BaseFrame.lua +++ b/src/elements/BaseFrame.lua @@ -28,6 +28,7 @@ end}) --- @shortDescription Creates a new Frame instance --- @return BaseFrame object The newly created Frame instance --- @usage local element = BaseFrame.new() +--- @private function BaseFrame.new() local self = setmetatable({}, BaseFrame):__init() self.set("term", term.current()) @@ -35,18 +36,17 @@ function BaseFrame.new() return self end ---- Initializes the Frame instance --- @shortDescription Initializes the Frame instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return table self The initialized instance +--- @protected function BaseFrame:init(props, basalt) Container.init(self, props, basalt) self.set("type", "BaseFrame") return self end ---- Renders a multiBlit to the render Object --- @shortDescription Renders a multiBlit to the render Object --- @param x number The x position to render to --- @param y number The y position to render to @@ -55,41 +55,42 @@ end --- @param text string The text to render --- @param fg string The foreground color --- @param bg string The background color +--- @protected function BaseFrame:multiBlit(x, y, width, height, text, fg, bg) if(x<1)then width = width + x - 1; x = 1 end if(y<1)then height = height + y - 1; y = 1 end self._render:multiBlit(x, y, width, height, text, fg, bg) end ---- Renders a text with a foreground color to the render Object --- @shortDescription Renders a text with a foreground color to the render Object --- @param x number The x position to render to --- @param y number The y position to render to --- @param text string The text to render --- @param fg colors The foreground color +--- @protected function BaseFrame:textFg(x, y, text, fg) if x < 1 then text = string.sub(text, 1 - x); x = 1 end self._render:textFg(x, y, text, fg) end ---- Renders a text with a background color to the render Object --- @shortDescription Renders a text with a background color to the render Object --- @param x number The x position to render to --- @param y number The y position to render to --- @param text string The text to render --- @param bg colors The background color +--- @protected function BaseFrame:textBg(x, y, text, bg) if x < 1 then text = string.sub(text, 1 - x); x = 1 end self._render:textBg(x, y, text, bg) end ---- Renders a text with a foreground and background color to the render Object --- @shortDescription Renders a text with a foreground and background color to the render Object --- @param x number The x position to render to --- @param y number The y position to render to --- @param text string The text to render --- @param fg string The foreground color --- @param bg string The background color +--- @protected function BaseFrame:blit(x, y, text, fg, bg) if x < 1 then text = string.sub(text, 1 - x) @@ -109,13 +110,18 @@ function BaseFrame:setCursor(x, y, blink, color) self._render:setCursor(x, y, blink, color) end ----@private +--- @shortDescription Handles mouse up events +--- @param button number The button that was released +--- @param x number The x position of the mouse +--- @param y number The y position of the mouse +--- @protected function BaseFrame:mouse_up(button, x, y) Container.mouse_up(self, button, x, y) Container.mouse_release(self, button, x, y) end ----@private +--- @shortDescription Resizes the Frame +--- @protected function BaseFrame:term_resize() local width, height = self.get("term").getSize() if(width == self.get("width") and height == self.get("height")) then @@ -127,8 +133,8 @@ function BaseFrame:term_resize() self._renderUpdate = true end ---- Renders the Frame --- @shortDescription Renders the Frame +--- @protected function BaseFrame:render() if(self._renderUpdate) then if self._render ~= nil then diff --git a/src/elements/Button.lua b/src/elements/Button.lua index f2aff87..7c07815 100644 --- a/src/elements/Button.lua +++ b/src/elements/Button.lua @@ -12,13 +12,12 @@ Button.__index = Button ---@property text string Button Button text Button.defineProperty(Button, "text", {default = "Button", type = "string", canTriggerRender = true}) ----@event mouse_click The event that is triggered when the button is clicked Button.defineEvent(Button, "mouse_click") Button.defineEvent(Button, "mouse_up") ---- Creates a new Button instance --- @shortDescription Creates a new Button instance --- @return table self The created instance +--- @private function Button.new() local self = setmetatable({}, Button):__init() self.set("width", 10) @@ -27,17 +26,17 @@ function Button.new() return self end ---- Initializes the Button instance --- @shortDescription Initializes the Button instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance +--- @protected function Button:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "Button") end ---- Renders the Button --- @shortDescription Renders the Button +--- @protected function Button:render() VisualElement.render(self) local text = self.get("text") diff --git a/src/elements/Checkbox.lua b/src/elements/Checkbox.lua index 9a98285..8c45d63 100644 --- a/src/elements/Checkbox.lua +++ b/src/elements/Checkbox.lua @@ -31,29 +31,29 @@ Checkbox.defineProperty(Checkbox, "autoSize", {default = true, type = "boolean"} Checkbox.defineEvent(Checkbox, "mouse_click") ---- Creates a new Checkbox instance --- @shortDescription Creates a new Checkbox instance --- @return Checkbox self The created instance +--- @protected function Checkbox.new() local self = setmetatable({}, Checkbox):__init() return self end ---- Initializes the Checkbox instance --- @shortDescription Initializes the Checkbox instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance +--- @protected function Checkbox:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "Checkbox") end ---- Handles mouse click events --- @shortDescription Handles mouse click events --- @param button number The button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean Clicked Whether the event was handled +--- @protected function Checkbox:mouse_click(button, x, y) if VisualElement.mouse_click(self, button, x, y) then self.set("checked", not self.get("checked")) @@ -63,8 +63,8 @@ function Checkbox:mouse_click(button, x, y) return false end ---- Renders the Checkbox --- @shortDescription Renders the Checkbox +--- @protected function Checkbox:render() VisualElement.render(self) diff --git a/src/elements/Container.lua b/src/elements/Container.lua index 2b55637..292dc8a 100644 --- a/src/elements/Container.lua +++ b/src/elements/Container.lua @@ -83,15 +83,16 @@ end --- Creates a new Container instance --- @shortDescription Creates a new Container instance --- @return Container self The new container instance +--- @private function Container.new() local self = setmetatable({}, Container):__init() return self end ---- Initializes the Container instance --- @shortDescription Initializes the Container instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance +--- @protected function Container:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "Container") @@ -337,7 +338,7 @@ end --- @vararg any The event arguments --- @return boolean handled Whether the event was handled --- @return table child? The child that handled the event -function Container:callChildrenEvents(visibleOnly, event, ...) +function Container:callChildrenEvent(visibleOnly, event, ...) local children = visibleOnly and self.get("visibleChildrenEvents") or self.get("childrenEvents") if children[event] then local events = children[event] @@ -351,27 +352,27 @@ function Container:callChildrenEvents(visibleOnly, event, ...) return false end ---- Default handler for events --- @shortDescription Default handler for events --- @param event string The event to handle --- @vararg any The event arguments --- @return boolean handled Whether the event was handled +--- @protected function Container:handleEvent(event, ...) VisualElement.handleEvent(self, event, ...) local args = convertMousePosition(self, event, ...) - return self:callChildrenEvents(false, event, table.unpack(args)) + return self:callChildrenEvent(false, event, table.unpack(args)) end ---- Handles mouse click events --- @shortDescription Handles mouse click events --- @param button number The button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean handled Whether the event was handled +--- @protected function Container:mouse_click(button, x, y) if VisualElement.mouse_click(self, button, x, y) then local args = convertMousePosition(self, "mouse_click", button, x, y) - local success, child = self:callChildrenEvents(true, "mouse_click", table.unpack(args)) + local success, child = self:callChildrenEvent(true, "mouse_click", table.unpack(args)) if(success)then self.set("focusedChild", child) return true @@ -382,16 +383,16 @@ function Container:mouse_click(button, x, y) return false end ---- Handles mouse up events --- @shortDescription Handles mouse up events --- @param button number The button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean handled Whether the event was handled +--- @protected function Container:mouse_up(button, x, y) if VisualElement.mouse_up(self, button, x, y) then local args = convertMousePosition(self, "mouse_up", button, x, y) - local success, child = self:callChildrenEvents(true, "mouse_up", table.unpack(args)) + local success, child = self:callChildrenEvent(true, "mouse_up", table.unpack(args)) if(success)then return true end @@ -399,27 +400,27 @@ function Container:mouse_up(button, x, y) return false end ---- Handles mouse release events --- @shortDescription Handles mouse release events --- @param button number The button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click +--- @protected function Container:mouse_release(button, x, y) VisualElement.mouse_release(self, button, x, y) local args = convertMousePosition(self, "mouse_release", button, x, y) - self:callChildrenEvents(false, "mouse_release", table.unpack(args)) + self:callChildrenEvent(false, "mouse_release", table.unpack(args)) end ---- Handles mouse move events --- @shortDescription Handles mouse move events --- @param _ number unknown --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean handled Whether the event was handled +--- @protected function Container:mouse_move(_, x, y) if VisualElement.mouse_move(self, _, x, y) then local args = convertMousePosition(self, "mouse_move", _, x, y) - local success, child = self:callChildrenEvents(true, "mouse_move", table.unpack(args)) + local success, child = self:callChildrenEvent(true, "mouse_move", table.unpack(args)) if(success)then return true end @@ -427,16 +428,16 @@ function Container:mouse_move(_, x, y) return false end ---- Handles mouse drag events --- @shortDescription Handles mouse drag events --- @param button number The button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean handled Whether the event was handled +--- @protected function Container:mouse_drag(button, x, y) if VisualElement.mouse_drag(self, button, x, y) then local args = convertMousePosition(self, "mouse_drag", button, x, y) - local success, child = self:callChildrenEvents(true, "mouse_drag", table.unpack(args)) + local success, child = self:callChildrenEvent(true, "mouse_drag", table.unpack(args)) if(success)then return true end @@ -444,15 +445,15 @@ function Container:mouse_drag(button, x, y) return false end ---- Handles mouse scroll events --- @shortDescription Handles mouse scroll events --- @param direction number The direction of the scroll --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean handled Whether the event was handled +--- @protected function Container:mouse_scroll(direction, x, y) local args = convertMousePosition(self, "mouse_scroll", direction, x, y) - local success, child = self:callChildrenEvents(true, "mouse_scroll", table.unpack(args)) + local success, child = self:callChildrenEvent(true, "mouse_scroll", table.unpack(args)) if(success)then return true end @@ -462,10 +463,10 @@ function Container:mouse_scroll(direction, x, y) return false end ---- Handles key events --- @shortDescription Handles key events --- @param key number The key that was pressed --- @return boolean handled Whether the event was handled +--- @protected function Container:key(key) if self.get("focusedChild") then return self.get("focusedChild"):dispatchEvent("key", key) @@ -473,10 +474,10 @@ function Container:key(key) return true end ---- Handles char events --- @shortDescription Handles char events --- @param char string The character that was pressed --- @return boolean handled Whether the event was handled +--- @protected function Container:char(char) if self.get("focusedChild") then return self.get("focusedChild"):dispatchEvent("char", char) @@ -484,10 +485,10 @@ function Container:char(char) return true end ---- Handles key up events --- @shortDescription Handles key up events --- @param key number The key that was released --- @return boolean handled Whether the event was handled +--- @protected function Container:key_up(key) if self.get("focusedChild") then return self.get("focusedChild"):dispatchEvent("key_up", key) @@ -495,7 +496,6 @@ function Container:key_up(key) return true end ---- Draws multiple lines of text, fg and bg strings, it is usually used in the render loop --- @shortDescription Draws multiple lines of text, fg and bg strings --- @param x number The x position to draw the text --- @param y number The y position to draw the text @@ -505,6 +505,7 @@ end --- @param fg string The foreground color of the text --- @param bg string The background color of the text --- @return Container self The container instance +--- @protected function Container:multiBlit(x, y, width, height, text, fg, bg) local w, h = self.get("width"), self.get("height") @@ -517,13 +518,13 @@ function Container:multiBlit(x, y, width, height, text, fg, bg) return self end ---- Draws a line of text and fg as color, it is usually used in the render loop --- @shortDescription Draws a line of text and fg as color --- @param x number The x position to draw the text --- @param y number The y position to draw the text --- @param text string The text to draw --- @param fg color The foreground color of the text --- @return Container self The container instance +--- @protected function Container:textFg(x, y, text, fg) local w, h = self.get("width"), self.get("height") @@ -538,13 +539,13 @@ function Container:textFg(x, y, text, fg) return self end ---- Draws a line of text and bg as color, it is usually used in the render loop --- @shortDescription Draws a line of text and bg as color --- @param x number The x position to draw the text --- @param y number The y position to draw the text --- @param text string The text to draw --- @param bg color The background color of the text --- @return Container self The container instance +--- @protected function Container:textBg(x, y, text, bg) local w, h = self.get("width"), self.get("height") @@ -559,7 +560,6 @@ function Container:textBg(x, y, text, bg) return self end ---- Draws a line of text and fg and bg as colors, it is usually used in the render loop --- @shortDescription Draws a line of text and fg and bg as colors --- @param x number The x position to draw the text --- @param y number The y position to draw the text @@ -567,6 +567,7 @@ end --- @param fg string The foreground color of the text --- @param bg string The background color of the text --- @return Container self The container instance +--- @protected function Container:blit(x, y, text, fg, bg) local w, h = self.get("width"), self.get("height") @@ -587,8 +588,8 @@ function Container:blit(x, y, text, fg, bg) return self end ---- Renders the container --- @shortDescription Renders the container +--- @protected function Container:render() VisualElement.render(self) if not self.get("childrenSorted")then @@ -608,9 +609,7 @@ function Container:render() end end ---- Destroys the container and its children ---- @shortDescription Destroys the container and its children ---- @return Container self The container instance +--- @private function Container:destroy() for _, child in ipairs(self._values.children) do child:destroy() diff --git a/src/elements/Dropdown.lua b/src/elements/Dropdown.lua index d966e30..75e9712 100644 --- a/src/elements/Dropdown.lua +++ b/src/elements/Dropdown.lua @@ -22,7 +22,7 @@ Dropdown.defineProperty(Dropdown, "dropSymbol", {default = "\31", type = "string --- Creates a new Dropdown instance --- @shortDescription Creates a new Dropdown instance --- @return Dropdown self The newly created Dropdown instance ---- @usage local dropdown = Dropdown.new() +--- @private function Dropdown.new() local self = setmetatable({}, Dropdown):__init() self.set("width", 16) @@ -31,23 +31,23 @@ function Dropdown.new() return self end ---- Initializes the Dropdown instance --- @shortDescription Initializes the Dropdown instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return Dropdown self The initialized instance +--- @protected function Dropdown:init(props, basalt) List.init(self, props, basalt) self.set("type", "Dropdown") return self end ---- Handles mouse click events --- @shortDescription Handles mouse click events --- @param button number The button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean handled Whether the event was handled +--- @protected function Dropdown:mouse_click(button, x, y) if not VisualElement.mouse_click(self, button, x, y) then return false end @@ -96,8 +96,8 @@ function Dropdown:mouse_click(button, x, y) return false end ---- Renders the Dropdown --- @shortDescription Renders the Dropdown +--- @protected function Dropdown:render() VisualElement.render(self) diff --git a/src/elements/Flexbox.lua b/src/elements/Flexbox.lua index 325f817..a33691c 100644 --- a/src/elements/Flexbox.lua +++ b/src/elements/Flexbox.lua @@ -232,10 +232,9 @@ local function updateLayout(self, direction, spacing, justifyContent, wrap) self.set("flexUpdateLayout", false) end ---- Creates a new Flexbox instance --- @shortDescription Creates a new Flexbox instance --- @return Flexbox object The newly created Flexbox instance ---- @usage local element = Flexbox.new("myId", basalt) +--- @private function Flexbox.new() local self = setmetatable({}, Flexbox):__init() self.set("width", 12) @@ -247,11 +246,11 @@ function Flexbox.new() return self end ---- Initializes the Flexbox instance --- @shortDescription Initializes the Flexbox instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return Flexbox self The initialized instance +--- @protected function Flexbox:init(props, basalt) Container.init(self, props, basalt) self.set("type", "Flexbox") @@ -275,10 +274,10 @@ function Flexbox:addChild(element) return self end ---- Removes a child element from the flexbox --- @shortDescription Removes a child element from the flexbox --- @param element Element The child element to remove --- @return Flexbox self The flexbox instance +--- @protected function Flexbox:removeChild(element) Container.removeChild(self, element) @@ -307,9 +306,9 @@ function Flexbox:addLineBreak() return self end ---- Renders the flexbox and its children --- @shortDescription Renders the flexbox and its children --- @return Flexbox self The flexbox instance +--- @protected function Flexbox:render() if(self.get("flexUpdateLayout"))then updateLayout(self, self.get("flexDirection"), self.get("flexSpacing"), self.get("flexJustifyContent"), self.get("flexWrap")) diff --git a/src/elements/Frame.lua b/src/elements/Frame.lua index adf1c0b..22e09ca 100644 --- a/src/elements/Frame.lua +++ b/src/elements/Frame.lua @@ -10,7 +10,7 @@ Frame.__index = Frame --- Creates a new Frame instance --- @shortDescription Creates a new Frame instance --- @return Frame self The newly created Frame instance ---- @usage local frame = Frame.new() +--- @private function Frame.new() local self = setmetatable({}, Frame):__init() self.set("width", 12) @@ -20,11 +20,11 @@ function Frame.new() return self end ---- Initializes the Frame instance --- @shortDescription Initializes the Frame instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return Frame self The initialized instance +--- @protected function Frame:init(props, basalt) Container.init(self, props, basalt) self.set("type", "Frame") diff --git a/src/elements/Image.lua b/src/elements/Image.lua index 57bca5e..a5864a7 100644 --- a/src/elements/Image.lua +++ b/src/elements/Image.lua @@ -18,11 +18,20 @@ Image.defineProperty(Image, "currentFrame", {default = 1, type = "number", canTr ---@property metadata table {} Image metadata (version, palette, etc) Image.defineProperty(Image, "metadata", {default = {}, type = "table"}) +--- Creates a new Image instance +--- @shortDescription Creates a new Image instance +--- @return Image self The newly created Image instance +--- @private function Image.new() local self = setmetatable({}, Image):__init() return self end +--- @shortDescription Initializes the Image instance +--- @param props table The properties to initialize the element with +--- @param basalt table The basalt instance +--- @return Image self The initialized instance +--- @protected function Image:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "Image") @@ -30,7 +39,9 @@ function Image:init(props, basalt) end --- Loads a bimg format image +--- @shortDescription Loads a bimg format image --- @param bimgData table The bimg image data +--- @return Image self The Image instance function Image:loadBimg(bimgData) if type(bimgData) ~= "table" then return self end @@ -57,6 +68,7 @@ function Image:loadBimg(bimgData) end --- Gets pixel information at position +--- @shortDescription Gets pixel information at position --- @param x number X position --- @param y number Y position --- @return number? fg Foreground color @@ -80,6 +92,7 @@ function Image:getPixelData(x, y) end --- Sets character at position +--- @shortDescription Sets character at position --- @param x number X position --- @param y number Y position --- @param char string Single character to set @@ -107,6 +120,7 @@ function Image:setChar(x, y, char) end --- Sets foreground color at position +--- @shortDescription Sets foreground color at position --- @param x number X position --- @param y number Y position --- @param color number Color value (0-15) @@ -134,6 +148,7 @@ function Image:setFg(x, y, color) end --- Sets background color at position +--- @shortDescription Sets background color at position --- @param x number X position --- @param y number Y position --- @param color number Color value (0-15) @@ -161,6 +176,7 @@ function Image:setBg(x, y, color) end --- Sets all properties at position +--- @shortDescription Sets all properties at position --- @param x number X position --- @param y number Y position --- @param char string? Character to set (optional) @@ -173,6 +189,9 @@ function Image:setPixel(x, y, char, fg, bg) return self end +--- Advances to the next frame in the animation +--- @shortDescription Advances to the next frame in the animation +--- @return Image self The Image instance function Image:nextFrame() if not self.get("metadata").animation then return end @@ -185,6 +204,8 @@ function Image:nextFrame() return self end +--- @shortDescription Renders the Image +--- @protected function Image:render() VisualElement.render(self) diff --git a/src/elements/Input.lua b/src/elements/Input.lua index b2ea1c4..85a3857 100644 --- a/src/elements/Input.lua +++ b/src/elements/Input.lua @@ -31,10 +31,9 @@ Input.defineEvent(Input, "mouse_click") Input.defineEvent(Input, "key") Input.defineEvent(Input, "char") ---- Creates a new Input instance --- @shortDescription Creates a new Input instance --- @return Input object The newly created Input instance ---- @usage local element = Input.new("myId", basalt) +--- @private function Input.new() local self = setmetatable({}, Input):__init() self.set("width", 8) @@ -42,21 +41,21 @@ function Input.new() return self end ---- Initializes the Input instance --- @shortDescription Initializes the Input instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return Input self The initialized instance +--- @protected function Input:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "Input") return self end ---- Handles char events --- @shortDescription Handles char events --- @param char string The character that was typed --- @return boolean handled Whether the event was handled +--- @protected function Input:char(char) if not self.get("focused") then return false end local text = self.get("text") @@ -74,10 +73,10 @@ function Input:char(char) return true end ---- Handles key events --- @shortDescription Handles key events --- @param key number The key that was pressed --- @return boolean handled Whether the event was handled +--- @protected function Input:key(key) if not self.get("focused") then return false end local pos = self.get("cursorPos") @@ -113,26 +112,26 @@ function Input:key(key) return true end ---- Handles focus events --- @shortDescription Handles focus events +--- @protected function Input:focus() VisualElement.focus(self) self:updateRender() end ---- Handles blur events --- @shortDescription Handles blur events +--- @protected function Input:blur() VisualElement.blur(self) self:updateRender() end ---- Handles mouse click events --- @shortDescription Handles mouse click events --- @param button number The button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean handled Whether the event was handled +--- @protected function Input:mouse_click(button, x, y) if VisualElement.mouse_click(self, button, x, y) then local relX, relY = self:getRelativePosition(x, y) @@ -145,6 +144,7 @@ end --- Updates the input's viewport --- @shortDescription Updates the input's viewport +--- @return Input self The updated instance function Input:updateViewport() local width = self.get("width") local cursorPos = self.get("cursorPos") @@ -161,10 +161,11 @@ function Input:updateViewport() if viewOffset > textLength - width then self.set("viewOffset", math.max(0, textLength - width)) end + return self end ---- Renders the input element --- @shortDescription Renders the input element +--- @protected function Input:render() local text = self.get("text") local viewOffset = self.get("viewOffset") diff --git a/src/elements/Label.lua b/src/elements/Label.lua index 1ee58bf..b9227d3 100644 --- a/src/elements/Label.lua +++ b/src/elements/Label.lua @@ -33,7 +33,7 @@ end}) --- Creates a new Label instance --- @shortDescription Creates a new Label instance --- @return Label self The newly created Label instance ---- @usage local label = Label.new() +--- @private function Label.new() local self = setmetatable({}, Label):__init() self.set("z", 3) @@ -47,6 +47,7 @@ end --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return Label self The initialized instance +--- @protected function Label:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "Label") @@ -62,8 +63,8 @@ function Label:getWrappedText() return wrappedText end ---- Renders the Label --- @shortDescription Renders the Label by drawing its text content +--- @protected function Label:render() VisualElement.render(self) local text = self.get("text") diff --git a/src/elements/List.lua b/src/elements/List.lua index b927caa..0dca9ec 100644 --- a/src/elements/List.lua +++ b/src/elements/List.lua @@ -27,7 +27,7 @@ List.defineEvent(List, "mouse_scroll") --- Creates a new List instance --- @shortDescription Creates a new List instance --- @return List self The newly created List instance ---- @usage local list = List.new() +--- @private function List.new() local self = setmetatable({}, List):__init() self.set("width", 16) @@ -37,11 +37,11 @@ function List.new() return self end ---- Initializes the List instance --- @shortDescription Initializes the List instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return List self The initialized instance +--- @protected function List:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "List") @@ -99,12 +99,12 @@ function List:getSelectedItems() return selected end ---- Handles mouse click events --- @shortDescription Handles mouse click events --- @param button number The mouse button that was clicked --- @param x number The x-coordinate of the click --- @param y number The y-coordinate of the click --- @return boolean Whether the event was handled +--- @protected function List:mouse_click(button, x, y) if button == 1 and self:isInBounds(x, y) and self.get("selectable") then local _, index = self:getRelativePosition(x, y) @@ -140,12 +140,12 @@ function List:mouse_click(button, x, y) return false end ---- Handles mouse scroll events --- @shortDescription Handles mouse scroll events --- @param direction number The direction of the scroll (1 for down, -1 for up) --- @param x number The x-coordinate of the scroll --- @param y number The y-coordinate of the scroll --- @return boolean Whether the event was handled +--- @protected function List:mouse_scroll(direction, x, y) if self:isInBounds(x, y) then local offset = self.get("offset") @@ -185,8 +185,8 @@ function List:scrollToTop() return self end ---- Renders the list --- @shortDescription Renders the list +--- @protected function List:render() VisualElement.render(self) diff --git a/src/elements/Menu.lua b/src/elements/Menu.lua index f770199..bca6d47 100644 --- a/src/elements/Menu.lua +++ b/src/elements/Menu.lua @@ -15,7 +15,7 @@ Menu.defineProperty(Menu, "separatorColor", {default = colors.gray, type = "numb --- Creates a new Menu instance --- @shortDescription Creates a new Menu instance --- @return Menu self The newly created Menu instance ---- @usage local menu = Menu.new() +--- @private function Menu.new() local self = setmetatable({}, Menu):__init() self.set("width", 30) @@ -24,11 +24,11 @@ function Menu.new() return self end ---- Initializes the Menu instance --- @shortDescription Initializes the Menu instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return Menu self The initialized instance +--- @protected function Menu:init(props, basalt) List.init(self, props, basalt) self.set("type", "Menu") @@ -58,8 +58,8 @@ function Menu:setItems(items) return List.setItems(self, listItems) end ---- Renders the menu --- @shortDescription Renders the menu horizontally with proper spacing and colors +--- @protected function Menu:render() VisualElement.render(self) local currentX = 1 @@ -87,12 +87,12 @@ function Menu:render() end end ---- Handles mouse click events --- @shortDescription Handles mouse click events and item selection --- @param button number The button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean Whether the event was handled +--- @protected function Menu:mouse_click(button, x, y) if not VisualElement.mouse_click(self, button, x, y) then return false end if(self.get("selectable") == false) then return false end diff --git a/src/elements/Program.lua b/src/elements/Program.lua index 2fa9624..0b89985 100644 --- a/src/elements/Program.lua +++ b/src/elements/Program.lua @@ -113,10 +113,9 @@ function BasaltProgram:stop() end ---- Creates a new Program instance --- @shortDescription Creates a new Program instance --- @return Program object The newly created Program instance ---- @usage local element = Program.new("myId", basalt) +--- @private function Program.new() local self = setmetatable({}, Program):__init() self.set("z", 5) @@ -125,11 +124,11 @@ function Program.new() return self end ---- Initializes the Program instanceProperty --- @shortDescription Initializes the Program instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return Program self The initialized instance +--- @protected function Program:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "Program") @@ -150,11 +149,11 @@ function Program:execute(path) return self end ---- Handles all incomming events --- @shortDescription Handles all incomming events --- @param event string The event to handle --- @param ... any The event arguments --- @return any result The event result +--- @protected function Program:dispatchEvent(event, ...) local program = self.get("program") local result = VisualElement.dispatchEvent(self, event, ...) @@ -170,8 +169,8 @@ function Program:dispatchEvent(event, ...) return result end ---- Gets called when the element gets focused --- @shortDescription Gets called when the element gets focused +--- @protected function Program:focus() if(VisualElement.focus(self))then local program = self.get("program") @@ -183,8 +182,8 @@ function Program:focus() end end ---- Renders the program --- @shortDescription Renders the program +--- @protected function Program:render() VisualElement.render(self) local program = self.get("program") diff --git a/src/elements/ProgressBar.lua b/src/elements/ProgressBar.lua index f1f11a4..5fae3b6 100644 --- a/src/elements/ProgressBar.lua +++ b/src/elements/ProgressBar.lua @@ -16,7 +16,7 @@ ProgressBar.defineProperty(ProgressBar, "progressColor", {default = colors.black --- Creates a new ProgressBar instance --- @shortDescription Creates a new ProgressBar instance --- @return ProgressBar self The newly created ProgressBar instance ---- @usage local progressBar = ProgressBar.new() +--- @private function ProgressBar.new() local self = setmetatable({}, ProgressBar):__init() self.set("width", 10) @@ -24,18 +24,18 @@ function ProgressBar.new() return self end ---- Initializes the ProgressBar instance --- @shortDescription Initializes the ProgressBar instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return ProgressBar self The initialized instance +--- @protected function ProgressBar:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "ProgressBar") end ---- Renders the ProgressBar --- @shortDescription Renders the progress bar with filled portion and optional percentage text +--- @protected function ProgressBar:render() VisualElement.render(self) local width = self.get("width") diff --git a/src/elements/Scrollbar.lua b/src/elements/Scrollbar.lua index c386765..33c9083 100644 --- a/src/elements/Scrollbar.lua +++ b/src/elements/Scrollbar.lua @@ -46,7 +46,7 @@ Scrollbar.defineEvent(Scrollbar, "mouse_scroll") --- Creates a new Scrollbar instance --- @shortDescription Creates a new Scrollbar instance --- @return Scrollbar self The newly created Scrollbar instance ---- @usage local scrollbar = Scrollbar.new() +--- @private function Scrollbar.new() local self = setmetatable({}, Scrollbar):__init() self.set("width", 1) @@ -54,11 +54,11 @@ function Scrollbar.new() return self end ---- Initializes the Scrollbar instance --- @shortDescription Initializes the Scrollbar instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return Scrollbar self The initialized instance +--- @protected function Scrollbar:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "Scrollbar") @@ -106,12 +106,12 @@ local function getRelativeScrollPosition(self, x, y) return self.get("orientation") == "vertical" and relY or relX end ---- Handles mouse click events --- @shortDescription Handles mouse click events --- @param button number The mouse button clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean Whether the event was handled +--- @protected function Scrollbar:mouse_click(button, x, y) if VisualElement.mouse_click(self, button, x, y) then local size = getScrollbarSize(self) @@ -132,12 +132,12 @@ function Scrollbar:mouse_click(button, x, y) end end ---- Handles mouse drag events --- @shortDescription Handles mouse drag events --- @param button number The mouse button being dragged --- @param x number The x position of the drag --- @param y number The y position of the drag --- @return boolean Whether the event was handled +--- @protected function Scrollbar:mouse_drag(button, x, y) if(VisualElement.mouse_drag(self, button, x, y))then local size = getScrollbarSize(self) @@ -156,12 +156,12 @@ function Scrollbar:mouse_drag(button, x, y) end end ---- Handles mouse scroll events --- @shortDescription Handles mouse scroll events --- @param direction number The scroll direction (1 for up, -1 for down) --- @param x number The x position of the scroll --- @param y number The y position of the scroll --- @return boolean Whether the event was handled +--- @protected function Scrollbar:mouse_scroll(direction, x, y) if not self:isInBounds(x, y) then return false end direction = direction > 0 and -1 or 1 @@ -174,8 +174,8 @@ function Scrollbar:mouse_scroll(direction, x, y) return true end ---- Renders the Scrollbar --- @shortDescription Renders the scrollbar +--- @protected function Scrollbar:render() VisualElement.render(self) diff --git a/src/elements/Slider.lua b/src/elements/Slider.lua index 4a539d2..9983017 100644 --- a/src/elements/Slider.lua +++ b/src/elements/Slider.lua @@ -25,7 +25,7 @@ Slider.defineEvent(Slider, "mouse_up") --- Creates a new Slider instance --- @shortDescription Creates a new Slider instance --- @return Slider self The newly created Slider instance ---- @usage local slider = Slider.new() +--- @private function Slider.new() local self = setmetatable({}, Slider):__init() self.set("width", 8) @@ -34,11 +34,11 @@ function Slider.new() return self end ---- Initializes the Slider instance --- @shortDescription Initializes the Slider instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return Slider self The initialized instance +--- @protected function Slider:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "Slider") @@ -55,12 +55,12 @@ function Slider:getValue() return math.floor((step - 1) * (max / (maxSteps - 1))) end ---- Handles mouse click events --- @shortDescription Updates slider position on mouse click --- @param button number The mouse button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean handled Whether the event was handled +--- @protected function Slider:mouse_click(button, x, y) if button == 1 and self:isInBounds(x, y) then local relX, relY = self:getRelativePosition(x, y) @@ -74,12 +74,12 @@ function Slider:mouse_click(button, x, y) end Slider.mouse_drag = Slider.mouse_click ---- Handles mouse release events --- @shortDescription Handles mouse release events --- @param button number The mouse button that was released --- @param x number The x position of the release --- @param y number The y position of the release --- @return boolean handled Whether the event was handled +--- @protected function Slider:mouse_scroll(direction, x, y) if self:isInBounds(x, y) then local step = self.get("step") @@ -90,8 +90,8 @@ function Slider:mouse_scroll(direction, x, y) end end ---- Renders the slider --- @shortDescription Renders the slider with track and handle +--- @protected function Slider:render() VisualElement.render(self) local width = self.get("width") diff --git a/src/elements/Table.lua b/src/elements/Table.lua index 48fa629..cef7582 100644 --- a/src/elements/Table.lua +++ b/src/elements/Table.lua @@ -32,7 +32,7 @@ Table.defineEvent(Table, "mouse_scroll") --- Creates a new Table instance --- @shortDescription Creates a new Table instance --- @return Table self The newly created Table instance ---- @usage local table = Table.new() +--- @private function Table.new() local self = setmetatable({}, Table):__init() self.set("width", 30) @@ -41,11 +41,11 @@ function Table.new() return self end ---- Initializes the Table instance --- @shortDescription Initializes the Table instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return Table self The initialized instance +--- @protected function Table:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "Table") @@ -72,12 +72,12 @@ function Table:sortData(columnIndex) return self end ---- Handles mouse click events --- @shortDescription Handles header clicks for sorting and row selection --- @param button number The button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean handled Whether the event was handled +--- @protected function Table:mouse_click(button, x, y) if not VisualElement.mouse_click(self, button, x, y) then return false end @@ -110,12 +110,12 @@ function Table:mouse_click(button, x, y) return true end ---- Handles mouse scroll events --- @shortDescription Handles scrolling through the table data --- @param direction number The scroll direction (-1 up, 1 down) --- @param x number The x position of the scroll --- @param y number The y position of the scroll --- @return boolean handled Whether the event was handled +--- @protected function Table:mouse_scroll(direction, x, y) local data = self.get("data") local height = self.get("height") @@ -127,8 +127,8 @@ function Table:mouse_scroll(direction, x, y) return true end ---- Renders the table --- @shortDescription Renders the table with headers, data and scrollbar +--- @protected function Table:render() VisualElement.render(self) diff --git a/src/elements/TextBox.lua b/src/elements/TextBox.lua index e7dcf2e..a0065b7 100644 --- a/src/elements/TextBox.lua +++ b/src/elements/TextBox.lua @@ -33,6 +33,7 @@ TextBox.defineEvent(TextBox, "mouse_scroll") --- Creates a new TextBox instance --- @shortDescription Creates a new TextBox instance --- @return TextBox self The newly created TextBox instance +--- @private function TextBox.new() local self = setmetatable({}, TextBox):__init() self.set("width", 20) @@ -40,11 +41,11 @@ function TextBox.new() return self end ---- Initializes the TextBox instance --- @shortDescription Initializes the TextBox instance --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return TextBox self The initialized instance +--- @protected function TextBox:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "TextBox") @@ -55,6 +56,7 @@ end --- @shortDescription Adds a new syntax highlighting pattern --- @param pattern string The regex pattern to match --- @param color colors The color to apply +--- @return TextBox self The TextBox instance function TextBox:addSyntaxPattern(pattern, color) table.insert(self.get("syntaxPatterns"), {pattern = pattern, color = color}) return self @@ -134,20 +136,20 @@ function TextBox:updateViewport() return self end ---- Handles character input --- @shortDescription Handles character input --- @param char string The character that was typed --- @return boolean handled Whether the event was handled +--- @protected function TextBox:char(char) if not self.get("editable") or not self.get("focused") then return false end insertChar(self, char) return true end ---- Handles key events --- @shortDescription Handles key events --- @param key number The key that was pressed --- @return boolean handled Whether the event was handled +--- @protected function TextBox:key(key) if not self.get("editable") or not self.get("focused") then return false end local lines = self.get("lines") @@ -184,12 +186,12 @@ function TextBox:key(key) return true end ---- Handles mouse scroll events --- @shortDescription Handles mouse scroll events --- @param direction number The scroll direction --- @param x number The x position of the scroll --- @param y number The y position of the scroll --- @return boolean handled Whether the event was handled +--- @protected function TextBox:mouse_scroll(direction, x, y) if self:isInBounds(x, y) then local scrollY = self.get("scrollY") @@ -207,12 +209,12 @@ function TextBox:mouse_scroll(direction, x, y) return false end ---- Handles mouse click events --- @shortDescription Handles mouse click events --- @param button number The button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean handled Whether the event was handled +--- @protected function TextBox:mouse_click(button, x, y) if VisualElement.mouse_click(self, button, x, y) then local relX, relY = self:getRelativePosition(x, y) @@ -274,8 +276,8 @@ local function applySyntaxHighlighting(self, line) return text, colors end ---- Renders the TextBox --- @shortDescription Renders the TextBox with syntax highlighting +--- @protected function TextBox:render() VisualElement.render(self) diff --git a/src/elements/Tree.lua b/src/elements/Tree.lua index 851e68c..ca32173 100644 --- a/src/elements/Tree.lua +++ b/src/elements/Tree.lua @@ -34,7 +34,7 @@ Tree.defineEvent(Tree, "mouse_scroll") --- Creates a new Tree instance --- @shortDescription Creates a new Tree instance --- @return Tree self The newly created Tree instance ---- @usage local tree = Tree.new() +--- @private function Tree.new() local self = setmetatable({}, Tree):__init() self.set("width", 30) @@ -48,6 +48,7 @@ end --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return Tree self The initialized instance +--- @protected function Tree:init(props, basalt) VisualElement.init(self, props, basalt) self.set("type", "Tree") @@ -106,6 +107,7 @@ end --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean handled Whether the event was handled +--- @protected function Tree:mouse_click(button, x, y) if VisualElement.mouse_click(self, button, x, y) then local relX, relY = self:getRelativePosition(x, y) @@ -136,12 +138,12 @@ function Tree:onSelect(callback) return self end ---- Handles mouse scroll events --- @shortDescription Handles mouse scroll events for vertical scrolling --- @param direction number The scroll direction (1 for up, -1 for down) --- @param x number The x position of the scroll --- @param y number The y position of the scroll --- @return boolean handled Whether the event was handled +--- @protected function Tree:mouse_scroll(direction, x, y) if VisualElement.mouse_scroll(self, direction, x, y) then local flatNodes = flattenTree(self.get("nodes"), self.get("expandedNodes")) @@ -167,8 +169,8 @@ function Tree:getNodeSize() return width, height end ---- Renders the tree --- @shortDescription Renders the tree with nodes, selection and scrolling +--- @protected function Tree:render() VisualElement.render(self) diff --git a/src/elements/VisualElement.lua b/src/elements/VisualElement.lua index a5c8dcc..abd61aa 100644 --- a/src/elements/VisualElement.lua +++ b/src/elements/VisualElement.lua @@ -110,22 +110,21 @@ local max, min = math.max, math.min --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return VisualElement object The newly created VisualElement instance ---- @usage local element = VisualElement.new("myId", basalt) +--- @private function VisualElement.new() local self = setmetatable({}, VisualElement):__init() return self end ---- Initializes the VisualElement instance --- @shortDescription Initializes a new visual element with properties --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance +--- @protected function VisualElement:init(props, basalt) BaseElement.init(self, props, basalt) self.set("type", "VisualElement") end ---- Draws multiple characters at once with colors --- @shortDescription Multi-character drawing with colors --- @param x number The x position to draw --- @param y number The y position to draw @@ -134,6 +133,7 @@ end --- @param text string The text to draw --- @param fg string The foreground color --- @param bg string The background color +--- @protected function VisualElement:multiBlit(x, y, width, height, text, fg, bg) local xElement, yElement = self:calculatePosition() x = x + xElement - 1 @@ -141,12 +141,12 @@ function VisualElement:multiBlit(x, y, width, height, text, fg, bg) self.parent:multiBlit(x, y, width, height, text, fg, bg) end ---- Draws text with foreground color --- @shortDescription Draws text with foreground color --- @param x number The x position to draw --- @param y number The y position to draw --- @param text string The text char to draw --- @param fg color The foreground color +--- @protected function VisualElement:textFg(x, y, text, fg) local xElement, yElement = self:calculatePosition() x = x + xElement - 1 @@ -154,12 +154,12 @@ function VisualElement:textFg(x, y, text, fg) self.parent:textFg(x, y, text, fg) end ---- Draws text with background color --- @shortDescription Draws text with background color --- @param x number The x position to draw --- @param y number The y position to draw --- @param text string The text char to draw --- @param bg color The background color +--- @protected function VisualElement:textBg(x, y, text, bg) local xElement, yElement = self:calculatePosition() x = x + xElement - 1 @@ -167,13 +167,13 @@ function VisualElement:textBg(x, y, text, bg) self.parent:textBg(x, y, text, bg) end ---- Draws text with both foreground and background colors --- @shortDescription Draws text with both colors --- @param x number The x position to draw --- @param y number The y position to draw --- @param text string The text char to draw --- @param fg string The foreground color --- @param bg string The background color +--- @protected function VisualElement:blit(x, y, text, fg, bg) local xElement, yElement = self:calculatePosition() x = x + xElement - 1 @@ -200,12 +200,12 @@ function VisualElement:isInBounds(x, y) y >= yPos and y <= yPos + height - 1 end ---- Handles a mouse click event --- @shortDescription Handles a mouse click event --- @param button number The button that was clicked --- @param x number The x position of the click --- @param y number The y position of the click --- @return boolean clicked Whether the element was clicked +--- @protected function VisualElement:mouse_click(button, x, y) if self:isInBounds(x, y) then self.set("clicked", true) @@ -215,12 +215,12 @@ function VisualElement:mouse_click(button, x, y) return false end ---- Handles a mouse up event --- @shortDescription Handles a mouse up event --- @param button number The button that was released --- @param x number The x position of the release --- @param y number The y position of the release --- @return boolean release Whether the element was released on the element +--- @protected function VisualElement:mouse_up(button, x, y) if self:isInBounds(x, y) then self.set("clicked", false) @@ -230,16 +230,22 @@ function VisualElement:mouse_up(button, x, y) return false end ---- Handles a mouse release event --- @shortDescription Handles a mouse release event --- @param button number The button that was released --- @param x number The x position of the release --- @param y number The y position of the release +--- @protected function VisualElement:mouse_release(button, x, y) self:fireEvent("mouse_release", button, self:getRelativePosition(x, y)) self.set("clicked", false) end +---@shortDescription Handles a mouse move event +---@param _ number unknown +---@param x number The x position of the mouse +---@param y number The y position of the mouse +---@return boolean hover Whether the mouse has moved over the element +--- @protected function VisualElement:mouse_move(_, x, y) if(x==nil)or(y==nil)then return @@ -260,6 +266,12 @@ function VisualElement:mouse_move(_, x, y) return false end +--- @shortDescription Handles a mouse scroll event +--- @param direction number The scroll direction +--- @param x number The x position of the scroll +--- @param y number The y position of the scroll +--- @return boolean scroll Whether the element was scrolled +--- @protected function VisualElement:mouse_scroll(direction, x, y) if(self:isInBounds(x, y))then self:fireEvent("mouse_scroll", direction, self:getRelativePosition(x, y)) @@ -268,6 +280,12 @@ function VisualElement:mouse_scroll(direction, x, y) return false end +--- @shortDescription Handles a mouse drag event +--- @param button number The button that was clicked while dragging +--- @param x number The x position of the drag +--- @param y number The y position of the drag +--- @return boolean drag Whether the element was dragged +--- @protected function VisualElement:mouse_drag(button, x, y) if(self.get("clicked"))then self:fireEvent("mouse_drag", button, self:getRelativePosition(x, y)) @@ -276,19 +294,23 @@ function VisualElement:mouse_drag(button, x, y) return false end ---- Handles a focus event --- @shortDescription Handles a focus event +--- @protected function VisualElement:focus() self:fireEvent("focus") end ---- Handles a blur event --- @shortDescription Handles a blur event +--- @protected function VisualElement:blur() self:fireEvent("blur") self:setCursor(1,1, false) end +--- Calculates the position of the element relative to its parent +--- @shortDescription Calculates the position of the element +--- @return number x The x position +--- @return number y The y position function VisualElement:calculatePosition() local x, y = self.get("x"), self.get("y") if not self.get("ignoreOffset") then @@ -305,6 +327,8 @@ end --- @shortDescription Returns the absolute position of the element ---@param x? number x position ---@param y? number y position +---@return number x The absolute x position +---@return number y The absolute y position function VisualElement:getAbsolutePosition(x, y) local xPos, yPos = self.get("x"), self.get("y") if(x ~= nil) then @@ -329,7 +353,8 @@ end --- @shortDescription Returns the relative position of the element ---@param x? number x position ---@param y? number y position ----@return number, number +---@return number x The relative x position +---@return number y The relative y position function VisualElement:getRelativePosition(x, y) if (x == nil) or (y == nil) then x, y = self.get("x"), self.get("y") @@ -345,21 +370,24 @@ function VisualElement:getRelativePosition(x, y) y - (elementY - 1) - (parentY - 1) end ---- Sets the cursor position --- @shortDescription Sets the cursor position --- @param x number The x position of the cursor --- @param y number The y position of the cursor --- @param blink boolean Whether the cursor should blink +--- @param color number The color of the cursor +--- @return VisualElement self The VisualElement instance +--- @protected function VisualElement:setCursor(x, y, blink, color) if self.parent then local absX, absY = self:getAbsolutePosition(x, y) absX = max(self.get("x"), min(absX, self.get("width") + self.get("x") - 1)) return self.parent:setCursor(absX, absY, blink, color) end + return self end ---- Renders the element --- @shortDescription Renders the element +--- @protected function VisualElement:render() if(not self.get("backgroundEnabled"))then return