From 8157c025ea670d3e4ac6d1462a8efa1a29422b50 Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Mon, 18 Jul 2022 13:58:43 +0200 Subject: [PATCH] docs again --- Basalt/main.lua | 34 +++- Basalt/objects/Program.lua | 4 +- Basalt/objects/Progressbar.lua | 3 - Basalt/objects/example.lua | 47 ------ docs/objects/Basalt.md | 91 +++++++++-- docs/objects/Button.md | 3 - docs/objects/Input.md | 1 - docs/objects/List.md | 276 ++++++++++++++++++++++++--------- docs/objects/Object.md | 35 ++--- docs/objects/Program.md | 48 +++--- docs/objects/Radio.md | 251 +++++++++++++++++++++--------- docs/objects/Thread.md | 2 +- 12 files changed, 535 insertions(+), 260 deletions(-) delete mode 100644 Basalt/objects/example.lua diff --git a/Basalt/main.lua b/Basalt/main.lua index 7d3d554..cf1cefe 100644 --- a/Basalt/main.lua +++ b/Basalt/main.lua @@ -9,7 +9,7 @@ local debugger = true local projectDirectory = fs.getDir(table.pack(...)[2] or "") -local activeKey, frames, monFrames, variables = {}, {}, {}, {} +local activeKey, frames, monFrames, variables, shedules = {}, {}, {}, {}, {} local mainFrame, activeFrame, focusedObject, updaterActive if not term.isColor or not term.isColor() then @@ -85,6 +85,27 @@ local bInstance = { end } +local function handleShedules(event, p1, p2, p3, p4) + if(#shedules>0)then + local finished = {} + for n=1,#shedules do + if(shedules[n]~=nil)then + if (coroutine.status(shedules[n]) == "suspended")then + local ok, result = coroutine.resume(shedules[n], event, p1, p2, p3, p4) + if not(ok)then + table.insert(finished, n) + end + else + table.insert(finished, n) + end + end + end + for n=1,#finished do + table.remove(shedules, finished[n]-(n-1)) + end + end +end + local function drawFrames() if(updaterActive)then if(mainFrame~=nil)then @@ -139,6 +160,7 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4) for _, v in pairs(frames) do v:eventHandler(event, p1, p2, p3, p4) end + handleShedules(event, p1, p2, p3, p4) drawFrames() end @@ -207,6 +229,16 @@ basalt = { end end end, + + shedule = function(f) + assert(f~="function", "Shedule needs a function in order to work!") + local co = coroutine.create(f) + local ok, result = coroutine.resume(co) + if(ok)then + table.insert(shedules, co) + end + return co + end, createFrame = function(name) name = name or uuid() diff --git a/Basalt/objects/Program.lua b/Basalt/objects/Program.lua index 1d51370..d7569cd 100644 --- a/Basalt/objects/Program.lua +++ b/Basalt/objects/Program.lua @@ -473,8 +473,8 @@ return function(name, parent) end; execute = function(self, path, ...) - cachedPath = path - curProcess = process:new(path, pWindow, ...) + cachedPath = path or cachedPath + curProcess = process:new(cachedPath, pWindow, ...) pWindow.setBackgroundColor(colors.black) pWindow.setTextColor(colors.white) pWindow.clear() diff --git a/Basalt/objects/Progressbar.lua b/Basalt/objects/Progressbar.lua index 35f010f..13b4177 100644 --- a/Basalt/objects/Progressbar.lua +++ b/Basalt/objects/Progressbar.lua @@ -36,9 +36,6 @@ return function(name) if(xmlValue("progressSymbol", data)~=nil)then activeBarSymbol = xmlValue("progressSymbol", data) end if(xmlValue("backgroundSymbol", data)~=nil)then bgBarSymbol = xmlValue("backgroundSymbol", data) end if(xmlValue("progressSymbolColor", data)~=nil)then activeBarSymbolCol = colors[xmlValue("progressSymbolColor", data)] end - if(xmlValue("scrollable", data)~=nil)then if(xmlValue("scrollable", data))then self:setScrollable(true) else self:setScrollable(false) end end - if(xmlValue("offset", data)~=nil)then self:setOffset(xmlValue("offset", data)) end - if(xmlValue("space", data)~=nil)then space = xmlValue("space", data) end if(xmlValue("onDone", data)~=nil)then self:onProgressDone(baseFrame:getVariable(xmlValue("onDone", data))) end return self end, diff --git a/Basalt/objects/example.lua b/Basalt/objects/example.lua deleted file mode 100644 index 0717d05..0000000 --- a/Basalt/objects/example.lua +++ /dev/null @@ -1,47 +0,0 @@ -local Object = require("Object") - -return function(name) - local base = Object(name) -- this will load the base object class, it is necessary if you want to make a visual object, otherwise you dont need that. - local objectType = "Example" -- here is the object type, make sure it is the same as the file name - this way you can also make sure its unique - - -- here you could set some default values, but its not necessary, it doesn't matter if you call the functions or change the values directly, maybe i should change that - --i guess its better if you call functions base:setBackground, base:setSize and so on. - base.width = 12 - base.height = 1 - base.bgColor = colors.lightGray - base.fgColor = colors.gray - base:setValue(false) - base:setZIndex(5) -- if you want to change the zIndex always use the function - - local object = { -- here you start your unique object class, please always make sure a getType exists! - getType = function(self) - return objectType - end; - - - mouseClickHandler = function(self, event, button, x, y) -- this is your extended mouseClickHandler, if you want something to happen if the user clicks on that - if (base.mouseClickHandler(self, event, button, x, y)) then -- here you access the base class mouseClickHandler it will return true if the user really clicks on the object - local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) --getAnchorPosition is obviously for returning the x and y coords changed by the anchor system, absolute position explains itself i guess - if ((event == "mouse_click") or (event == "mouse_drag")) and (button == 1) then - --here you can create your logic - end - return true -- please always return true if base.mouseClickHandler also returns true, otherwise your object wont get focused. - end - end; - - draw = function(self) -- if your object is visual, you will need a draw function - if (base.draw(self)) then - if (self.parent ~= nil) then - local obx, oby = self:getAnchorPosition() - --self.parent:drawBackgroundbox(obx, oby, self.width, self.height, self.bgColor) -- changes the background color of that object - --self.parent:drawForegroundbox(obx, oby, self.width, self.height, self.fgColor) -- changes the foreground (textcolor) color of that object - --self.parent:writeText(obx, oby, "Some Text", self.bgColor, self.fgColor) -- writes something on the screen, also able to change its bgcolor and fgcolor - - --the draw functions always gets called after something got visually changed. I am always redrawing the entire screen, but only if something has changed. - end - end - end; - } - - return setmetatable(object, base) -- required -end \ No newline at end of file diff --git a/docs/objects/Basalt.md b/docs/objects/Basalt.md index abaf32f..bd7ab63 100644 --- a/docs/objects/Basalt.md +++ b/docs/objects/Basalt.md @@ -15,7 +15,7 @@ Create a base-frame (main frame) #### Usage: * Create and show a frame with id "myFirstFrame" ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() +local mainFrame = basalt.createFrame("myFirstFrame") ``` ## basalt.removeFrame @@ -27,7 +27,7 @@ Removes a base frame #### Usage: * Removes the previously created frame with id "myFirstFrame" ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() +local mainFrame = basalt.createFrame("myFirstFrame") basalt.removeFrame("myFirstFrame") ``` @@ -42,7 +42,7 @@ Returns a base frame with the given name #### Usage: * Creates, fetches and shows the "myFirstFrame" object ```lua -basalt.createFrame("myFirstFrame") +basalt.createFrame("myFirstFrame"):hide() basalt.getFrame("myFirstFrame"):show() ``` @@ -56,8 +56,8 @@ Returns the currently active base frame #### Usage: * Displays the active frame name in the debug console ```lua -basalt.createFrame("myFirstFrame"):show() -basalt.debug(basalt.getActiveFrame():getName()) -- returns myFirstFrame +basalt.createFrame() +basalt.debug(basalt.getActiveFrame():getName()) -- returns the uuid ``` ## basalt.autoUpdate @@ -66,7 +66,7 @@ Starts the draw and event handler until basalt.stopUpdate() is called #### Usage: * Enable the basalt updates, otherwise the screen will not continue to update ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() +local mainFrame = basalt.createFrame() basalt.autoUpdate() ``` @@ -81,8 +81,8 @@ Calls the draw and event handler once - this gives more flexibility about which #### Usage: * Creates and starts a custom update cycle ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aButton = mainFrame:addButton("myButton"):setPosition(2,2):show() +local mainFrame = basalt.createFrame() +local aButton = mainFrame:addButton():setPosition(2,2) while true do basalt.update(os.pullEventRaw()) @@ -95,8 +95,8 @@ Stops the automatic draw and event handler which got started by basalt.autoUpdat #### Usage: * When the quit button is clicked, the button stops basalt auto updates ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aButton = mainFrame:addButton("myButton"):setPosition(2,2):setText("Stop Basalt!"):show() +local mainFrame = basalt.createFrame() +local aButton = mainFrame:addButton():setPosition(2,2):setText("Stop Basalt!") aButton:onClick(function() basalt.stopUpdate() @@ -117,8 +117,8 @@ Checks if the user is currently holding a key #### Usage: * Shows a debug message with true or false if the left ctrl key is down, as soon as you click on the button. ```lua -local mainFrame = basalt.createFrame("myFirstFrame"):show() -local aButton = mainFrame:addButton("myButton"):setPosition(2,2):setText("Check Ctrl"):show() +local mainFrame = basalt.createFrame() +local aButton = mainFrame:addButton():setPosition(2,2):setText("Check Ctrl") aButton:onClick(function() basalt.debug(basalt.isKeyDown(keys.leftCtrl) ) @@ -136,10 +136,75 @@ which returns the debug Label. Also basalt.debugFrame and basalt.debugList are available. #### Parameters: -1. `...` (multiple parameters are possible, like print does)
+1. `...` (multiple parameters are possible, like print does) #### Usage: * Prints "Hello! ^-^" to the debug console ```lua basalt.debug("Hello! ", "^-^") ``` + +## setTheme +Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) + +#### Parameters: +1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example + +#### Usage: +* Creates a new base frame and adds a new theme which only changes the default color of buttons. +```lua +basalt.setTheme({ + ButtonBG = colors.yellow, + ButtonText = colors.red, + ..., +}) +``` + +## setVariable +This stores a variable which you're able to access via xml. You are also able to add a function, which then gets called by object events created in XML. + +#### Parameters: +1. `string` a key name +1. `any` any variable + +#### Usage: +* Adds a function to basalt. +```lua +basalt.setVariable("clickMe", function() + basalt.debug("I got clicked") +end) +``` +```xml + + + + + + - + +