diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..c5c39c4 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,21 @@ +# Welcome to The Basalt Wiki! +*Note: The Basalt Wiki is a work in progress, now also just migrated away from github wiki. Please treat Wiki errors the same as bugs and report them accordingly.* + +Here you can find information about how to use Basalt as well as examples of functional Basalt code. The aim of Basalt is to improve user interaction through visual display. + +On the left side of this page you can find a Wiki Navigation, where you can find a more detailed list of Basalt's features + +## About Basalt + +Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (AKA Computer Craft: Tweaked) - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's home page. + +## Quick Demo +![Preview](https://media0.giphy.com/media/fvmNPshXKeU7FFA9iA/giphy.gif) + +## Questions & Bugs + +Obviously NyoriE has implemented some easter eggs, _some people_ call them "bugs". If you happen to discover one of these just make a new issue. + +Additionally, if you have questions about Basalt or how to make use of it, feel free to create a new discussion on Basalt's Discussion Board. + +You may also join the Discord: https://discord.gg/yNNnmBVBpE \ No newline at end of file diff --git a/docs/_sidebar.md b/docs/_sidebar.md new file mode 100644 index 0000000..0d0aca5 --- /dev/null +++ b/docs/_sidebar.md @@ -0,0 +1,29 @@ +- Home + - [Home](/) + - [Getting Started](/home/gettingStarted) + - [Installer](/home/installer) +- Objects + - [Animation](/objects/Animation) + - [Basalt](/objects/Basalt) + - [Button](/objects/Button) + - [Checkbox](/objects/Checkbox) + - [Dropdown](/objects/Dropdown) + - [Frame](/objects/Frame) + - [Image](/objects/Image) + - [Input](/objects/Input) + - [Label](/objects/Label) + - [List](/objects/List) + - [Menubar](/objects/Menubar) + - [Object](/objects/Object) + - [Pane](/objects/Pane) + - [Program](/objects/Program) + - [Radio](/objects/Radio) + - [Scrollbar](/objects/Scrollbar) + - [Silder](/obects/Slider) + - [Textfield](/objects/Textfield) + - [Thread](/objects/Thread) + - [Timer](/objects/Timer) + +- Tips & tricks + - [Executing own logic](/tips/logic) + - [Changing button colors](/tips/buttons) \ No newline at end of file diff --git a/docs/home/gettingStarted.md b/docs/home/gettingStarted.md new file mode 100644 index 0000000..b470a31 --- /dev/null +++ b/docs/home/gettingStarted.md @@ -0,0 +1,71 @@ +# Getting Started! + +Basalt aims to be a relatively small, easy to use framework. + +Accordingly, we have provided an installation script. + + +Just use the following command in any CC:Tweaked shell: + +`wget https://github.com/Pyroxenium/Basalt/raw/master/basalt.lua basalt.lua` + +This will download `basalt.lua` to your local directory. + +To load the framework, make use of the following snippet: +````lua +--> For those who are unfamiliar with lua, dofile executes the code in the referenced file +local basalt = dofile("basalt.lua") +```` + + +Here is a fully functioning example of Basalt code: + +````lua +local basalt = dofile("basalt.lua") --> Load the Basalt framework + +--> Create the first frame. Please note that Basalt needs at least one active "non-parent" frame to properly supply events +--> When Basalt#createFrame makes use of unique identifiers (commonly referred to as UIDs), meaning that the supplied value must be UNIQUE +--> If the supplied UID is ambiguous, Basalt#createFrame returns a nil value +local mainFrame = basalt.createFrame("mainFrame") + +--> Show the frame to the user +mainFrame:show() + +local button = mainFrame:addButton("clickableButton") --> Add a button to the mainFrame (With a unique identifier) + +--> Set the position of the button, Button#setPosition follows an x, y pattern. +--> The x value is how far right the object should be from its anchor (negative values from an anchor will travel left) +--> The y value is how far down the object should be from its anchor (negative values from an anchor will travel up) +button:setPosition(4, 4) + +button:setText("Click me!") --> Set the text of our button + +local function buttonClick() --> This function serves as our click logic + basalt.debug("I got clicked!") +end + +--> Remember! You cannot supply buttonClick(), that will only supply the result of the function +--> Make sure the button knows which function to call when it's clicked +button:onClick(buttonClick) + +button:show() --> Make the button visible, so the user can click it + +basalt.autoUpdate() --> Basalt#autoUpdate starts the event listener to detect user input +```` +If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above: +````lua +local basalt = dofile("basalt.lua") + +local mainFrame = basalt.createFrame("mainFrame"):show() +local button = mainFrame --> Basalt returns an instance of the object on most methods, to make use of "call-chaining" + :addButton("clickableButton") --> This is an example of call chaining + :setPosition(4,4) + :setText("Click me!") + :onClick( + function() + basalt.debug("I got clicked!") + end) + :show() + +basalt.autoUpdate() +```` diff --git a/docs/home/installer.md b/docs/home/installer.md new file mode 100644 index 0000000..cc83958 --- /dev/null +++ b/docs/home/installer.md @@ -0,0 +1,74 @@ +# Installer + +This is just a script which helps you to install basalt.lua, if it's not already on the computer. Means, you create your program (which requires basalt) and add this on the top of your program. Now, everytime you execute your program it checks if basalt.lua exists or not. + +## Visual Installer +This is a visual version, it asks the user if he wants to install basalt.lua (if not found)
+![](https://i.imgur.com/b4Ys7FB.png) +````lua +--Basalt configurated installer +local filePath = "basalt.lua" --here you can change the file path default: basalt.lua +if not(fs.exists(filePath))then + local w,h = term.getSize() + term.clear() + local _installerWindow = window.create(term.current(),w/2-8,h/2-3,18,6) + _installerWindow.setBackgroundColor(colors.gray) + _installerWindow.setTextColor(colors.black) + _installerWindow.write(" Basalt Installer ") + _installerWindow.setBackgroundColor(colors.lightGray) + for line=2,6,1 do + _installerWindow.setCursorPos(1,line) + if(line==3)then + _installerWindow.write(" No Basalt found! ") + elseif(line==4)then + _installerWindow.write(" Install it? ") + elseif(line==6)then + _installerWindow.setTextColor(colors.black) + _installerWindow.setBackgroundColor(colors.gray) + _installerWindow.write("Install") + _installerWindow.setBackgroundColor(colors.lightGray) + _installerWindow.write(string.rep(" ",5)) + _installerWindow.setBackgroundColor(colors.red) + _installerWindow.write("Cancel") + else + _installerWindow.write(string.rep(" ",18)) + end + end + _installerWindow.setVisible(true) + _installerWindow.redraw() + while(not(fs.exists(filePath))) do + local event, p1,p2,p3,p4 = os.pullEvent() + if(event=="mouse_click")then + if(p3==math.floor(h/2+2))and(p2>=w/2-8)and(p2<=w/2-2)then + shell.run("pastebin run ESs1mg7P") -- this is an alternative to the wget command + _installerWindow.setVisible(false) + term.clear() + break + end + if(p3==h/2+2)and(p2<=w/2+9)and(p2>=w/2+4)then + _installerWindow.clear() + _installerWindow.setVisible(false) + term.setCursorPos(1,1) + term.clear() + return + end + end + end + term.setCursorPos(1,1) + term.clear() +end + +local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt +```` + +## Basic Installer +Here is a very basic one which just installs basalt.lua if don't exist: +````lua +--Basalt configurated installer +local filePath = "basalt.lua" --here you can change the file path default: basalt.lua +if not(fs.exists(filePath))then + shell.run("wget https://github.com/Pyroxenium/Basalt/raw/master/basalt.lua basalt.lua") +end +local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt + +```` \ No newline at end of file diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..f30aaa4 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,24 @@ + + + + + + + + Basalt Docs + + +
+ + + + + \ No newline at end of file diff --git a/docs/objects/Animation.md b/docs/objects/Animation.md new file mode 100644 index 0000000..06ac2b5 --- /dev/null +++ b/docs/objects/Animation.md @@ -0,0 +1,55 @@ +# Animation + +With animations you can create a beautiful experience for users while interacting with objects.
+For now the animation class is very basic, i will expand it in the future, but i have to say already now you can do almost everything you can imagine! + +Right now animation is a class which makes use of the timer event
+Here are all possible functions available for animations: + +## add +adds a new function to your animation +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local testButton = mainFrame:addButton("myTestButton"):show() +local aAnimation = mainFrame:addAnimation("anim1"):add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end) + +aAnimation:play() -- this will set the button position to 3,3, waits 1 sec., sets it to 4,4, waits 2 sec. and then sets the position to 5,5 +```` +**parameters:** function
+**returns:** self
+ +## wait +sets a wait timer for the next function after the previous function got executed, no wait timer calls the next function immediatly +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local testButton = mainFrame:addButton("myTestButton"):show() +local aAnimation = mainFrame:addAnimation("anim1"):add(function() testButton:setPosition(3,3) end):wait(1):add(function() testButton:setPosition(1,1,"r") end):wait(2):add(function() testButton:setPosition(1,1,"r") end) + +aAnimation:play() -- this will set the button position to 3,3, waits 1 sec., sets it to 4,4, waits 2 sec. and then sets the position to 5,5 +```` +**parameters:** timer - how long we should wait to call the next function
+**returns:** self
+ +## play +starts to play the animation +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local testButton = mainFrame:addButton("myTestButton"):show() +local aAnimation = mainFrame:addAnimation("anim1"):add(function() testButton:setBackground(colors.black) end):wait(1):add(function() testButton:setBackground(colors.gray) end):wait(1):add(function() testButton:setBackground(colors.lightGray) end) + +aAnimation:play() -- changes the background color of that button from black to gray and then to lightGray +```` +**parameters:** [endlessloop] - bool if it should loop forever - will change that to loopcount in the future
+**returns:** self
+ +## cancel +cancels the animation +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local testButton = mainFrame:addButton("myTestButton"):show() +local aAnimation = mainFrame:addAnimation("anim1"):add(function() testButton:setBackground(colors.black) end):wait(1):add(function() aAnimation:cancel() end):wait(1):add(function() testButton:setBackground(colors.lightGray) end) + +aAnimation:play() +```` +**parameters:** -
+**returns:** self
\ No newline at end of file diff --git a/docs/objects/Basalt.md b/docs/objects/Basalt.md new file mode 100644 index 0000000..ab727d7 --- /dev/null +++ b/docs/objects/Basalt.md @@ -0,0 +1,80 @@ +# Basalt + +Basalt is managing all the things. + +To start using Basalt you have to do the following line of code: + +`local basalt = dofile("basalt.lua")` + +remember you need the basalt.lua file on your computer! + +Now you are able to call all these functions: + +## basalt.createFrame +create a frame without a parent +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +```` +**parameters:** string name
+**returns:** new frame object
+ +## basalt.removeFrame +removes a frame (only possible for non-parent frames) +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +basalt.removeFrame("myFirstFrame") +```` +**parameters:** string name
+**returns:**-
+ +## basalt.getFrame +With that function you can get frames, but only frames without a parent! +````lua +basalt.createFrame("myFirstFrame") +basalt.getFrame("myFirstFrame"):show() +```` +**parameters:** string name
+**returns:** frame object
+ +## basalt.getActiveFrame +returns the currently active (without a parent) frame +````lua +basalt.createFrame("myFirstFrame"):show() +basalt.debug(basalt.getActiveFrame():getName()) -- returns myFirstFrame +```` +**parameters:** -
+**returns:** frame object
+ +## basalt.autoUpdate +starts the draw and event handler until you use basalt.stopUpdate +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +basalt.autoUpdate() +```` +**parameters:** -
+**returns:**-
+ +## basalt.update +calls the draw and event handler method once +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +basalt.autoUpdate() +```` +**parameters:** string event, ... (you can use some paramters here. you dont have to pass any paramters )
+**returns:**-
+ +## basalt.stopUpdate +stops the draw and event handler +````lua +basalt.stopUpdate() +```` +**parameters:** -
+**returns:**-
+ +## basalt.debug +creates a label with some information on the main frame on the bottom left, if you click on that label it will open a log view for you see it as the new print for debugging +````lua +basalt.debug("Hi i am cute") +```` +**parameters:** ... (multiple parameters are possible, like print does)
+**returns:**-
\ No newline at end of file diff --git a/docs/objects/Button.md b/docs/objects/Button.md new file mode 100644 index 0000000..a4c9066 --- /dev/null +++ b/docs/objects/Button.md @@ -0,0 +1,25 @@ +# Button + +Buttons are objects, which execute function by clicking on them + +The following list is only available to buttons:
+Remember button also inherits from [object](/objects/Object): + +## setText +Sets the displayed button text +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):setText("Click"):show() -- you could also use :setValue() instead of :setText() - no difference +```` +**Arguments:** string text
+**returns:** self
+ +## Examples +Add a onClick event: +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):setText("Click"):onClick(function(self,event,button,x,y) +if(event=="mouse_click")and(button==1)then +basalt.debug("Left mousebutton got clicked!") +end +end):show() \ No newline at end of file diff --git a/docs/objects/Checkbox.md b/docs/objects/Checkbox.md new file mode 100644 index 0000000..8896900 --- /dev/null +++ b/docs/objects/Checkbox.md @@ -0,0 +1,14 @@ +# Checkbox + +With checkbox, the user can set a bool to true or false + +Here are all possible functions available for checkbox: + Remember checkbox inherits from [object](/objects/Object): + + +Create a onChange event: +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):onChange(function(self) basalt.debug("The value got changed into "..self:getValue()) end):show() + +```` \ No newline at end of file diff --git a/docs/objects/Dropdown.md b/docs/objects/Dropdown.md new file mode 100644 index 0000000..b4b0b6c --- /dev/null +++ b/docs/objects/Dropdown.md @@ -0,0 +1,180 @@ +# Dropdown + +Dropdowns are objects where you can create endless entrys the user can click on a button and it opens a "list" where the user can choose a entry + +Here is a example of how to create a standard dropdown: + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +```` + +Here are all possible functions available for dropdowns:
+Remember dropdown inherits from [object](/objects/Object): + +## addItem +Adds a item to the dropdown + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +```` +**parameters:** string text, number bgcolor, number fgcolor, any ... - (text is the displayed text, bgcolor and fgcolors the colors of background/text and args (...) is something dynamic, you wont see them but if you require some more information per item you can use that)
+**returns:** self
+ +## removeItem +Removes a item from the dropdown + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:removeItem(2) +```` +**parameters:** number index
+**returns:** self
+ +## editItem +Edits a item on the dropdown + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:editItem(3,"3. Edited Entry",colors.yellow,colors.green) +```` +**parameters:** number index, string text, number bgcolor, number fgcolor, any ...
+**returns:** self
+ +## setScrollable +Makes the dropdown scrollable + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:setScrollable(true) +```` +**parameters:** boolean isScrollable
+**returns:** self
+ +## selectItem +selects a item in the dropdown (same as a player would click on a item) + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:selectItem(1) +```` +**parameters:** number index
+**returns:** self
+ +## clear +clears the entire list (dropdown) + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:clear() +```` +**parameters:** -
+**returns:** self
+ +## getItemIndex +returns the item index of the currently selected item + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:getItemIndex() +```` +**parameters:** -
+**returns:** number index
+ +## setSelectedItem +Sets the background of the item which is currently selected + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:setSelectedItem(colors.green, colors.blue) +```` +**parameters:** number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)
+**returns:** self
+ +## setOffset +sets the dropdown offset (will automatically change if scrolling is active) + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:setOffset(3) +```` +**parameters:** number offsetValue
+**returns:** self
+ +## getOffset +returns the current offset + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:getOffset() +```` +**parameters:** -
+**returns:** number offsetValue
+ +## getOffset +returns the current offset + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:getOffset() +```` +**parameters:** -
+**returns:** number offsetValue
+ +## setDropdownSize +sets the dropdown size (if you click on the button) + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:setDropdownSize(12, 4) +```` +**parameters:** number width, number height
+**returns:** self
\ No newline at end of file diff --git a/docs/objects/Frame.md b/docs/objects/Frame.md new file mode 100644 index 0000000..174f0fc --- /dev/null +++ b/docs/objects/Frame.md @@ -0,0 +1,159 @@ +# Frames + + + +Frames are like containers, but are also normal objects. +In other words, you can add other objects _(even frames)_ to a frame; if the frame itself is visible +all sub-objects _(if they are set as visible)_ are also visible. A better description will follow. + +## basalt.createFrame +Creates a new non-parent frame - in most cases it is the first thing you need. + +````lua +local myFirstFrame = basalt.createFrame("myFirstFrame") +```` +**Parameters:**
+1. string name (should be unique)
+**returns:** new frame object
+ +## addFrame +The same as basalt.createFrame, but it will have a parent frame +````lua +frame:addFrame("myFirstFrame") +```` +**Parameters:** string name (should be unique)
+**returns:** new frame object
+Example: +````lua +local mainFrame = basalt.createFrame("myFirstFrame") +local aFrame = mainFrame:addFrame("myFirstSubFrame") +```` +## setBar +Changes the frame bar +````lua +frame:setBar("My first Frame!", colors.gray, colors.lightGray) +```` +**Parameters:** string text, number bgcolor, number fgcolor
+**returns:** self
+Example: +````lua +local mainFrame = basalt.createFrame("myFirstFrame") +local aFrame = MainFrame:addFrame("myFirstSubFrame") +aFrame:setBar("My first Frame!") +```` +or: +````lua +local mainFrame = basalt.createFrame("myFirstFrame") +local aFrame = mainFrame:addFrame("myFirstSubFrame"):setBar("My first Frame!") +```` + +## setBarTextAlign +Sets the bar text alignment +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setBar("My first Frame!"):setBarTextAlign("right") +```` +**Parameters:** string value - ("left", "center", "right"))
+**returns:** self
+ + + +## showBar +shows/hides the bar on top where you will see the title if its active +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setBar("Hello World!"):showBar() +```` +**Parameters:** bool visible (no Parameters = true)
+**returns:** self
+ +## isModifierActive -- DISABLED this function will work very soon +returns true if user is currently holding a key down +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):isModifierActive("shift") +```` +**Parameters:** int or string - int can be any os.queueEvent("key") key, or instead of int you can use the following strings: "shift", "ctrl", "alt"
+**returns:** boolean - if the user is holding the key down
+ +**Example:** +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setSize(20,8):show() +local aLabel = mainFrame:addLabel("myFirstLabel"):setText("shift inactive") +mainFrame:addButton("myFirstButton"):setText("Click"):onClick(function() +if(mainFrame:isModifierActive("shift")then + aLabel:setText("shift is active yay") +else + aLabel:setText("shift is not active ohno") +end) +```` + +## getObject +returns a children object +````lua +local mainFrame = basalt.createFrame("myFirstFrame") +mainFrame:addButton("myFirstButton") +local aButton = mainFrame:getObject("myFirstButton") +```` +**Parameters:** string name (has to be a children)
+**returns:** any object
+ +## removeObject +removes the object +````lua +local mainFrame = basalt.createFrame("myFirstFrame") +mainFrame:addButton("myFirstButton") +mainFrame:removeObject("myFirstButton") +```` +**Parameters:** string name (has to be a children)
+**returns:** any object
+ +## setFocusedObject +changes the currently focused object +````lua +local mainFrame = basalt.createFrame("myFirstFrame") +local aButton = mainFrame:addButton("myFirstButton") +mainFrame:setFocusedObject(aButton) +```` +**Parameters:** any object (has to be a children)
+**returns:** self
+## removeFocusedObject +removes the focus of the currently focused object +````lua +local mainFrame = basalt.createFrame("myFirstFrame") +local aButton = mainFrame:addButton("myFirstButton") +mainFrame:removeFocusedObject(aButton) +```` +**Parameters:** any object (has to be a children)
+**returns:** self
+ +## getFocusedObject +gets the currently focused object +````lua +local mainFrame = basalt.createFrame("myFirstFrame") +local aButton = mainFrame:addButton("myFirstButton") +local focusedObject = mainFrame:getFocusedObject() +```` +**Parameters:** -
+**returns:** object
+ +## setMovable + + +## setMoveable +##### _Deprecated in favor of setMovable_ + +sets if the frame should be moveable or not (to move the frame you need to drag it on the top bar) + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setMoveable(true) +```` +**Parameters:** bool moveable
+**returns:** self
+ +## setOffset +sets the frame's coordinate offset, they will get added to their children objects. For example, if you use the scrollbar and you use its value to add a offset to a frame, you will get a scrollable frame. +objects are also able to ignore the offset by using :ignoreOffset() (maybe your scrollbar if its a children of the frame should ignore offset) + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setOffset(5, 3) +```` +**Parameters:** number x, number y (offset in x direction and offset in y direction, also doesn't matter if its a negative value or positive
+**returns:** self
diff --git a/docs/objects/Image.md b/docs/objects/Image.md new file mode 100644 index 0000000..a63e0f6 --- /dev/null +++ b/docs/objects/Image.md @@ -0,0 +1,37 @@ +# Image + +The image object is for adding more advanced backgrounds. +It also provides a :shrink() function, where you can shrink the images to smaller ones. This functionallity is fully provided by the blittle library created by Bomb Bloke. I did not ask for permission to add it into the framework. If the creator wants me to remove the blittle part, just text me on discord! + +Here are all possible functions available for image: +Remember image inherits from [object](/objects/Object): + + +## loadImage +loads a image into the memory. +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aImage = mainFrame:addImage("myFirstImage"):loadImage("randomImage.nfp"):show() +```` +**Arguments:** string path
+**returns:** self
+ + +## loadBlittleImage -- not finished yet +loads a blittle image into the memory. +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aImage = mainFrame:addImage("myFirstImage"):loadBlittleImage("blittleImage.blt"):show() +```` +**Arguments:** string path
+**returns:** self
+ +## shrink +If you were loading a normal (paint) image into the memory, this function would shrink it to a +blittle image and immediatly draws it (if it's visible) +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aImage = mainFrame:addImage("myFirstImage"):loadBlittleImage("randomImage.nfp"):shrink():show() +```` +**Arguments:** -
+**returns:** self
\ No newline at end of file diff --git a/docs/objects/Input.md b/docs/objects/Input.md new file mode 100644 index 0000000..83d5e82 --- /dev/null +++ b/docs/objects/Input.md @@ -0,0 +1,15 @@ +# Input + +With input's you are able to create a object where the user can type something in.
+ +Here are all possible functions available for inputs:
+Remember input inherits from [object](/objects/Object): + +## setInputType +changes the input type +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aInput = mainFrame:addInput("myFirstInput"):setInputType("password"):show() +```` +**parameters:** string value ("text", "password", "number")
+**returns:** self
\ No newline at end of file diff --git a/docs/objects/Label.md b/docs/objects/Label.md new file mode 100644 index 0000000..09f6093 --- /dev/null +++ b/docs/objects/Label.md @@ -0,0 +1,17 @@ +# Label + +With the Label object you are able to add some text. + +By default label's width is auto sizing based on the length of the text. If you change the size with setSize it will automatically stop autosizing the width. + +Here are all possible functions available for labels.
+Remember label inherits from [object](/objects/Object): + +## setText +sets the text which gets displayed. +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aInput = mainFrame:addLabel("myFirstLabel"):setText("Hello lovely basalt community!"):show() +```` +**arguments:** string text
+**returns:** self
\ No newline at end of file diff --git a/docs/objects/List.md b/docs/objects/List.md new file mode 100644 index 0000000..4aed420 --- /dev/null +++ b/docs/objects/List.md @@ -0,0 +1,153 @@ +# List + +Lists are objects where you can create endless entrys and the user can choose one of them + +Here is a example of how to create a standard list: + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aList = mainFrame:addList("myFirstList"):show() +```` + +This will create a default list with the size 8 width and 5 height on position 1 1 (relative to its parent frame), the default background is colors.lightGray, the default text color is colors.black and the default zIndex is 5. The default horizontal text align is "center", default symbol is ">" + +Here are all possible functions available for lists. Remember list inherit from [object](/objects/Object): + +## addItem +Adds a item to the list + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aList = mainFrame:addList("myFirstList"):show() +aList:addItem("1. Entry") +aList:addItem("2. Entry",colors.yellow) +aList:addItem("3. Entry",colors.yellow,colors.green) +```` +**parameters:** string text, number bgcolor, number fgcolor, any ... - (text is the displayed text, bgcolor and fgcolors the colors of background/text and args (...) is something dynamic, you wont see them but if you require some more information per item you can use that)
+**returns:** self
+ +## removeItem +Removes a item from the list + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aList = mainFrame:addList("myFirstList"):show() +aList:addItem("1. Entry") +aList:addItem("2. Entry",colors.yellow) +aList:addItem("3. Entry",colors.yellow,colors.green) +aList:removeItem(2) +```` +**parameters:** number index
+**returns:** self
+ +## editItem +Edits a item on the list + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aList = mainFrame:addList("myFirstList"):show() +aList:addItem("1. Entry") +aList:addItem("2. Entry",colors.yellow) +aList:addItem("3. Entry",colors.yellow,colors.green) +aList:editItem(3,"3. Edited Entry",colors.yellow,colors.green) +```` +**parameters:** number index, string text, number bgcolor, number fgcolor, any ...
+**returns:** self
+ +## setScrollable +Makes the list scrollable + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aList = mainFrame:addList("myFirstList"):show() +aList:addItem("1. Entry") +aList:addItem("2. Entry",colors.yellow) +aList:addItem("3. Entry",colors.yellow,colors.green) +aList:setScrollable(true) +```` +**parameters:** boolean isScrollable
+**returns:** self
+ +## selectItem +selects a item in the list (same as a player would click on a item) + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aList = mainFrame:addList("myFirstList"):show() +aList:addItem("1. Entry") +aList:addItem("2. Entry",colors.yellow) +aList:addItem("3. Entry",colors.yellow,colors.green) +aList:selectItem(1) +```` +**parameters:** number index
+**returns:** self
+ +## clear +clears the entire list + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:clear() +```` +**parameters:** -
+**returns:** self
+ +## getItemIndex +returns the item index of the currently selected item + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() +aDropdown:addItem("1. Entry") +aDropdown:addItem("2. Entry",colors.yellow) +aDropdown:addItem("3. Entry",colors.yellow,colors.green) +aDropdown:getItemIndex() +```` +**parameters:** -
+**returns:** number index
+ +## setSelectedItem +Sets the background of the item which is currently selected + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aList = mainFrame:addList("myFirstList"):show() +aList:addItem("1. Entry") +aList:addItem("2. Entry",colors.yellow) +aList:addItem("3. Entry",colors.yellow,colors.green) +aList:setSelectedItem(colors.green, colors.blue) +```` +**parameters:** number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)
+**returns:** self
+ +## setOffset +sets the list offset (will automatically change if scrolling is active) + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aList = mainFrame:addList("myFirstList"):show() +aList:addItem("1. Entry") +aList:addItem("2. Entry",colors.yellow) +aList:addItem("3. Entry",colors.yellow,colors.green) +aList:setOffset(3) +```` +**parameters:** number offsetValue
+**returns:** self
+ +## getOffset +returns the current offset + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aList = mainFrame:addList("myFirstList"):show() +aList:addItem("1. Entry") +aList:addItem("2. Entry",colors.yellow) +aList:addItem("3. Entry",colors.yellow,colors.green) +aList:getOffset() +```` +**parameters:** -
+**returns:** number offsetValue
\ No newline at end of file diff --git a/docs/objects/Menubar.md b/docs/objects/Menubar.md new file mode 100644 index 0000000..55be638 --- /dev/null +++ b/docs/objects/Menubar.md @@ -0,0 +1,3 @@ +# Menubar + +WIP \ No newline at end of file diff --git a/docs/objects/Object.md b/docs/objects/Object.md new file mode 100644 index 0000000..aa9704e --- /dev/null +++ b/docs/objects/Object.md @@ -0,0 +1,249 @@ +# Objects + +This is the base class of all visual objects. This means, if you create a button, label, frame or something else visual (no timers, threads or animations) the following list can be used: + +## show +shows the object (only if the parent frame is already visible) +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local button = mainFrame:addButton("myFirstButton") +button:show() +```` +**parameters:** -
+**returns:** self
+ +## hide +hides the object +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local button = mainFrame:addButton("myFirstButton"):setText("Close"):onClick(function() mainFrame:hide() end) +button:show() +```` +**parameters:** -
+**returns:** self
+ +## setPosition +Changes the position relative to its parent frame +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setPosition(2,3) +```` +**parameters:** number x, number y[, boolean relative], if relative is set to true it will add/remove instead of set x, y
+**returns:** self
+ + + +## setBackground +Changes the object background color +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setBackground(colors.lightGray) +```` +**parameters:** number color
+**returns:** self
+ +## setForeground +Changes the object text color +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setForeground(colors.black) +```` +**parameters:** number color
+**returns:** self
+ +## setSize +Changes the object size +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setSize(15,5) +```` +**parameters:** number width, number length
+**returns:** self
+ +## setFocus +sets the object to be the focused object. +If you click on a object, it's normaly automatically the focused object. As example, if you :show() a frame and you want this particular frame to be in +the foreground, you have to use :setFocus() +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):setFocus():show() +```` +**parameters:** -
+**returns:** self
+ +## setZIndex +changes the z index (higher z index do have higher draw/event priority) 10 is more important than 5 or 1. You are also able to add multiple objects to the same z index, which means if you create a couple of buttons, you set their z index to 10, everything below 10 is less important, everything above 10 is more important. On the same z index: the last object which gets created is the most important one. +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):setZIndex(1):show() +```` +**parameters:** number index
+**returns:** self
+ +## setParent +changes the frame parent of that object +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aRandomFrame = basalt.createFrame("aRandomFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):onClick(function() aRandomFrame:setParent(mainFrame) end):show() +```` +**parameters:** frame object
+**returns:** self
+ +## isFocused +returns if the object is currently the focused object of the parent frame + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):show() +basalt.debug(aButton:isFocused()) -- shows true or false as a debug message +```` +**parameters:** -
+**returns:** boolean
+ +## getAnchorPosition +converts the x,y coordinates into the anchor coordinates of that object + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setSize(15,15):show() +local aButton = mainFrame:addButton("myFirstButton"):setAnchor("right","bottom"):setSize(8,1):setPosition(1,1):show() +basalt.debug(aButton:getAnchorPosition()) -- returns 7,14 (framesize - own size) instead of 1,1 +```` +**parameters:** number x, number y - or nothing (if nothing it uses the object's x, y)
+**returns:** number x, number y (converted)
+ +## setAnchor +sets the anchor of that object + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setAnchor("right"):show() +local aButton = mainFrame:addButton("myFirstButton"):setAnchor("bottom","right"):setSize(8,1):setPosition(1,1):show() +```` +**parameters:** string sides - ("left", "right", "top", "bottom") you can stack positions like so ..:setAnchor("right", "bottom")
+**returns:** self
+ +## getAbsolutePosition +converts the relative coordinates into absolute coordinates +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):setPosition(3,3):show() +local aButton = mainFrame:addButton("myFirstButton"):setSize(8,1):setPosition(4,2):show() +basalt.debug(aButton:getAbsolutePosition()) -- returns 7,5 (frame coords + own coords) instead of 4,2 +```` +**parameters:** number x, number y - or nothing (if nothing it uses the object's x, y)
+**returns:** self
+ +## setTextAlign +sets the text align of the object (for example buttons) +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):setSize(12,3):setTextAlign("right", "center"):setText("Dont't..."):show() +```` +**parameters:** string horizontal, string vertical - ("left", "center", "right")
+**returns:** self
+ +## setValue +sets the value of that object (input, label, checkbox, textfield, scrollbar,...) +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):setValue(true):show() +```` +**parameters:** any value
+**returns:** self
+ +## getValue +returns the currently saved value +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):setValue(true):show() +basalt.debug(aCheckbox:getValue()) -- returns true +```` +**parameters:**-
+**returns:** any value
+ +## getHeight/getWidth +returns the height or width +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):setSize(5,8):show() +basalt.debug(aButton:getHeight()) -- returns 8 +```` +**parameters:**-
+**returns:** number height/width
+ +## isVisible +returns if the object is currently visible +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):setSize(5,8):show() +basalt.debug(aButton:isVisible()) -- returns true +```` +**parameters:**-
+**returns:** boolean
+ +## getName +returns the given name of that object +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +basalt.debug(mainFrame:getName()) -- returns myFirstFrame +```` +**parameters:**-
+**returns:** string name
+ +# Object Events +These object events are available for all objects, if a object got some unique events, you can see them in their own category + +## onClick +creates a mouse_click event +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):setSize(10,3):onClick(function(self,event,button,x,y) basalt.debug("Hellooww UwU") end):show() +```` +**parameters:** function func
+**returns:** self
+ +## onClickUp +creates a click_up event +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):setSize(10,3):onClickUp(function(self,event,button,x,y) basalt.debug("Byeeeee UwU") end):show() +```` +**parameters:** function func
+**returns:** self
+ +## onMouseDrag +creates a mouse_drag event +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aButton = mainFrame:addButton("myFirstButton"):setSize(10,3):onClickUp(function(self,event,button,x,y) basalt.debug("Byeeeee UwU") end):show() +```` +**parameters:** function func
+**returns:** self
+ +## onChange +creates a change event (fires as soon as the value gets changed) +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):onChange(function(self) basalt.debug("i got changed into "..self:getValue()) end):show() +```` +**parameters:** function func
+**returns:** self
+ +## onKey +creates a key(board) - event can be key or char +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):onKey(function(self,event,key) basalt.debug("you clicked "..key) end):show() +```` +**parameters:** function func
+**returns:** self
+ +## onLoseFocus +creates a lose focus event +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):onLoseFocus(function(self) basalt.debug("please come back..") end):show() +```` +**parameters:** function func
+**returns:** self
+ +## onGetFocus +creates a get focus event +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):onGetFocus(function(self) basalt.debug("thanks!") end):show() +```` +**parameters:** function func
+**returns:** self
\ No newline at end of file diff --git a/docs/objects/Pane.md b/docs/objects/Pane.md new file mode 100644 index 0000000..4399fbb --- /dev/null +++ b/docs/objects/Pane.md @@ -0,0 +1,18 @@ +# Pane + +Panes are very simple sizeable background objects. + +The following list is only available to panes:
+Remember pane also inherits from [object](/objects/Object): + +Pane doesn't have any custom functionallity. If you want to change the color/position or size, just check out the [object](/objects/Object) wikipage. + +## Example: + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aPane = mainFrame:addPane("myFirstBackground") +aPane:setSize(30, 10) +aPane:setBackground(colors.yellow) +aPane:show() +```` \ No newline at end of file diff --git a/docs/objects/Program.md b/docs/objects/Program.md new file mode 100644 index 0000000..c4760ac --- /dev/null +++ b/docs/objects/Program.md @@ -0,0 +1,104 @@ +# Program + +With a program object you are able to open programs like shell or worm or any custom program you've made. There is only 1 thing you have to remember: the program needs at least one os.sleep() or coroutine.yield() somewhere. +
+Here is a list of all available functions for programs:
+Remember program inherits from [object](/objects/Object): + +## getStatus +returns the current status +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aProgram = mainFrame:addProgram("myFirstProgram"):show() +basalt.debug(aProgram:getStatus()) -- returns "running", "normal", "suspended" or "dead" +```` +**parameters:**-
+**returns:** string "running" - if its running, "normal" - is active but not running (waiting for a event), "suspended" - is suspended or not started, "dead" - has finished or stopped with an error
+ +## execute +executes the given path (-program) +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aProgram = mainFrame:addProgram("myFirstProgram"):show() +aProgram:execute("rom/programs/fun/worm.lua") -- executes worm +```` +**parameters:** string filepath - (the path to the program you want to execute)
+**returns:** self
+ +## stop +gives a terminate event to the program, which means if you are running a shell, and the shell executes a program by itself you have to call stop 2 times to entirely close the running program +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show() +mainFrame:addButton("myFirstButton"):setText("close"):onClick(function() aProgram:stop() end):show() + +```` +**parameters:**-
+**returns:** self
+ +## pause +pauses the program (prevents the program from receiving events) +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show() +mainFrame:addButton("myFirstButton"):setText("close"):onClick(function() aProgram:pause(true) end):show() + +```` +**parameters:** boolean pause
+**returns:** self
+ +## isPaused +returns if the program is currently paused +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show() +mainFrame:addButton("myFirstButton"):setText("pause"):onClick(function() basalt.debug(aProgram:isPaused()) end):show() + +```` +**parameters:** -
+**returns:** boolean isPaused
+ +## injectEvent +injects a event into the program manually +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show() +mainFrame:addButton("myFirstButton"):setText("inject"):onClick(function() aProgram:injectEvent("char", "w") end):show() + +```` +**parameters:** string event, any parameter, any parameter, any parameter, any parameter, boolean ignorePause
+**returns:** self
+ +## injectEvents +injects a event table into the program manually +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show() +--example will follow + +```` +**parameters:** string event, any parameter, any parameter, any parameter, any parameter, boolean ignorePause
+**returns:** self
+ +## getQueuedEvents +returns a table of all currently queued events (while pause is active incomming events will go into a queueEvents table) as soon as the program gets unpaused +it will inject these events +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show() +mainFrame:addButton("myFirstButton"):setText("inject"):onClick(function() basalt.debug(aProgram:getQueuedEvents()) end):show() + +```` +**parameters:** -
+**returns:** table queuedEvents
+ +## updateQueuedEvents +here you can manipulate the queuedEvents table with your own events table +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show() +--example will follow + +```` +**parameters:** table queuedEvents
+**returns:** self
\ No newline at end of file diff --git a/docs/objects/Radio.md b/docs/objects/Radio.md new file mode 100644 index 0000000..04875b3 --- /dev/null +++ b/docs/objects/Radio.md @@ -0,0 +1,124 @@ +# Radio + +Radios are objects where you can create endless entrys the user can click on a button and it opens a "list" where the user can choose a entry + +Here is a example of how to create a standard radio: + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aRadio = mainFrame:addRadio("myFirstRadio"):show() +```` + +Here are all possible functions available for radios:
+Remember radio inherits from [object](/objects/Object): + +## addItem +Adds a item to the radio + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aRadio = mainFrame:addRadio("myFirstRadio"):show() +aRadio:addItem("1. Entry",3,4) +aRadio:addItem("2. Entry",3,5,colors.yellow) +aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) +```` +**parameters:** string text, number x, number y, number bgcolor, number fgcolor, any ... - (text is the displayed text, bgcolor and fgcolors the colors of background/text and args (...) is something dynamic, you wont see them but if you require some more information per item you can use that)
+**returns:** self
+ +## removeItem +Removes a item from the radio + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aRadio = mainFrame:addRadio("myFirstRadio"):show() +aRadio:addItem("1. Entry",3,4) +aRadio:addItem("2. Entry",3,5,colors.yellow) +aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) +aRadio:removeItem(2) +```` +**parameters:** number index
+**returns:** self
+ +## editItem +Edits a item on the radio + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aRadio = mainFrame:addRadio("myFirstRadio"):show() +aRadio:addItem("1. Entry",3,4) +aRadio:addItem("2. Entry",3,5,colors.yellow) +aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) +aRadio:editItem(3,"3. Edited Entry",3,6,colors.yellow,colors.green) +```` +**parameters:** number index, string text, number x, number y, number bgcolor, number fgcolor, any ...
+**returns:** self
+ +## setScrollable +Makes the radio scrollable + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aRadio = mainFrame:addRadio("myFirstRadio"):show() +aRadio:addItem("1. Entry",3,4) +aRadio:addItem("2. Entry",3,5,colors.yellow) +aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) +aRadio:setScrollable(true) +```` +**parameters:** boolean isScrollable
+**returns:** self
+ +## selectItem +selects a item in the radio (same as a player would click on a item) + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aRadio = mainFrame:addRadio("myFirstRadio"):show() +aRadio:addItem("1. Entry",3,4) +aRadio:addItem("2. Entry",3,5,colors.yellow) +aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) +aRadio:selectItem(1) +```` +**parameters:** number index
+**returns:** self
+ +## clear +clears the entire list (radio) + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aRadio = mainFrame:addRadio("myFirstRadio"):show() +aRadio:addItem("1. Entry",3,4) +aRadio:addItem("2. Entry",3,5,colors.yellow) +aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) +aRadio:clear() +```` +**parameters:** -
+**returns:** self
+ +## getItemIndex +returns the item index of the currently selected item + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aRadio = mainFrame:addRadio("myFirstRadio"):show() +aRadio:addItem("1. Entry",3,4) +aRadio:addItem("2. Entry",3,5,colors.yellow) +aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) +aRadio:getItemIndex() +```` +**parameters:** -
+**returns:** number index
+ +## setSelectedItem +Sets the background of the item which is currently selected + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aRadio = mainFrame:addRadio("myFirstRadio"):show() +aRadio:addItem("1. Entry",3,4) +aRadio:addItem("2. Entry",3,5,colors.yellow) +aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) +aRadio:setSelectedItem(colors.green, colors.blue) +```` +**parameters:** number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)
+**returns:** self
\ No newline at end of file diff --git a/docs/objects/Scrollbar.md b/docs/objects/Scrollbar.md new file mode 100644 index 0000000..14350a4 --- /dev/null +++ b/docs/objects/Scrollbar.md @@ -0,0 +1,53 @@ +# Scrollbar + +Scrollbars are objects, the user can scroll vertically or horizontally, this can change the value.
+Here is a example of how to create a standard scrollbar: + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):show() +```` + +This will create a default label with a size 5 width and 1 height on position 1 1 (relative to its parent frame), the default background is colors.gray, the default text color is colors.black. the default bar type is vertical, the default symbol is " " and the default symbol color is colors.lightGray. The default zIndex is 5. + +Here are all possible functions available for scrollbars. Remember scrollbar inherit from [object](/objects/Object): + +## setSymbol +Changes the symbol + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setSymbol("X"):show() +```` +**parameters:** char symbol
+**returns:** self
+ +## setBackgroundSymbol +Changes the background symbol color + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setSymbol("X"):setBackgroundSymbol(colors.green):show() +```` +**parameters:** number symbolcolor
+**returns:** self
+ +## setBarType +If the bar goes vertically or horizontally + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setBarType("horizontal"):show() +```` +**parameters:** string value ("vertical" or "horizontal")
+**returns:** self
+ +## setMaxValue +the default max value is always the width (if vertical) or height (if horizontal), if you change the max value the bar will always calculate the value based on its width or height - example: you set the max value to 100, the height is 10 and it is a vertical bar, this means if the bar is on top, the value is 10, if the bar goes one below, it is 20 and so on. + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setMaxValue(123):show() +```` +**parameters:** any number
+**returns:** self
\ No newline at end of file diff --git a/docs/objects/Slider.md b/docs/objects/Slider.md new file mode 100644 index 0000000..627f661 --- /dev/null +++ b/docs/objects/Slider.md @@ -0,0 +1,42 @@ +# Slider + +With sliders you can add a object where the user can change a number value.

+ +Here are all possible functions available for sliders:
+Remember slider also inherits from [object](/objects/Object) + +## setSymbol +this will change the foreground symbol +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aSlider = mainFrame:addSlider("myFirstSlider"):setSymbol("X"):show() +```` +**parameters:** char symbol
+**returns:** self
+ +## setBackgroundSymbol +this will change the symbol background color +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aSlider = mainFrame:addSlider("myFirstSlider"):setBackgroundSymbol(colors.yellow):show() +```` +**parameters:** number color
+**returns:** self
+ +## setSymbolColor +this will change the symbol color +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aSlider = mainFrame:addSlider("myFirstSlider"):setSymbolColor(colors.red):show() +```` +**parameters:** number color
+**returns:** self
+ +## setBarType +this will change the bar to vertical/horizontal (default is horizontal) +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aSlider = mainFrame:addSlider("myFirstSlider"):setBarType("vertical"):show() +```` +**parameters:** string value ("vertical", "horizontal"
+**returns:** self
\ No newline at end of file diff --git a/docs/objects/Textfield.md b/docs/objects/Textfield.md new file mode 100644 index 0000000..2819d97 --- /dev/null +++ b/docs/objects/Textfield.md @@ -0,0 +1,74 @@ +# Textfield + +Textfields are objects, where the user can write something on multiple lines. it act's like the default edit script (without coloring)
+Here is a example of how to create a default textfield: + +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() +```` + +This will create a default textfield with the size 10 width and 4 height on position 1 1 (relative to its parent frame), the default background is colors.gray, the default text color is colors.black and the default zIndex is 5. + +A list of all possible functions available for textfields. Remember textfield inherits from [object](/objects/Object): + + +## getLines +returns all lines +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() +basalt.debug(aTextfield:getLines()) +```` +**parameters:** -
+**returns:** table lines
+ +## getLine +returns the line on index position +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() +basalt.debug(aTextfield:getLine(2)) +```` +**parameters:** number index
+**returns:** string line
+ +## editLine +edits line on index position +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() +aTextfield:editLine(2, "hellow") +```` +**parameters:** number index, string text
+**returns:** self
+ +## addLine +adds a line on index position (if index is nil it just adds the line on the bottom) +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() +aTextfield:addLine("hellow") +```` +**parameters:** string text, number index
+**returns:** self
+ +## removeLine +removes the line on index position +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() +aTextfield:removeLine(1) +```` +**parameters:** number index
+**returns:** self
+ +## getTextCursor +returns the cursor position +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() +basalt.debug(aTextfield:getTextCursor()) +```` +**parameters:** -
+**returns:** number x, number y
\ No newline at end of file diff --git a/docs/objects/Thread.md b/docs/objects/Thread.md new file mode 100644 index 0000000..ea38899 --- /dev/null +++ b/docs/objects/Thread.md @@ -0,0 +1,49 @@ +# Thread + +Threads are "functions" you can execute simultaneously. Ofc the reality is, i am just using coroutine for that. But it works pretty good AND is very easy to use. +
+Here is a list of all available functions for threads:
+ +## start +starts a new thread and executes the function +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aThread = mainFrame:addThread("myFirstThread"):show() +local function randomThreadFunction() + while true do + basalt.debug("Thread is active") + os.sleep(1) -- a sleep/coroutine.yield() or pullEvent is required otherwise we will never come back to the main program (error) + end +end +aThread:start(randomThreadfunction) +```` +**parameters:**function func
+**returns:** self
+ +## getStatus +gets the thread status +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aThread = mainFrame:addThread("myFirstThread"):show() +basalt.debug(aThread:getStatus()) -- returns "running", "normal", "suspended" or "dead" +```` +**parameters:** -
+**returns:** string "running" - if its running, "normal" - is active but not running (waiting for a event), "suspended" - is suspended
+ +## stop +stops the thread +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aThread = mainFrame:addThread("myFirstThread"):show() +local function randomThreadFunction() + while true do + basalt.debug("Thread is active") + os.sleep(1) -- a sleep/coroutine.yield() or pullEvent is required otherwise we will never come back to the main program (error) + end +end +aThread:start(randomThreadfunction) +local aButton = mainFrame:addButton("myFirstButton"):setText("Stop Thread"):onClick(function() aThread:stop() end):show() + +```` +**parameters:** -
+**returns:** self
\ No newline at end of file diff --git a/docs/objects/Timer.md b/docs/objects/Timer.md new file mode 100644 index 0000000..4598def --- /dev/null +++ b/docs/objects/Timer.md @@ -0,0 +1,51 @@ +# Timer + +With timers you can call delayed functions. +
+Here is a list of all available functions for timers:
+ +## setTime +sets the time the timer should wait after calling your function +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aTimer = mainFrame:addTimer("myFirstTimer") +aTimer:setTime(5) +```` +**parameters:**number time[, number repeats] - (time in seconds, if repeats is -1 it will call the function infinitly (every x seconds)
+**returns:** self
+ +## start +starts the timer +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aTimer = mainFrame:addTimer("myFirstTimer") +aTimer:setTime(5):start() +```` +**parameters:** -
+**returns:** self
+ +## cancel +stops/cancels the timer +````lua +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aTimer = mainFrame:addTimer("myFirstTimer") +aTimer:setTime(5):start() +aTimer:cancel() +```` +**parameters:** -
+**returns:** self
+ + +## onCall +adds a function to the timer +````lua +local function timerCall(self) + basalt.debug("i got called!") +end +local mainFrame = basalt.createFrame("myFirstFrame"):show() +local aTimer = mainFrame:addTimer("myFirstTimer") +aTimer:setTime(5):onCall(timerCall):start() + +```` +**parameters:** function func
+**returns:** self
\ No newline at end of file diff --git a/docs/tips/buttons.md b/docs/tips/buttons.md new file mode 100644 index 0000000..52fb3b2 --- /dev/null +++ b/docs/tips/buttons.md @@ -0,0 +1,41 @@ +# Changing button colors + +Here i want to explain to you how you would create a button with the default color gray, and as long as the user is clicking on the button it will change its color to black (the default frame-background is lightGray). + +To make this possible the button needs 1 onClick event, 1 onClickUp event and 1 onLoseFocus event. + +Very interesting sidetip: events can hold multiple functions!
+**Example snippet:** +````lua +local function buttonColoring() +-- here you can add some coloring for your button +end +local function buttonLogic() +-- here you can add some logic for your button +end +local button = mainFrame:addButton("ExampleButton"):show() +button:onClick(buttonColoring):onClick(buttonLogic) -- yes this would work, if not its a bug! +```` + +This means you can create a function wich handles only the coloring side of your button, and if your button also needs some logic you just create your own unique function for that and add it to your button. + +With this knowledge we create now a function where we pass a button-object as parameter and this will setup the coloring of our button: + +**Example snippet:** +````lua +local basalt = dofile("basalt.lua") +local mainFrame = basalt.createFrame("mainFrame"):show() +local button = mainFrame:addButton("firstButton"):setPosition(3,3):setSize(12,3):setText("Click me"):setBackground(colors.gray):setForeground(colors.black):show() + +local button2 = mainFrame:addButton("secondButton"):setPosition(25,3):setSize(16,3):setText("Another Btn"):setBackground(colors.gray):setForeground(colors.black):show() + +local function setupButtonColoring(btn) +btn:onClick(function() btn:setBackground(colors.black) btn:setForeground(colors.lightGray) end) +btn:onClickUp(function() btn:setBackground(colors.gray) btn:setForeground(colors.black) end) +btn:onLoseFocus(function() btn:setBackground(colors.gray) btn:setForeground(colors.black) end) +end +setupButtonColoring(button) +setupButtonColoring(button2) + +basalt.autoUpdate() +```` \ No newline at end of file diff --git a/docs/tips/logic.md b/docs/tips/logic.md new file mode 100644 index 0000000..9c44441 --- /dev/null +++ b/docs/tips/logic.md @@ -0,0 +1,57 @@ +# Executing your own logic + +You question yourself how you can execute your own logic while basalt is also active? There are multiple ways of doing that: + +## Number 1: +Using parallel.waitForAll + +````lua +local basalt = dofile("basalt.lua") + +local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame and a button without functionality +mainFrame:addButton("aButton"):onClick(function() end):show() + +local function yourCustomHandler() + while true do + -- add your logic here + os.sleep(1) -- you need something which calls coroutine.yield(), yes os.sleep does that os.pullEvent() aswell + end +end + +parallel.waitForAll(basalt.autoUpdate, yourCustomHandler) -- here it will handle your function (yourCustomHandler) and basalts handlers at the time +```` +You can read [here](http://www.computercraft.info/wiki/Parallel_(API)) what exactly parallel.waitForAll() does + +## Number 2: +Using threads + +````lua +local basalt = dofile("basalt.lua") + +local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a thread +mainFrame:addButton("aButton"):onClick(function() end):show() +local thread = mainFrame:addThread("customHandlerExecutingThread") + +local function yourCustomHandler() + while true do + -- add your logic here + os.sleep(1) -- you need something which calls coroutine.yield(), yes os.sleep does that os.pullEvent() aswell + end +end +thread:start(yourCustomHandler) -- this will create a coroutine and starts the coroutine, os.sleep does the rest, so you just have to call start once. +```` + +## Number 3: +Using timers + +````lua +local basalt = dofile("basalt.lua") + +local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a timer +mainFrame:addButton("aButton"):onClick(function() end):show() +local timer = mainFrame:addTimer("customHandlerExecutingTimer") + +local function yourCustomHandler() + -- add your logic here +end +timer:onCall(yourCustomHandler):setTime(1, -1):start() -- this will call your function every second until you :cancel() the timer \ No newline at end of file