From 59b4b4f88b9bbe74d35030b1fc1a112acc15a928 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Mon, 17 Mar 2025 19:09:15 +0100 Subject: [PATCH] Some docs stuff --- src/elements/BarChart.lua | 2 +- src/elements/BaseElement.lua | 25 +++++++++++++++---------- src/elements/BaseFrame.lua | 3 +-- tools/markdown.lua | 3 +++ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/elements/BarChart.lua b/src/elements/BarChart.lua index d9eddee..493923d 100644 --- a/src/elements/BarChart.lua +++ b/src/elements/BarChart.lua @@ -2,7 +2,7 @@ local elementManager = require("elementManager") local VisualElement = elementManager.getElement("VisualElement") local BaseGraph = elementManager.getElement("Graph") local tHex = require("libraries/colorHex") ---- @configDescription A bar chart element based on the graph element +--- @configDescription A bar chart element based on the graph element. ---@configDefault false --- This is the bar chart class. It is based on the graph element. It draws bar based points. diff --git a/src/elements/BaseElement.lua b/src/elements/BaseElement.lua index 31683a3..6cc4270 100644 --- a/src/elements/BaseElement.lua +++ b/src/elements/BaseElement.lua @@ -32,6 +32,10 @@ BaseElement.defineProperty(BaseElement, "name", {default = "", type = "string"}) BaseElement.defineProperty(BaseElement, "eventCallbacks", {default = {}, type = "table"}) --- Registers a new event listener for the element (on class level) +--- @shortDescription Registers a new event listener for the element (on class level) +--- @param class table The class to register +--- @param eventName string The name of the event to register +--- @param requiredEvent? string The name of the required event (optional) function BaseElement.defineEvent(class, eventName, requiredEvent) if not rawget(class, '_eventConfigs') then class._eventConfigs = {} @@ -43,6 +47,10 @@ function BaseElement.defineEvent(class, eventName, requiredEvent) end --- Registers a new event callback for the element (on class level) +--- @shortDescription Registers a new event callback for the element (on class level) +--- @param class table The class to register +--- @param callbackName string The name of the callback to register +--- @param ... string The names of the events to register the callback for function BaseElement.registerEventCallback(class, callbackName, ...) local methodName = callbackName:match("^on") and callbackName or "on"..callbackName local events = {...} @@ -61,7 +69,7 @@ end --- @shortDescription Creates a new BaseElement instance --- @return table The newly created BaseElement instance ----@private +--- @private function BaseElement.new() local self = setmetatable({}, BaseElement):__init() return self @@ -71,7 +79,7 @@ end --- @param props table The properties to initialize the element with --- @param basalt table The basalt instance --- @return table self The initialized instance ----@protected +--- @protected function BaseElement:init(props, basalt) self._props = props self._values.id = uuid() @@ -112,7 +120,7 @@ end --- @shortDescription Post initialization --- @return table self The BaseElement instance ----@protected +--- @protected function BaseElement:postInit() if(self._props)then for k,v in pairs(self._props)do @@ -126,7 +134,7 @@ end --- Checks if the element is a specific type --- @shortDescription Checks if the element is a specific type --- @param type string The type to check for ---- @return boolean Whether the element is of the specified type +--- @return boolean isType Whether the element is of the specified type function BaseElement:isType(type) for _, t in ipairs(self._values.type) do if t == type then @@ -141,7 +149,6 @@ end --- @param eventName string The name of the event to listen for --- @param enable? boolean Whether to enable or disable the event (default: true) --- @return table self The BaseElement instance ---- @usage element:listenEvent("mouse_click", true) function BaseElement:listenEvent(eventName, enable) enable = enable ~= false if enable ~= (self._registeredEvents[eventName] or false) then @@ -165,7 +172,6 @@ end --- @param event string The event to register the callback for --- @param callback function The callback function to register --- @return table self The BaseElement instance ---- @usage element:registerCallback("mouse_click", function(self, ...) end) function BaseElement:registerCallback(event, callback) if not self._registeredEvents[event] then self:listenEvent(event, true) @@ -184,7 +190,6 @@ end --- @param event string The event to fire --- @param ... any Additional arguments to pass to the callbacks --- @return table self The BaseElement instance ---- @usage element:fireEvent("mouse_click", 1, 2) function BaseElement:fireEvent(event, ...) if self.get("eventCallbacks")[event] then for _, callback in ipairs(self.get("eventCallbacks")[event]) do @@ -228,7 +233,7 @@ end --- Returns the base frame of the element --- @shortDescription Returns the base frame of the element ---- @return table BaseFrame The base frame of the element +--- @return BaseFrame BaseFrame The base frame of the element function BaseElement:getBaseFrame() if self.parent then return self.parent:getBaseFrame() @@ -238,7 +243,6 @@ end --- Destroys the element and cleans up all references --- @shortDescription Destroys the element and cleans up all references ---- @usage element:destroy() function BaseElement:destroy() if self.parent then self.parent:removeChild(self) @@ -260,13 +264,14 @@ end --- Requests a render update for this element --- @shortDescription Requests a render update for this element ---- @usage element:updateRender() +--- @return table self The BaseElement instance function BaseElement:updateRender() if(self.parent) then self.parent:updateRender() else self._renderUpdate = true end + return self end return BaseElement \ No newline at end of file diff --git a/src/elements/BaseFrame.lua b/src/elements/BaseFrame.lua index 7c6fd30..492fa94 100644 --- a/src/elements/BaseFrame.lua +++ b/src/elements/BaseFrame.lua @@ -31,8 +31,6 @@ end}) --- @private function BaseFrame.new() local self = setmetatable({}, BaseFrame):__init() - self.set("term", term.current()) - self.set("background", colors.lightGray) return self end @@ -43,6 +41,7 @@ end --- @protected function BaseFrame:init(props, basalt) Container.init(self, props, basalt) + self.set("term", term.current()) self.set("type", "BaseFrame") return self end diff --git a/tools/markdown.lua b/tools/markdown.lua index 594d539..1488b5b 100644 --- a/tools/markdown.lua +++ b/tools/markdown.lua @@ -326,6 +326,9 @@ local function markdownClassFunctionList(className) end end end + if(#fList<=0)then + return "" + end local output = "\n## Functions\n\n|Method|Returns|Description|\n|---|---|---|\n" for _, block in pairs(fList) do