diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 184129d..a349f2d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -32,29 +32,24 @@ jobs: build-essential \ libreadline-dev - # Konfiguriere LuaRocks für Lua 5.3 sudo luarocks --lua-version=5.3 install ldoc - # Verifiziere Installation ldoc --version || exit 1 - name: Generate Documentation run: | - # Erstelle config.ld wenn nicht vorhanden if [ ! -f "config.ld" ]; then echo 'project="Basalt2"; title="Basalt2 Documentation"; description="A powerful UI Framework for ComputerCraft"; dir="docs"; style="!pale"; format="markdown"; file="src"; all=true; template=true' > config.ld fi - echo "LDoc Konfiguration:" + echo "LDoc Configuration:" cat config.ld - echo "Verfügbare Lua-Dateien:" + echo "Available Lua-Files:" find src -name "*.lua" -type f - # Generiere Dokumentation ldoc . --verbose - # Prüfe ob Docs generiert wurden if [ ! -d "docs" ]; then echo "Documentation generation failed" exit 1 diff --git a/src/main.lua b/src/main.lua index 6574f2c..7cf5e6f 100644 --- a/src/main.lua +++ b/src/main.lua @@ -1,7 +1,15 @@ +--- Basalt UI Framework main module +-- @module basalt +-- @author NyoriE +-- @license MIT +-- @copyright 2025 + local elementManager = require("elementManager") local expect = require("libraries/expect") local errorManager = require("errorManager") +--- The main Basalt instance +-- @type Basalt local basalt = {} basalt.traceback = true basalt._events = {} @@ -12,6 +20,12 @@ basalt.LOGGER = require("log") local mainFrame = nil local updaterActive = false +--- Creates a new UI element +-- @function create +-- @param type string The type of element to create (e.g. "BaseFrame") +-- @param[opt] id string Optional ID for the element +-- @return table The created element instance +-- @usage local button = basalt.create("Button", "myButton") function basalt.create(type, id) if(id==nil)then id = elementManager.generateId() end local element = elementManager.getElement(type).new(id, basalt) @@ -22,16 +36,28 @@ function basalt.create(type, id) return element end +--- Creates and returns a new frame +-- @function createFrame +-- @return table The created frame instance +-- @usage local mainFrame = basalt.createFrame() function basalt.createFrame() local frame = basalt.create("BaseFrame") mainFrame = frame return frame end +--- Returns the element manager instance +-- @function getElementManager +-- @return table The element manager +-- @usage local manager = basalt.getElementManager() function basalt.getElementManager() return elementManager end +--- Gets or creates the main frame +-- @function getMainFrame +-- @return table The main frame instance +-- @usage local frame = basalt.getMainFrame() function basalt.getMainFrame() if(mainFrame == nil)then mainFrame = basalt.createFrame() @@ -39,20 +65,36 @@ function basalt.getMainFrame() return mainFrame end +--- Sets the active frame +-- @function setActiveFrame +-- @param frame table The frame to set as active +-- @return boolean Always returns false +-- @usage basalt.setActiveFrame(myFrame) function basalt.setActiveFrame(frame) mainFrame = frame return false end +--- Schedules a function to be updated +-- @function scheduleUpdate +-- @param func function The function to schedule +-- @return number The schedule ID +-- @usage local id = basalt.scheduleUpdate(myFunction) function basalt.scheduleUpdate(func) table.insert(basalt._schedule, func) return #basalt._schedule end +--- Removes a scheduled update +-- @function removeSchedule +-- @param id number The schedule ID to remove +-- @usage basalt.removeSchedule(scheduleId) function basalt.removeSchedule(id) basalt._schedule[id] = nil end +-- Internal event handler +-- @local local function updateEvent(event, ...) if(event=="terminate")then basalt.stop() end @@ -75,12 +117,17 @@ local function updateEvent(event, ...) end end +-- Internal render function +-- @local local function renderFrames() if(mainFrame)then mainFrame:render() end end +--- Updates all scheduled functions +-- @function update +-- @usage basalt.update() function basalt.update() for k,v in pairs(basalt._schedule) do if type(v)=="function" then @@ -89,12 +136,20 @@ function basalt.update() end end +--- Stops the Basalt runtime +-- @function stop +-- @usage basalt.stop() function basalt.stop() term.clear() term.setCursorPos(1,1) updaterActive = false end +--- Starts the Basalt runtime +-- @function run +-- @param[opt] isActive boolean Whether to start active (default: true) +-- @usage basalt.run() +-- @usage basalt.run(false) function basalt.run(isActive) updaterActive = isActive if(isActive==nil)then updaterActive = true end