58 Commits

Author SHA1 Message Date
Robert Jelic
797a48ea95 Update Basalt.md 2022-06-25 15:57:14 +02:00
Robert Jelic
ccdebe30ef Update _navbar.md 2022-06-25 15:46:11 +02:00
Robert Jelic
91b16fbd80 Update _navbar.md 2022-06-25 15:33:26 +02:00
Robert Jelic
71e8870c7c Update Frame.md 2022-06-25 15:32:10 +02:00
Robert Jelic
1198a5b4e0 Update Object.md 2022-06-25 15:25:08 +02:00
Robert Jelic
c280f8b9d6 Create progressBarEnergyExample.lua 2022-06-24 22:11:27 +02:00
Robert Jelic
8326d02a33 very small bugfix 2022-06-24 21:59:01 +02:00
Robert Jelic
3799cf9013 Update _sidebar.md 2022-06-24 21:23:15 +02:00
Robert Jelic
ccfc2eecd0 Create Progressbar.md 2022-06-24 21:22:42 +02:00
Robert Jelic
a763990b0c Update Label.md 2022-06-24 20:49:14 +02:00
Robert Jelic
2edff41380 Update Menubar.md 2022-06-24 20:43:50 +02:00
Robert Jelic
1c668ef34b Update Menubar.md 2022-06-24 20:43:11 +02:00
Robert Jelic
226471821f Update otherEvents.md 2022-06-24 20:05:47 +02:00
Robert Jelic
2919803846 Update otherEvents.md 2022-06-24 20:05:13 +02:00
Robert Jelic
1b1b4ae22c Rename KeyEvents.md to keyEvents.md 2022-06-24 19:59:18 +02:00
Robert Jelic
813bf7d2cf Update Object.md 2022-06-24 19:55:41 +02:00
Robert Jelic
39b3d1f732 Update Object.md 2022-06-24 19:54:34 +02:00
Robert Jelic
5253d03c60 Update otherEvents.md 2022-06-24 19:43:30 +02:00
Robert Jelic
02a11d656d Update Object.md 2022-06-24 19:40:02 +02:00
Robert Jelic
72e633ec21 Update basaltPreview.lua 2022-06-24 19:36:22 +02:00
Robert Jelic
df4ad896b2 Some changes
-reworked monitor support
-fixed small draw bugs
-changed focus behaviour
-added some events
-fixed offset bug
-added border
-added shadow
-reworkd anchor system
-added possibility to remove background by setting the value to false
2022-06-24 19:33:37 +02:00
Robert Jelic
94cb23fd58 Rename Key to KeyEvents.md 2022-06-20 23:13:33 +02:00
Robert Jelic
939be0764e Create Key 2022-06-20 23:13:07 +02:00
Robert Jelic
9858bce3f6 Update mouseEvents.md 2022-06-20 23:06:44 +02:00
Robert Jelic
3e937033b9 Update mouseEvents.md 2022-06-20 23:05:33 +02:00
Robert Jelic
989fefe330 Update README.md 2022-06-20 23:00:02 +02:00
Robert Jelic
6b3a7cd73f small monitor/offsetbugfix update
-reworked monitor support (you are able to write on monitors through computer)
-fixed offset bugs
-couple of smaller bugfixes
2022-06-20 21:07:09 +02:00
Samuel Pizette
a899b1d247 updated Object.md to new format 2022-06-09 12:37:33 -04:00
Samuel Pizette
b6ee09636b updated param and return headers 2022-06-09 11:43:59 -04:00
Samuel Pizette
4b8f3c2d5c fixed spacing issue 2022-06-09 11:39:34 -04:00
Samuel Pizette
5a6811930b re-re-added design.md 2022-06-09 11:32:54 -04:00
Samuel Pizette
7759b720b6 added syntax highlighting 2022-06-09 11:19:13 -04:00
Samuel Pizette
64e7d777c1 bad syntax fix #2 2022-06-09 11:09:04 -04:00
Samuel Pizette
332be95285 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	docs/home/gettingStarted.md
#	docs/home/installer.md
#	docs/tips/logic.md
2022-06-09 11:08:46 -04:00
Samuel Pizette
cb98307e44 bad syntax fix 2022-06-09 11:08:26 -04:00
Robert Jelic
eb2dd86ac8 Update installer.md 2022-06-08 19:33:40 +02:00
Robert Jelic
5b9a3bb565 Update index.html 2022-06-08 19:30:58 +02:00
Robert Jelic
b6e2aefb68 fixed crash -> if you dont use :setSize() on sub frames 2022-06-06 21:23:50 +02:00
Robert Jelic
4f3ffc328d added switch 2022-06-06 20:49:30 +02:00
Robert Jelic
c5b9a5f568 Merge branch 'master' of https://github.com/Pyroxenium/Basalt 2022-06-06 17:07:10 +02:00
Robert Jelic
b0b104ee82 couple of bugfixes
-fixed screen flickering
-fixed menubar (now works as intended)
-reworked sliders (behaviour more like scrollbars)
-visual fix to dropdowns
2022-06-06 17:06:56 +02:00
Robert Jelic
e833d4bcf1 Update events.md 2022-06-05 14:44:13 +02:00
Robert Jelic
7b2556bd8c Update mouseEvents.md 2022-06-05 14:42:18 +02:00
Robert Jelic
f2972417a7 Update _sidebar.md 2022-06-05 14:41:36 +02:00
Robert Jelic
2a577fff9f Rename events to events.md 2022-06-05 14:39:09 +02:00
Robert Jelic
cfcdbce8d5 Create events 2022-06-05 14:38:55 +02:00
Robert Jelic
980b016b2c Merge pull request #19 from Erb3/erb3-patch3
[WIKI] rephrasing, link updates, sidebar update
2022-06-04 19:57:52 +02:00
Erlend
1c7f465cd8 Using tweaked.cc instead of deprecated computercraft.info link 2022-06-04 19:29:41 +02:00
Erlend
038bab11ba Remove sidebar listing for something that dosent exist 2022-06-04 19:20:15 +02:00
Erlend
3cfc2fca9c Remove unused file 2022-06-04 19:19:41 +02:00
Erlend
2e11c99ef2 Update Home.md with new links, ++
I updated Home.md with new links to the new repo. I also rephrased some things.
2022-06-04 19:17:32 +02:00
Robert Jelic
98b84a9509 Update installer.md 2022-06-03 21:51:05 +02:00
Robert Jelic
50b0bf6b95 update installer image 2022-06-03 21:49:31 +02:00
Robert Jelic
42450d42d3 Update installer.md 2022-06-03 21:47:51 +02:00
Robert Jelic
e29e5cc77d Merge pull request #18 from Erb3/erb3-patch2
Add favicon to wiki
2022-06-03 20:39:17 +02:00
Erlend
a50ed1f486 Add favicon links in index.html 2022-06-03 20:19:45 +02:00
Erlend
6d66757ae4 Add favicon files 2022-06-03 20:18:51 +02:00
Robert Jelic
e5839c3704 Update mouseEvents.md 2022-06-03 19:20:41 +02:00
70 changed files with 2954 additions and 1596 deletions

View File

@@ -9,12 +9,3 @@ Basalt is still under developement and you may find bugs!
Check out the [wiki](https://basalt.madefor.cc/) for information<br> Check out the [wiki](https://basalt.madefor.cc/) for information<br>
If you have questions, feel free to join the discord server: [https://discord.gg/yM7kndJdJJ](https://discord.gg/yM7kndJdJJ) If you have questions, feel free to join the discord server: [https://discord.gg/yM7kndJdJJ](https://discord.gg/yM7kndJdJJ)
Todo:<br>
- Improve performance<br>
- Fix menubar scroll functionality<br>
- Fix frames moving incorrectly when anchor is bottom/right<br>
- Fix click event and lose focus event order<br>
- Improve event system<br>
- Add info to image and pane object, and onBackgroundKey
- Fix mouse events for frames with a program

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -1,24 +1,24 @@
# Welcome to The Basalt Wiki!<br> # Welcome to The Basalt Wiki!
_Note: The Basalt Wiki is a work in progress. Please treat Wiki errors the same as bugs and report them accordingly._ *Note: The Basalt Wiki is a work in progress. 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. 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.
## About Basalt ## 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 <a href="https://tweaked.cc/">home page</a>. Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (Also know as "ComputerCraft: Tweaked") - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's [wiki](https://tweaked.cc/) or [download](https://www.curseforge.com/minecraft/mc-mods/cc-tweaked).
<br><br>
## Quick Demo ## Quick Demo
![Preview](https://media0.giphy.com/media/fvmNPshXKeU7FFA9iA/giphy.gif) ![Preview](https://media0.giphy.com/media/fvmNPshXKeU7FFA9iA/giphy.gif)
<br><br>
## Questions & Bugs ## Questions & Bugs
Obviously I've implemented some easter eggs, _some people_ call them "bugs". If you happen to discover one of these just make a new <a href="https://github.com/NoryiE/Basalt/issues">issue</a>. Obviously NyoriE has implemented some easter eggs, *some people* call them "bugs". If you happen to discover one of these just make a new <a href="https://github.com/Pyroxenium/Basalt/issues">issue</a>.
Additionally, if you have questions about Basalt or how to make use of it, feel free to create a new discussion on <a href="https://github.com/NoryiE/Basalt/discussions">Basalt's Discussion Board</a>. Additionally, if you have questions about Basalt or how to make use of it, feel free to create a new discussion on <a href="https://github.com/Pyroxenium/Basalt/discussions">Basalt's Discussion Board</a>, or ask in our [discord](https://discord.gg/yNNnmBVBpE).
You may also message me on Discord: NyoriE#8206 ---
Feel free to join our [discord](https://discord.gg/yNNnmBVBpE)!
<br><br> <br><br>

BIN
docs/_media/installer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -1,4 +1,4 @@
- Getting Started - Getting Started
- [Home](Home.md) - [Home](Home.md)
- [Quick Start](home/Quick-Start.md) - [Quick Start](home/Quick-Start.md)
- [Installer](objects/Installer.md) - [Installer](home/installer)

View File

@@ -3,8 +3,8 @@
- [Quick Start](home/Quick-Start.md) - [Quick Start](home/Quick-Start.md)
- [Installer](home/installer) - [Installer](home/installer)
- Objects - Objects
- - [Object](objects/Object)
- [Basalt](objects/Basalt) - [Basalt](objects/Basalt)
- [Object](objects/Object)
- [Button](objects/Button) - [Button](objects/Button)
- [Checkbox](objects/Checkbox) - [Checkbox](objects/Checkbox)
- [Dropdown](objects/Dropdown) - [Dropdown](objects/Dropdown)
@@ -16,6 +16,7 @@
- [Menubar](objects/Menubar) - [Menubar](objects/Menubar)
- [Pane](objects/Pane) - [Pane](objects/Pane)
- [Program](objects/Program) - [Program](objects/Program)
- [Progressbar](objects/Progressbar)
- [Radio](objects/Radio) - [Radio](objects/Radio)
- [Scrollbar](objects/Scrollbar) - [Scrollbar](objects/Scrollbar)
- [Slider](objects/Slider) - [Slider](objects/Slider)
@@ -25,7 +26,10 @@
- [Timer](objects/Timer) - [Timer](objects/Timer)
- Events - Events
- [Mouse Events](events/mouseEvents.md) - [Mouse Events](events/mouseEvents.md)
- [Keyboard Events](events/keyEvents.md)
- [Other Events](events/otherEvents.md)
- Tips & Tricks - Tips & Tricks
- [Component Logic](tips/logic) - [Component Logic](tips/logic)
- [Changing Button Color](tips/buttons) - [Changing Button Color](tips/buttons)
- [Design Tips](tips/design.md) - [Advanced usage of Events](tips/events.md)
- [Example Designs](tips/design.md)

39
docs/events/keyEvents.md Normal file
View File

@@ -0,0 +1,39 @@
Here we will talk about keyboard events and how you can manipulate them. There are 2 possible key events you can add to almost every visual object.
# onKey
`onKey(self, event, key)`<br>
The computercraft event which triggers this method is `key`.
Any visual object can register onKey events.
Here is a example on how to add a onKey event to your frame:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local subFrame = mainFrame:addFrame("subFrame"):setPosition(3,3):setSize(18,6):setBar("Sub Frame",colors.black):showBar():show()
function openSubFrame()
subFrame:show()
end
mainFrame:onKey(openSubFrame)
```
# onKeyUp
`onKeyUp(self, event, key)`<br>
The computercraft event which triggers this method is `key_up`.
Any visual object can register onKeyUp events.
Here is a example on how to add a onKeyUp event to your frame:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local subFrame = mainFrame:addFrame("subFrame"):setPosition(3,3):setSize(18,6):setBar("Sub Frame",colors.black):showBar():show()
function openSubFrame()
subFrame:show()
end
mainFrame:onKeyUp(openSubFrame)
```

View File

@@ -32,12 +32,12 @@ local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show() local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show() local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnClick() function buttonOnClick(self, button, x, y)
basalt.debug("Button got clicked!") basalt.debug("Button got clicked!")
end end
button:onClick(buttonOnClick) button:onClick(buttonOnClick)
function buttonOnRelease() function buttonOnRelease(self, button, x, y)
basalt.debug("Button got released!") basalt.debug("Button got released!")
end end
button:onClickUp(buttonOnRelease) button:onClickUp(buttonOnRelease)
@@ -46,7 +46,7 @@ button:onClickUp(buttonOnRelease)
# onScroll # onScroll
`onScroll(self, direction, x, y)`<br> `onScroll(self, direction, x, y)`<br>
The computercraft event which triggers this method is `mouse_scroll`. The computercraft event which triggers this method is `mouse_scroll`.
Any visual object can register a onScroll events. Any visual object can register onScroll events.
Here is a example on how to add a onScroll event to your button: Here is a example on how to add a onScroll event to your button:
@@ -56,43 +56,27 @@ local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show() local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show() local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnScroll() function buttonOnScroll(self, direction, x, y)
basalt.debug("Someone scrolls on me!") basalt.debug("Someone scrolls on me!")
end end
button:onScroll(buttonOnScroll) button:onScroll(buttonOnScroll)
``` ```
# Beginner Tips # onDrag
`onDrag(self, button, x, y)`<br>
The computercraft event which triggers this method is `mouse_drag`.
Any visual object can register onDrag events.
## 1 Here is a example on how to add a onDrag event to your button:
Not everyone knows that a function (or in other words a method) does not need to have a name. Instead of a function name you are also able to add the function itself as a argument.
Both do the exact same thing:
```lua ```lua
local function clickButton() local basalt = dofile("basalt.lua")
basalt.debug("I got clicked!")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnDrag(self, button, x, y)
basalt.debug("Someone drags me (i know i wont reposition myself)!")
end end
button:onClick(clickButton) button:onDrag(buttonOnDrag)
``` ```
```lua
button:onClick(function()
basalt.debug("I got clicked!")
end)
```
## 2
there is also a function with which you can check if the user is holding a key down, it is called `basalt.isKeyDown()`. It's especially useful for click events.
Let us say you want a button to execute something, but if you are holding ctrl down, something in the execution should get changed. This is how you would
achieve that:
```lua
button:onClick(function()
if(basalt.isKeyDown(keys.LeftCtrl)then
basalt.debug("Ctrl is down!")
else
basalt.debug("Ctrl is up!")
end
end)
```

View File

@@ -0,0 +1,75 @@
There are also other useful events you can listen to:
# onChange
`onChange(self)`<br>
This is a custom event which gets triggered as soon as the function :setValue() is called. This function is also called by basalt, for example if you change the input, textfield or checkbox (or all the different types of lists) objects.
Here is a example on how to add a onChange event to your input, and also another example for your checkbox:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local aInput = mainFrame:addInput("specialInput"):setPosition(3,3):show()
local aCheckbox = mainFrame:addCheckbox("specialCheckbox"):setPosition(3,5):show()
local function checkInput(input)
if(string.lower(input:getValue())=="hello")then
basalt.debug("Hello back!")
end
end
local function checkCheckbox(checkbox)
if(checkbox:getValue()==true)then -- or if(checkbox:getValue())then
basalt.debug("Checkbox is active, let us do something!")
end
end
aInput:onChange(checkInput)
aCheckbox:onChange(checkCheckbox)
```
# onResize
`onResize(self)`<br>
This is a custom event which gets triggered as soon as the parent frame gets resized.
Here is a example on how to add a onResize event to your button:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local aButton = mainFrame:addButton("myButton"):setPosition(3,3):show()
local function onButtonResize(button)
local width = mainFrame:getWidth()
button:setSize()
end
aButton:onResize(onButtonResize)
```
# onLoseFocus
`onLoseFocus(self)`<br>
This event gets triggered as soon as the object loses its focus.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("exampleButton"):setPosition(3,3):onLoseFocus(
function(self)
basalt.debug("Please come back... :(")
end
):show()
```
# onGetFocus
`onGetFocus(self)`<br>
This event gets triggered as soon as the object is the currently focused object.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("exampleButton"):setPosition(3,3):onGetFocus(
function(self)
basalt.debug("Welcome back!")
end
):show()
```

BIN
docs/favicon-16x16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
docs/favicon-32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
docs/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -10,16 +10,16 @@ Just use the following command in any CC:Tweaked shell:
This will download `basalt.lua` to your local directory This will download `basalt.lua` to your local directory
To load the framework, make use of the following snippet To load the framework, make use of the following snippet
````lua ```lua
--> For those who are unfamiliar with lua, dofile executes the code in the referenced file --> For those who are unfamiliar with lua, dofile executes the code in the referenced file
local basalt = dofile("basalt.lua") local basalt = dofile("basalt.lua")
```` ```
Here is a fully functioning example of Basalt code Here is a fully functioning example of Basalt code
````lua ```lua
local basalt = dofile("basalt.lua") --> Load the Basalt framework 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 --> Create the first frame. Please note that Basalt needs at least one active "non-parent" frame to properly supply events
@@ -50,9 +50,9 @@ button:onClick(buttonClick)
button:show() --> Make the button visible, so the user can click it button:show() --> Make the button visible, so the user can click it
basalt.autoUpdate() --> Basalt#autoUpdate starts the event listener to detect user input 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: If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above:
````lua ```lua
local basalt = dofile("basalt.lua") local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show() local mainFrame = basalt.createFrame("mainFrame"):show()
@@ -67,4 +67,4 @@ local button = mainFrame --> Basalt returns an instance of the object on most me
:show() :show()
basalt.autoUpdate() basalt.autoUpdate()
```` ```

View File

@@ -1,71 +0,0 @@
# 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()
````

View File

@@ -4,19 +4,19 @@ This is just a script which helps you to setup your program to automatically ins
## Basic Installer ## Basic Installer
Here is a very basic one which just installs basalt.lua if don't exist: Here is a very basic one which just installs basalt.lua if don't exist:
````lua ```lua
--Basalt configurated installer --Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
if not(fs.exists(filePath))then if not(fs.exists(filePath))then
shell.run("pastebin run ESs1mg7P "..filePath) -- this is an alternative to the wget command shell.run("pastebin run ESs1mg7P "..filePath) -- this is an alternative to the wget command
end end
local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
```` ```
## Advanced Installer ## Advanced Installer
This is a visual version, it asks the user if he wants to install basalt.lua (if not found)<br> This is a visual version, it asks the user if he wants to install basalt.lua (if not found)<br>
![](https://i.imgur.com/b4Ys7FB.png) ![](https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/installer.png)
````lua ```lua
--Basalt configurated installer --Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
if not(fs.exists(filePath))then if not(fs.exists(filePath))then
@@ -51,12 +51,12 @@ if not(fs.exists(filePath))then
local event, p1,p2,p3,p4 = os.pullEvent() local event, p1,p2,p3,p4 = os.pullEvent()
if(event=="mouse_click")then if(event=="mouse_click")then
if(p3==math.floor(h/2+2))and(p2>=w/2-8)and(p2<=w/2-2)then if(p3==math.floor(h/2+2))and(p2>=w/2-8)and(p2<=w/2-2)then
shell.run("pastebin run ESs1mg7P "..filePath) -- this is an alternative to the wget command shell.run("pastebin run ESs1mg7P "..filePath)
_installerWindow.setVisible(false) _installerWindow.setVisible(false)
term.clear() term.clear()
break break
end end
if(p3==h/2+2)and(p2<=w/2+9)and(p2>=w/2+4)then if(p3==math.floor(h/2+2))and(p2<=w/2+9)and(p2>=w/2+4)then
_installerWindow.clear() _installerWindow.clear()
_installerWindow.setVisible(false) _installerWindow.setVisible(false)
term.setCursorPos(1,1) term.setCursorPos(1,1)
@@ -70,4 +70,5 @@ if not(fs.exists(filePath))then
end end
local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
```` ------------------------------
```

View File

@@ -8,6 +8,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<!-- <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">--> <!-- <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple-dark.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple-dark.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.28.0/themes/prism-tomorrow.min.css">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<style> <style>
:root { :root {
--theme-color: #16CC27; --theme-color: #16CC27;
@@ -43,9 +46,9 @@
auto2top: true auto2top: true
} }
</script> </script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-lua.min.js"></script>
<!-- Docsify v4 --> <!-- Docsify v4 -->
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script> <script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
<script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/js/docsify-themeable.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/js/docsify-themeable.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/prismjs@1.28.0/components/prism-lua.min.js"></script>
</body> </body>
</html> </html>

View File

@@ -31,13 +31,13 @@ Sets a wait timer for the next function after the previous function got executed
1. `animation` Animation in use 1. `animation` Animation in use
#### Usage: #### Usage:
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local testButton = mainFrame:addButton("myTestButton"):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) 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() aAnimation:play()
```` ```
## play ## play
Plays the animation Plays the animation
@@ -48,13 +48,13 @@ Plays the animation
1. `animation` Animation in use 1. `animation` Animation in use
#### Usage: #### Usage:
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local testButton = mainFrame:addButton("myTestButton"):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) 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 aAnimation:play() -- changes the background color of that button from black to gray and then to lightGray
```` ```
## cancel ## cancel
Cancels the animation Cancels the animation
@@ -64,10 +64,10 @@ Cancels the animation
#### Usage: #### Usage:
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local testButton = mainFrame:addButton("myTestButton"):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) 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() aAnimation:play()
```` ```

View File

@@ -4,10 +4,10 @@ To start using Basalt you have to do the following line of code:
remember you need the basalt.lua file on your computer! remember you need the basalt.lua file on your computer!
Now you are able to call all these functions: Now you are able to use the following functions:
## basalt.createFrame ## basalt.createFrame
Create a frame without a parent Create a base-frame (main frame)
#### Parameters: #### Parameters:
1. `string` name 1. `string` name
@@ -16,25 +16,25 @@ Create a frame without a parent
#### Usage: #### Usage:
* Create and show a frame with id "myFirstFrame" * Create and show a frame with id "myFirstFrame"
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
```` ```
## basalt.removeFrame ## basalt.removeFrame
Removes a frame (only possible for non-parent frames) Removes a base frame
#### Parameters: #### Parameters:
1. `string` name 1. `string` name
#### Usage: #### Usage:
* Removes the previously created frame with id "myFirstFrame" * Removes the previously created frame with id "myFirstFrame"
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
basalt.removeFrame("myFirstFrame") basalt.removeFrame("myFirstFrame")
```` ```
## basalt.getFrame ## basalt.getFrame
With that function you can get frames, but only frames without a parent! Returns a base frame with the given name
#### Parameters: #### Parameters:
1. `string` name 1. `string` name
@@ -43,81 +43,86 @@ With that function you can get frames, but only frames without a parent!
#### Usage: #### Usage:
* Creates, fetches and shows the "myFirstFrame" object * Creates, fetches and shows the "myFirstFrame" object
````lua ```lua
basalt.createFrame("myFirstFrame") basalt.createFrame("myFirstFrame")
basalt.getFrame("myFirstFrame"):show() basalt.getFrame("myFirstFrame"):show()
```` ```
## basalt.getActiveFrame ## basalt.getActiveFrame
Returns the currently active (without a parent) frame Returns the currently active base frame
#### Returns: #### Returns:
1. `frame` The current frame 1. `frame` The current frame
#### Usage: #### Usage:
* Displays the active frame name in the debug console * Displays the active frame name in the debug console
````lua ```lua
basalt.createFrame("myFirstFrame"):show() basalt.createFrame("myFirstFrame"):show()
basalt.debug(basalt.getActiveFrame():getName()) -- returns myFirstFrame basalt.debug(basalt.getActiveFrame():getName()) -- returns myFirstFrame
```` ```
## basalt.autoUpdate ## basalt.autoUpdate
Starts the draw and event handler until basalt.stopUpdate() is called Starts the draw and event handler until basalt.stopUpdate() is called
#### Usage: #### Usage:
* Enable the basalt updates, otherwise the screen will not continue to update * Enable the basalt updates, otherwise the screen will not continue to update
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
basalt.autoUpdate() basalt.autoUpdate()
```` ```
## basalt.update ## basalt.update
Calls the draw and event handler method once Calls the draw and event handler once - this gives more flexibility about which events basalt should process. For example you could filter the terminate event.
#### Parameters: #### Parameters:
1. `string` The event to be received 1. `string` The event to be received
2. `...` Additional event variables to capture 2. `...` Additional event variables to capture
#### Usage: #### Usage:
* Prints "Left Mouse Button clicked!" when clicked * Creates and starts a custom update cycle
````lua ```lua
quitButton:onClick( local mainFrame = basalt.createFrame("myFirstFrame"):show()
function(obj, event, x, y) local aButton = mainFrame:addButton("myButton"):setPosition(2,2):show()
if(event == "mouse_click") and (button == 1) then --> The button at index 1 is left
basalt.debug("Left Mouse Button clicked!") while true do
end basalt.update(os.pullEventRaw())
end end
) ```
````
## basalt.stopUpdate ## basalt.stopUpdate
Stops the draw and event handler _(including, but not limited to mouse clicks)_ Stops the automatic draw and event handler which got started by basalt.autoUpdate()
#### Usage: #### Usage:
* When the quit button is clicked, the button stops basalt updates and clears the terminal * When the quit button is clicked, the button stops basalt updates and clears the terminal
````lua ```lua
quitButton:onClick( ```lua
function(obj, event) local mainFrame = basalt.createFrame("myFirstFrame"):show()
if (event == "mouse_click") and (obj == quitButton) then --> The button at index 1 is left local aButton = mainFrame:addButton("myButton"):setPosition(2,2):setText("Stop Basalt!"):show()
basalt.stopUpdate()
term.clear() aButton:onClick(function()
end basalt.stopUpdate()
end end)
)
```` basalt.autoUpdate()
```
## basalt.debug ## 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 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
You can also edit the default debug Label (change position, change color or whatever you want) by accessing the variable basalt.debugLabel
which returns the debug Label.
Also basalt.debugFrame and basalt.debugList are available.
#### Parameters: #### Parameters:
1. `...` (multiple parameters are possible, like print does)<br> 1. `...` (multiple parameters are possible, like print does)<br>
#### Usage: #### Usage:
* Prints "Hello! ^-^" to the debug console * Prints "Hello! ^-^" to the debug console
````lua ```lua
basalt.debug("Hello! ^-^") basalt.debug("Hello! ", "^-^")
```` ```

View File

@@ -5,20 +5,20 @@ Remember button also inherits from [Object](objects/Object.md)
## setText ## setText
Sets the displayed button text Sets the displayed button text
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setText("Click"):show() -- you could also use :setValue() instead of :setText() - no difference local aButton = mainFrame:addButton("myFirstButton"):setText("Click"):show() -- you could also use :setValue() instead of :setText() - no difference
```` ```
**Arguments:** string text<br> #### Parameters: string text<br>
**returns:** self<br> #### Returns: self<br>
# Examples # Examples
Add a onClick event: Add a onClick event:
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setText("Click"):onClick(function(self,event,button,x,y) local aButton = mainFrame:addButton("myFirstButton"):setText("Click"):onClick(function(self,event,button,x,y)
if(event=="mouse_click")and(button==1)then if(event=="mouse_click")and(button==1)then
basalt.debug("Left mousebutton got clicked!") basalt.debug("Left mousebutton got clicked!")
end end
end):show() end):show()
```` ```

View File

@@ -5,9 +5,9 @@ Remember button also inherits from [Object](objects/Object.md)
Create a onChange event: Create a onChange event:
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() 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() local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):onChange(function(self) basalt.debug("The value got changed into "..self:getValue()) end):show()
```` ```

View File

@@ -2,10 +2,10 @@ Dropdowns are objects where you can create endless entrys the user can click on
Here is a example of how to create a standard dropdown: Here is a example of how to create a standard dropdown:
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
```` ```
Here are all possible functions available for dropdowns: <br> Here are all possible functions available for dropdowns: <br>
Remember Dropdown also inherits from [Object](objects/Object.md) Remember Dropdown also inherits from [Object](objects/Object.md)
@@ -13,166 +13,166 @@ Remember Dropdown also inherits from [Object](objects/Object.md)
## addItem ## addItem
Adds a item to the dropdown Adds a item to the dropdown
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) 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)<br> #### 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)<br>
**returns:** self<br> #### Returns: self<br>
## removeItem ## removeItem
Removes a item from the dropdown Removes a item from the dropdown
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:removeItem(2) aDropdown:removeItem(2)
```` ```
**parameters:** number index<br> #### Parameters: number index<br>
**returns:** self<br> #### Returns: self<br>
## editItem ## editItem
Edits a item on the dropdown Edits a item on the dropdown
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:editItem(3,"3. Edited 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 ...<br> #### Parameters: number index, string text, number bgcolor, number fgcolor, any ...<br>
**returns:** self<br> #### Returns: self<br>
## setScrollable ## setScrollable
Makes the dropdown scrollable Makes the dropdown scrollable
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:setScrollable(true) aDropdown:setScrollable(true)
```` ```
**parameters:** boolean isScrollable<br> #### Parameters: boolean isScrollable<br>
**returns:** self<br> #### Returns: self<br>
## selectItem ## selectItem
selects a item in the dropdown (same as a player would click on a item) selects a item in the dropdown (same as a player would click on a item)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:selectItem(1) aDropdown:selectItem(1)
```` ```
**parameters:** number index<br> #### Parameters: number index<br>
**returns:** self<br> #### Returns: self<br>
## clear ## clear
clears the entire list (dropdown) clears the entire list (dropdown)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:clear() aDropdown:clear()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** self<br> #### Returns: self<br>
## getItemIndex ## getItemIndex
returns the item index of the currently selected item returns the item index of the currently selected item
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:getItemIndex() aDropdown:getItemIndex()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** number index<br> #### Returns: number index<br>
## setSelectedItem ## setSelectedItem
Sets the background of the item which is currently selected Sets the background of the item which is currently selected
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:setSelectedItem(colors.green, colors.blue) aDropdown:setSelectedItem(colors.green, colors.blue)
```` ```
**parameters:** number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)<br> #### Parameters: number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)<br>
**returns:** self<br> #### Returns: self<br>
## setOffset ## setOffset
sets the dropdown offset (will automatically change if scrolling is active) sets the dropdown offset (will automatically change if scrolling is active)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:setOffset(3) aDropdown:setOffset(3)
```` ```
**parameters:** number offsetValue<br> #### Parameters: number offsetValue<br>
**returns:** self<br> #### Returns: self<br>
## getOffset ## getOffset
returns the current offset returns the current offset
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:getOffset() aDropdown:getOffset()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** number offsetValue<br> #### Returns: number offsetValue<br>
## getOffset ## getOffset
returns the current offset returns the current offset
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:getOffset() aDropdown:getOffset()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** number offsetValue<br> #### Returns: number offsetValue<br>
## setDropdownSize ## setDropdownSize
sets the dropdown size (if you click on the button) sets the dropdown size (if you click on the button)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:setDropdownSize(12, 4) aDropdown:setDropdownSize(12, 4)
```` ```
**parameters:** number width, number height<br> #### Parameters: number width, number height<br>
**returns:** self<br> #### Returns: self<br>

View File

@@ -15,9 +15,9 @@ Creates a new non-parent frame - in most cases it is the first thing you'll need
#### Usage: #### Usage:
* Create a frame with an id "myFirstFrame", stored in a variable named frame * Create a frame with an id "myFirstFrame", stored in a variable named frame
````lua ```lua
local myFrame = basalt.createFrame("myFirstFrame") local myFrame = basalt.createFrame("myFirstFrame")
```` ```
## addFrame ## addFrame
Creates a child frame on the frame, the same as [basalt.createFrame](https://github.com/Pyroxenium/Basalt/wiki/Frame#basaltcreateframe) except the frames are given a parent-child relationship automatically Creates a child frame on the frame, the same as [basalt.createFrame](https://github.com/Pyroxenium/Basalt/wiki/Frame#basaltcreateframe) except the frames are given a parent-child relationship automatically
@@ -30,16 +30,16 @@ Creates a child frame on the frame, the same as [basalt.createFrame](https://git
#### Usage: #### Usage:
* Create a frame with id "myFirstFrame" then create a child of that frame, named "myFirstSubFrame" * Create a frame with id "myFirstFrame" then create a child of that frame, named "myFirstSubFrame"
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame") local mainFrame = basalt.createFrame("myFirstFrame")
local myFrame = mainFrame:addFrame("myFirstSubFrame") local myFrame = mainFrame:addFrame("myFirstSubFrame")
```` ```
## setBar ## setBar
Sets the text, background, and foreground of the upper bar of the frame, accordingly. Sets the text, background, and foreground of the upper bar of the frame, accordingly.
#### Parameters: #### Parameters:
1. `string` The text to set the bar to 1. `string` The title text to set the bar to
2. `number` The background color 2. `number` The background color
2. `number` The foreground color 2. `number` The foreground color
@@ -47,21 +47,22 @@ Sets the text, background, and foreground of the upper bar of the frame, accordi
1. `frame` The frame being used 1. `frame` The frame being used
#### Usage: #### Usage:
* Set the title to "My first frame!", with a background of gray and a foreground of light gray. * Set the title to "My first frame!", with a background of black and a foreground of light gray.
````lua ```lua
frame:setBar("My first Frame!", colors.gray, colors.lightGray) frame:setBar("My first Frame!", colors.black, colors.lightGray)
```` ```
* Store the frame, use the named frame variable after assigning. * Store the frame, use the named frame variable after assigning.
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame") local mainFrame = basalt.createFrame("myFirstFrame"):show()
local myFrame = MainFrame:addFrame("myFirstSubFrame") local myFrame = MainFrame:addFrame("myFirstSubFrame")
myFrame:setBar("My first Frame!") myFrame:setBar("My first Frame!")
```` myFrame:show()
```
* This abuses the call-chaining that Basalt uses. * This abuses the call-chaining that Basalt uses.
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame") local mainFrame = basalt.createFrame("myFirstFrame"):show()
local myFrame = mainFrame:addFrame("myFirstSubFrame"):setBar("My first Frame!") local myFrame = mainFrame:addFrame("myFirstSubFrame"):setBar("My first Frame!"):show()
```` ```
## setBarTextAlign ## setBarTextAlign
Sets the frame's bar-text alignment Sets the frame's bar-text alignment
@@ -74,9 +75,9 @@ Sets the frame's bar-text alignment
#### Usage: #### Usage:
* Set the title of myFrame to "My first frame!", and align it to the right. * Set the title of myFrame to "My first frame!", and align it to the right.
````lua ```lua
local mainFrame = myFrame:setBar("My first Frame!"):setBarTextAlign("right") local mainFrame = myFrame:setBar("My first Frame!"):setBarTextAlign("right")
```` ```
## showBar ## showBar
Toggles the frame's upper bar Toggles the frame's upper bar
@@ -89,75 +90,26 @@ Toggles the frame's upper bar
#### Usage: #### Usage:
* Sets myFrame to have a bar titled "Hello World!" and subsequently displays it. * Sets myFrame to have a bar titled "Hello World!" and subsequently displays it.
````lua ```lua
local mainFrame = myFrame:setBar("Hello World!"):showBar() local mainFrame = myFrame:setBar("Hello World!"):showBar()
```` ```
## addMonitor ## setMonitor
adds a monitor to the active main frame. Sets this frame as a monitor frame
#### Parameters: #### Parameters:
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...) 1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
#### Returns: #### Returns:
1. `frame` returns a frame which you can use like normal frames 1. `frame` The frame being used
#### Usage: #### Usage:
* Adds a monitor to the mainFrame. Only as long as this frame is also the active Frame, the monitor will be shown. * Creates a new monitor frame, you can use to show objects on a monitor.
````lua ```lua
local mainFrame = basalt.createFrame("mainFrame"):show() local mainFrame = basalt.createFrame("mainFrame"):show()
local monitor1 = mainFrame:addMonitor("right"):show() local monitorFrame = basalt.createFrame("mainFrame"):setMonitor("right"):show()
monitorFrame:setBar("Monitor 1"):showBar()
monitor1:setBar("Monitor 1"):showBar() ```
````
## setMonitorScale
changes the monitor scale (almost the same as setTextScale())
#### Parameters:
1. `number` Possible values are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 (1 is the same as 0.5 by setTextScale, and 10 is the same as 5)
#### Returns:
1. `monitor` The monitor being used
#### Usage:
* Changes the monitor scale to 2
````lua
local mainFrame = basalt.createFrame("mainFrame"):show()
local monitor1 = mainFrame:addMonitor("right"):setMonitorScale(2):show()
monitor1:setBar("Monitor 1"):showBar()
````
## ~~isModifierActive~~
### _Disabled, this function is a WIP_
Returns true if the user is currently holding the respective key down
#### Parameters:
1. `number | string` - Any os.queueEvent("key") key, or you can use the following strings: "shift", "ctrl", "alt"
#### Returns:
1. `boolean` - Whether the user is holding the key down
#### Usage:
* Checks if the "shift" modifier is active on the myFrame frame
````lua
local isActive = myFrame:isModifierActive("shift")
````
* Creates a label, changing the text to "Shift is inactive oh no :(" and "Shift is active yay!", accordingly.
````lua
local aLabel = myFrame:addLabel("myFirstLabel"):setText("Shift is inactive oh no :(")
myFrame:addButton("myFirstButton"):setText("Click"):onClick(
function()
if myFrame:isModifierActive("shift") then
aLabel:setText("Shift is active yay!")
else
aLabel:setText("Shift is inactive oh no :(")
end
end
)
````
## getObject ## getObject
Returns a child object of the frame Returns a child object of the frame
@@ -169,10 +121,10 @@ Returns a child object of the frame
#### Usage: #### Usage:
* Adds a button with id "myFirstButton", then retrieves it again through the frame object * Adds a button with id "myFirstButton", then retrieves it again through the frame object
````lua ```lua
myFrame:addButton("myFirstButton") myFrame:addButton("myFirstButton")
local aButton = myFrame:getObject("myFirstButton") local aButton = myFrame:getObject("myFirstButton")
```` ```
## removeObject ## removeObject
Removes a child object from the frame Removes a child object from the frame
@@ -185,10 +137,10 @@ Removes a child object from the frame
#### Usage: #### Usage:
* Adds a button with the id "myFirstButton", then removes it with the aforementioned id * Adds a button with the id "myFirstButton", then removes it with the aforementioned id
````lua ```lua
myFrame:addButton("myFirstButton") myFrame:addButton("myFirstButton")
myFrame:removeObject("myFirstButton") myFrame:removeObject("myFirstButton")
```` ```
## setFocusedObject ## setFocusedObject
Sets the currently focused object Sets the currently focused object
@@ -201,10 +153,10 @@ Sets the currently focused object
#### Usage: #### Usage:
* Creates button with id "myFirstButton", sets the focused object to the previously mentioned button * Creates button with id "myFirstButton", sets the focused object to the previously mentioned button
````lua ```lua
local aButton = myFrame:addButton("myFirstButton") local aButton = myFrame:addButton("myFirstButton")
myFrame:setFocusedObject(aButton) myFrame:setFocusedObject(aButton)
```` ```
## removeFocusedObject ## removeFocusedObject
Removes the focus of the supplied object Removes the focus of the supplied object
@@ -216,10 +168,10 @@ Removes the focus of the supplied object
#### Usage: #### Usage:
* Creates a button with id "myFirstButton", then removes the focus from that button * Creates a button with id "myFirstButton", then removes the focus from that button
````lua ```lua
local aButton = myFrame:addButton("myFirstButton") local aButton = myFrame:addButton("myFirstButton")
myFrame:removeFocusedObject(aButton) myFrame:removeFocusedObject(aButton)
```` ```
## getFocusedObject ## getFocusedObject
Gets the currently focused object Gets the currently focused object
@@ -228,9 +180,9 @@ Gets the currently focused object
#### Usage: #### Usage:
* Gets the currently focused object from the frame, storing it in a variable * Gets the currently focused object from the frame, storing it in a variable
````lua ```lua
local focusedObject = myFrame:getFocusedObject() local focusedObject = myFrame:getFocusedObject()
```` ```
## setMovable ## setMovable
Sets whether the frame can be moved. _In order to move the frame click and drag the upper bar of the frame_ Sets whether the frame can be moved. _In order to move the frame click and drag the upper bar of the frame_
@@ -242,28 +194,12 @@ Sets whether the frame can be moved. _In order to move the frame click and drag
#### Usage: #### Usage:
* Creates a frame with id "myFirstFrame" and makes it movable * Creates a frame with id "myFirstFrame" and makes it movable
````lua ```lua
local myFrame = basalt.createFrame("myFirstFrame"):setMovable(true) local myFrame = basalt.createFrame("myFirstFrame"):setMovable(true)
```` ```
## ~~setMoveable~~
### _Deprecated in favor of setMovable_
Sets whether the frame can be moved. _In order to move the frame use the upper bar of the frame_
#### Parameters:
1. `boolean` Whether the object is movable
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a frame with id "myFirstFrame" and makes it movable
````lua
local myFrame = basalt.createFrame("myFirstFrame"):setMoveable(true)
````
## setOffset ## setOffset
Sets the frame's coordinate offset. The frame's child objects will receive the frame's coordinate offset. For example, when using the scrollbar, if you use its value to add an offset to a frame, you will get a scrollable frame. Sets the frame's coordinate offset. The frame's child objects will receive the frame's coordinate offset. For example, when using a scrollbar, if you use its value to add an offset to a frame, you will get a scrollable frame.
Objects are also able to ignore the offset by using :ignoreOffset() (For example, you may want to ignore the offset on the scrollbar itself) Objects are also able to ignore the offset by using :ignoreOffset() (For example, you may want to ignore the offset on the scrollbar itself)
The function can be supplied negative offsets The function can be supplied negative offsets
@@ -277,10 +213,10 @@ The function can be supplied negative offsets
#### Usage: #### Usage:
* Creates "myFirstFrame" with an x offset of 5 and a y offset of 3 * Creates "myFirstFrame" with an x offset of 5 and a y offset of 3
````lua ```lua
local myFrame = basalt.createFrame("myFirstFrame"):setOffset(5, 3) local myFrame = basalt.createFrame("myFirstFrame"):setOffset(5, 3)
```` ```
* Creates "myFirstFrame" with an x offset of 5 and a y offset of -5 (Meaning if you added a button with y position 5, it would be at y position 0) * Creates "myFirstFrame" with an x offset of 5 and a y offset of -5 (Meaning if you added a button with y position 5, it would be at y position 0)
````lua ```lua
local myFrame = basalt.createFrame("myFirstFrame"):setOffset(5, -5) local myFrame = basalt.createFrame("myFirstFrame"):setOffset(5, -5)
```` ```

View File

@@ -7,30 +7,30 @@ Remember Image inherits from [Object](objects/Object.md)
## loadImage ## loadImage
loads a image into the memory. loads a image into the memory.
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aImage = mainFrame:addImage("myFirstImage"):loadImage("randomImage.nfp"):show() local aImage = mainFrame:addImage("myFirstImage"):loadImage("randomImage.nfp"):show()
```` ```
**Arguments:** string path<br> #### Parameters: string path<br>
**returns:** self<br> #### Returns: self<br>
## loadBlittleImage -- not finished yet ## loadBlittleImage -- not finished yet
loads a blittle image into the memory. loads a blittle image into the memory.
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aImage = mainFrame:addImage("myFirstImage"):loadBlittleImage("blittleImage.blt"):show() local aImage = mainFrame:addImage("myFirstImage"):loadBlittleImage("blittleImage.blt"):show()
```` ```
**Arguments:** string path<br> #### Parameters: string path<br>
**returns:** self<br> #### Returns: self<br>
## shrink ## shrink
If you were loading a normal (paint) image into the memory, this function would shrink it to a 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) blittle image and immediatly draws it (if it's visible)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aImage = mainFrame:addImage("myFirstImage"):loadBlittleImage("randomImage.nfp"):shrink():show() local aImage = mainFrame:addImage("myFirstImage"):loadBlittleImage("randomImage.nfp"):shrink():show()
```` ```
**Arguments:** -<br> #### Parameters: -<br>
**returns:** self<br> #### Returns: self<br>

View File

@@ -5,9 +5,9 @@ Remember Input inherits from [Object](objects/Object.md)
## setInputType ## setInputType
changes the input type changes the input type
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aInput = mainFrame:addInput("myFirstInput"):setInputType("password"):show() local aInput = mainFrame:addInput("myFirstInput"):setInputType("password"):show()
```` ```
**parameters:** string value ("text", "password", "number")<br> #### Parameters: string value ("text", "password", "number")<br>
**returns:** self<br> #### Returns: self<br>

View File

@@ -3,7 +3,7 @@ This is just a script which helps you to install basalt.lua, if it's not already
## Visual Installer ## Visual Installer
This is a visual version, it asks the user if he wants to install basalt.lua (if not found)<br> This is a visual version, it asks the user if he wants to install basalt.lua (if not found)<br>
![](https://i.imgur.com/b4Ys7FB.png) ![](https://i.imgur.com/b4Ys7FB.png)
````lua ```lua
--Basalt configurated installer --Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
if not(fs.exists(filePath))then if not(fs.exists(filePath))then
@@ -58,11 +58,11 @@ end
local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
------------------------------ ------------------------------
```` ```
## Basic Installer ## Basic Installer
Here is a very basic one which just installs basalt.lua if don't exist: Here is a very basic one which just installs basalt.lua if don't exist:
````lua ```lua
--Basalt configurated installer --Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
if not(fs.exists(filePath))then if not(fs.exists(filePath))then
@@ -70,4 +70,4 @@ shell.run("pastebin run ESs1mg7P")
end end
local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
```` ```

View File

@@ -7,28 +7,29 @@ Remember Label inherits from [Object](objects/Object.md)
## setText ## setText
sets the text which gets displayed. sets the text which gets displayed.
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aInput = mainFrame:addLabel("myFirstLabel"):setText("Hello lovely basalt community!"):show() local aInput = mainFrame:addLabel("myFirstLabel"):setText("Hello lovely basalt community!"):show()
```` ```
**arguments:** string text<br> #### Parameters: string text<br>
**returns:** self<br> #### Returns: self<br>
## setFontSize ## setFontSize
sets the font size of that text. sets the font size of that text.
````lua The font size is handled by bigfonts, if you're curious what bigfonts is, check out this page: http://www.computercraft.info/forums2/index.php?/topic/25367-bigfont-api-write-bigger-letters-v10/
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aInput = mainFrame:addLabel("myFirstLabel"):setText("Hello"):setFontSize(2):show() local aInput = mainFrame:addLabel("myFirstLabel"):setText("Hello"):setFontSize(2):show()
```` ```
**arguments:** number size (1 = default, 2 = big, 3 = bigger, 4 = huge)<br> #### Parameters: number size (1 = default, 2 = big, 3 = bigger, 4 = huge)<br>
**returns:** self<br> #### Returns: self<br>
## getFontSize ## getFontSize
returns the fontsize returns the fontsize
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aInput = mainFrame:addLabel("myFirstLabel"):setText("Hello"):setFontSize(2):show() local aInput = mainFrame:addLabel("myFirstLabel"):setText("Hello"):setFontSize(2):show()
basalt.debug(aInput:getFontSize()) -- returns 2 basalt.debug(aInput:getFontSize()) -- returns 2
```` ```
**arguments:** <br> #### Parameters: <br>
**returns:** number<br> #### Returns: number<br>

View File

@@ -2,10 +2,10 @@ Lists are objects where you can create endless entrys and the user can choose on
Here is a example of how to create a standard list: Here is a example of how to create a standard list:
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):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 ">" 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 ">"
@@ -14,138 +14,138 @@ Here are all possible functions available for lists. Remember List inherits from
## addItem ## addItem
Adds a item into the list Adds a item into the list
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show() local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry") aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow) aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green) 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)<br> #### 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)<br>
**returns:** self<br> #### Returns: self<br>
## removeItem ## removeItem
Removes a item from the list Removes a item from the list
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show() local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry") aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow) aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green) aList:addItem("3. Entry",colors.yellow,colors.green)
aList:removeItem(2) aList:removeItem(2)
```` ```
**parameters:** number index<br> #### Parameters: number index<br>
**returns:** self<br> #### Returns: self<br>
## editItem ## editItem
Edits a item on the list Edits a item on the list
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show() local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry") aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow) aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green) aList:addItem("3. Entry",colors.yellow,colors.green)
aList:editItem(3,"3. Edited 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 ...<br> #### Parameters: number index, string text, number bgcolor, number fgcolor, any ...<br>
**returns:** self<br> #### Returns: self<br>
## setScrollable ## setScrollable
Makes the list scrollable Makes the list scrollable
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show() local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry") aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow) aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green) aList:addItem("3. Entry",colors.yellow,colors.green)
aList:setScrollable(true) aList:setScrollable(true)
```` ```
**parameters:** boolean isScrollable<br> #### Parameters: boolean isScrollable<br>
**returns:** self<br> #### Returns: self<br>
## selectItem ## selectItem
selects a item in the list (same as a player would click on a item) selects a item in the list (same as a player would click on a item)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show() local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry") aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow) aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green) aList:addItem("3. Entry",colors.yellow,colors.green)
aList:selectItem(1) aList:selectItem(1)
```` ```
**parameters:** number index<br> #### Parameters: number index<br>
**returns:** self<br> #### Returns: self<br>
## clear ## clear
clears the entire list clears the entire list
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:clear() aDropdown:clear()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** self<br> #### Returns: self<br>
## getItemIndex ## getItemIndex
returns the item index of the currently selected item returns the item index of the currently selected item
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show() local aDropdown = mainFrame:addDropdown("myFirstDropdown"):show()
aDropdown:addItem("1. Entry") aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow) aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green) aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:getItemIndex() aDropdown:getItemIndex()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** number index<br> #### Returns: number index<br>
## setSelectedItem ## setSelectedItem
Sets the background of the item which is currently selected Sets the background of the item which is currently selected
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show() local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry") aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow) aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green) aList:addItem("3. Entry",colors.yellow,colors.green)
aList:setSelectedItem(colors.green, colors.blue) aList:setSelectedItem(colors.green, colors.blue)
```` ```
**parameters:** number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)<br> #### Parameters: number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)<br>
**returns:** self<br> #### Returns: self<br>
## setOffset ## setOffset
sets the list offset (will automatically change if scrolling is active) sets the list offset (will automatically change if scrolling is active)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show() local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry") aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow) aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green) aList:addItem("3. Entry",colors.yellow,colors.green)
aList:setOffset(3) aList:setOffset(3)
```` ```
**parameters:** number offsetValue<br> #### Parameters: number offsetValue<br>
**returns:** self<br> #### Returns: self<br>
## getOffset ## getOffset
returns the current offset returns the current offset
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aList = mainFrame:addList("myFirstList"):show() local aList = mainFrame:addList("myFirstList"):show()
aList:addItem("1. Entry") aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow) aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green) aList:addItem("3. Entry",colors.yellow,colors.green)
aList:getOffset() aList:getOffset()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** number offsetValue<br> #### Returns: number offsetValue<br>

View File

@@ -1 +1,296 @@
WIP Menubars are like lists but instead of being vertical, they are horizontal. Imagine you are creating a Operating System and you would like to add a taskbar, menubars would be exactly what you need, because they are also scrollable, which means they have endless entry possibility.
If you want to access values inside items this is how the table for single items is made (just a example):
```lua
item = {
text="1. Entry",
bgCol=colors.black,
fgCol=colors.white
args = {}
}
```
Here are all possible functions available for menubars. Remember menubar inherits from [Object](objects/Object.md)
## addItem
Adds a item into the menubar
#### Parameters:
1. `string` The entry name
2. `number|color` unique default background color
3. `number|color` unique default text color
4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()).
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default menubar with 3 entries
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
```
## removeItem
Removes a item from the menubar
#### Parameters:
1. `number` The index which should get removed
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default menubar with 3 entries and removes the second one.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:removeItem(2)
```
## editItem
Edits item from the menubar
#### Parameters:
1. `number` The index which should be edited
2. `string` The new item name
3. `number` the new item background color
4. `number` The new item text color
5. `any` New additional information
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default menubar with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:editItem(2, "Still 2. Entry", colors.red)
```
## getItem
Returns a item by index
#### Parameters:
1. `number` The index which should be returned
#### Returns:
1. `table` The item table example: {text="1. Entry", bgCol=colors.black, fgCol=colors.white}
#### Usage:
* Creates a default menubar with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:editItem(2, "Still 2. Entry", colors.red)
```
## getItemCount
Returns the current item count
#### Returns:
1. `number` The item list count
#### Usage:
* Creates a default menubar with 3 entries and prints the current item count.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aMenubar:getItemCount())
```
## getAll
Returns all items as table
#### Returns:
1. `table` All items
#### Usage:
* Creates a default menubar with 3 entries and prints a table.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aMenubar:getAll())
```
## setSpace
Sets the space between entries
#### Parameters:
1. `number` The space between each entry
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default menubar with 3 entries and changes the space to 3.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:setSpace(3)
```
## setScrollable
Makes the menubar scrollable. The menubar will be scrollable as soon as the menubar is to small for all the entries.
#### Parameters:
1. `boolean` if this menubar should be scrollable or not
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default menubar with 3 entries and makes it scrollable.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:setScrollable(true)
```
## selectItem
selects a item in the list (same as a player would click on a item)
#### Parameters:
1. `number` The index which should get selected
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default menubar with 3 entries and selects the second entry.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:selectItem(2)
```
## clear
Removes all items.
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default menubar with 3 entries and removes them immediatley. Which makes no sense.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:clear()
```
## getItemIndex
returns the item index of the currently selected item
#### Returns:
1. `number` The current index
#### Usage:
* Creates a default menubar with 3 entries selects the second entry and prints the currently selected index.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:selectItem(2)
basalt.debug(aMenubar:getItemIndex())
```
## setSelectedItem
Sets the background and the foreground of the item which is currently selected
#### Parameters:
1. `number|color` The background color which should be used
2. `number|color` The text color which should be used
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default menubar with 4 entries and sets the selection background color to green.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry")
aMenubar:addItem("3. Entry")
aMenubar:addItem("4. Entry")
aMenubar:setSelectedItem(colors.green)
```
## setPositionOffset
Sets the offset of the menubar (the same as you would scroll) - default is 0
#### Parameters:
1. `number` The offset value
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default menubar with 6 entries and sets the offset to 3.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry")
aMenubar:addItem("3. Entry")
aMenubar:addItem("4. Entry")
aMenubar:addItem("5. Entry")
aMenubar:addItem("6. Entry")
aMenubar:setPositionOffset(3)
```
## getPositionOffset
returns the current offset
#### Returns:
1. `number` Current offset
#### Usage:
* Creates a default menubar with 6 entries and sets the offset to 3.
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aMenubar = mainFrame:addMenubar("myFirstMenubar"):show()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry")
aMenubar:addItem("3. Entry")
aMenubar:addItem("4. Entry")
aMenubar:addItem("5. Entry")
aMenubar:addItem("6. Entry")
aMenubar:setPositionOffset(3)
basalt.debug(aMenubar:getPositionOffset())
```

View File

@@ -1,247 +1,382 @@
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: 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 methods apply:
## show ## show
shows the object (only if the parent frame is already visible) Shows the object (only if the parent frame is already visible)
````lua #### Returns:
1. `object` The object in use
#### Usage:
* Shows a frame named "myFirstFrame"
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local button = mainFrame:addButton("myFirstButton") local button = mainFrame:addButton("myFirstButton")
button:show() button:show()
```` ```
**parameters:** -<br>
**returns:** self<br>
## hide ## hide
hides the object Hides the object
````lua
#### Returns:
1. `object` The object in use
#### Usage:
* Hides a frame named "myFirstFrame"
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local button = mainFrame:addButton("myFirstButton"):setText("Close"):onClick(function() mainFrame:hide() end) local button = mainFrame:addButton("myFirstButton"):setText("Close"):onClick(function() mainFrame:hide() end)
button:show() button:show()
```` ```
**parameters:** -<br>
**returns:** self<br>
## setPosition ## setPosition
Changes the position relative to its parent frame Changes the position relative to its parent frame
````lua #### Parameters:
local mainFrame = basalt.createFrame("myFirstFrame"):setPosition(2,3) 1. `number` x coordinate
```` 2. `number` y coordinate
**parameters:** number x, number y[, boolean relative], if relative is set to true it will add/remove instead of set x, y<br> 3. `boolean` Whether it will add/remove to the current coordinates instead of setting them
**returns:** self<br>
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the Buttons position to an x coordinate of 2 with a y coordinate of 3
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
mainFrame:addButton("myFirstButton"):setPosition(2,3)
```
## setBackground ## setBackground
Changes the object background color Changes the object background color, if you set the value to false the background wont be visible. For example you could see trough a frame.
````lua #### Parameters:
local mainFrame = basalt.createFrame("myFirstFrame"):setBackground(colors.lightGray) 1. `number|color` Background color
````
**parameters:** number color<br> #### Returns:
**returns:** self<br> 1. `object` The object in use
#### Usage:
* Creates a frame, and sets its background color to `colors.gray`
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):setBackground(colors.gray)
```
## setForeground ## setForeground
Changes the object text color Changes the object text color
````lua #### Parameters:
local mainFrame = basalt.createFrame("myFirstFrame"):setForeground(colors.black) 1. `number|color` Foreground color
````
**parameters:** number color<br> #### Returns:
**returns:** self<br> 1. `object` The object in use
#### Usage:
* Creates a frame, and sets its foreground color to `colors.green`
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):setForeground(colors.green)
```
## setSize ## setSize
Changes the object size Changes the object size
````lua #### Parameters:
local mainFrame = basalt.createFrame("myFirstFrame"):setSize(15,5) 1. `number` width
```` 2. `number` height
**parameters:** number width, number length<br>
**returns:** self<br> #### Returns:
1. `object` The object in use
#### Usage:
* Sets the frame to have a width of 15 and a height of 12
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local subFrame = mainFrame:addFrame("myFirstSubFrame"):setSize(15,12):show()
```
## setFocus ## setFocus
sets the object to be the focused object. 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 If you click on an object, it's normally automatically the focused object. For example, if you call :show() on a frame, and you want this particular frame to be in
the foreground, you have to use :setFocus() the foreground, you should also use :setFocus()
````lua #### Returns:
1. `object` The object in use
#### Usage:
* Sets the button to the focused object
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setFocus():show() local aButton = mainFrame:addButton("myFirstButton"):setFocus():show()
```` ```
**parameters:** -<br>
**returns:** self<br>
## setZIndex ## 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. Sets the z-index. Higher value means higher draw/event priority. You can also add multiple objects to the same z-index, if so the last added object will have the highest priority.
````lua #### Parameters:
1. `number` z-index
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the z-index of "myFirstButton" to `1` and the z-index of "myFirstLabel" to `1`
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setZIndex(1):show() local aButton = mainFrame:addButton("myFirstButton"):setZIndex(1):setPosition(2,2):show()
```` local aLabel = mainFrame:addButton("myFirstLabel"):setZIndex(2):setPosition(2,2):setText("I am a label!"):show()
**parameters:** number index<br> ```
**returns:** self<br>
## setParent ## setParent
changes the frame parent of that object Sets the parent frame of the object
````lua #### Parameters:
1. `frame` The to-be parent frame
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the parent frame of the random frame, adding it to the main frame when the button is clicked"
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aRandomFrame = basalt.createFrame("aRandomFrame"):show() local aRandomFrame = basalt.createFrame("aRandomFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):onClick(function() aRandomFrame:setParent(mainFrame) end):show() local aButton = mainFrame:addButton("myFirstButton"):onClick(
```` function()
**parameters:** frame object<br> aRandomFrame:setParent(mainFrame)
**returns:** self<br> end
):show()
```
## isFocused ## isFocused
returns if the object is currently the focused object of the parent frame Returns if the object is currently the focused object of the parent frame
````lua #### Returns:
1. `boolean` Whether the object is focused
#### Usage:
* Prints whether the button is focused to the debug console
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):show() local aButton = mainFrame:addButton("myFirstButton"):show()
basalt.debug(aButton:isFocused()) -- shows true or false as a debug message basalt.debug(aButton:isFocused()) -- shows true or false as a debug message
```` ```
**parameters:** -<br>
**returns:** boolean<br>
## getAnchorPosition ## getAnchorPosition
converts the x,y coordinates into the anchor coordinates of that object Converts the x and y coordinates into the anchor coordinates of the object
````lua #### Parameters:
1. `number|nil` x
2. `number|nil` y, if nothing it uses the object's x, y
#### Returns:
1. `number` x
2. `number` y
#### Usage:
* Prints the anchor position to the debug console
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):setSize(15,15):show() local mainFrame = basalt.createFrame("myFirstFrame"):setSize(15,15):show()
local aButton = mainFrame:addButton("myFirstButton"):setAnchor("right","bottom"):setSize(8,1):setPosition(1,1):show() local aButton = mainFrame:addButton("myFirstButton")
:setAnchor("bottomRight")
:setSize(8,1)
:setPosition(1,1)
:show()
basalt.debug(aButton:getAnchorPosition()) -- returns 7,14 (framesize - own size) instead of 1,1 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)<br>
**returns:** number x, number y (converted)<br>
## setAnchor ## setAnchor
sets the anchor of that object Sets the anchor of the object
````lua #### Parameters:
local mainFrame = basalt.createFrame("myFirstFrame"):setAnchor("right"):show() 1. `string` Anchor sides `("topLeft" "top", "topRight", "right", "bottomRight", "bottom", "bottomLeft", "left", "center")`
local aButton = mainFrame:addButton("myFirstButton"):setAnchor("bottom","right"):setSize(8,1):setPosition(1,1):show()
```` #### Returns:
**parameters:** string sides - ("left", "right", "top", "bottom") you can stack positions like so ..:setAnchor("right", "bottom")<br> 1. `object` The object in use
**returns:** self<br>
#### Usage:
* Sets the button to have an anchor of `bottomRight`
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton")
:setAnchor("bottomRight")
:setSize(8,1)
:setPosition(-8,1)
:show()
```
## getAbsolutePosition ## getAbsolutePosition
converts the relative coordinates into absolute coordinates Converts the relative coordinates into absolute coordinates
````lua #### Parameters:
1. `number|nil` x
2. `number|nil` y
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a frame and a button and prints the button's absolute position to the debug console
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):setPosition(3,3):show() local mainFrame = basalt.createFrame("myFirstFrame"):setPosition(3,3):show()
local aButton = mainFrame:addButton("myFirstButton"):setSize(8,1):setPosition(4,2):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 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)<br>
**returns:** self<br>
## setTextAlign ## setTextAlign
sets the text align of the object (for example buttons) Sets the text align of the object (for example buttons)
````lua #### Parameters:
1. `string` horizontal
2. `string` vertical ("left", "center", "right")
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a button with text aligned to `right, center`
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setSize(12,3):setTextAlign("right", "center"):setText("Dont't..."):show() local aButton = mainFrame:addButton("myFirstButton")
```` :setSize(12,3)
**parameters:** string horizontal, string vertical - ("left", "center", "right")<br> :setTextAlign("right", "center")
**returns:** self<br> :setText("Don't...")
:show()
```
## setValue ## setValue
sets the value of that object (input, label, checkbox, textfield, scrollbar,...) Sets the value of that object (input, label, checkbox, textfield, scrollbar,...)
````lua #### Parameters:
1. `any` Value to set the object to
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a checkbox and ticks it
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):setValue(true):show() local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):setValue(true):show()
```` ```
**parameters:** any value<br>
**returns:** self<br>
## getValue ## getValue
returns the currently saved value Returns the currently saved value
````lua #### Returns:
1. `any` Object's value
#### Usage:
* Prints the value of the checkbox to the debug console
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):setValue(true):show() local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):setValue(true):show()
basalt.debug(aCheckbox:getValue()) -- returns true basalt.debug(aCheckbox:getValue()) -- returns true
```` ```
**parameters:**-<br>
**returns:** any value<br>
## getHeight/getWidth ## getHeight/getWidth
returns the height or width Returns the respective height/width of the object
````lua #### Returns:
1. `number` height/width
#### Usage:
* Prints the height of the object to the debug console
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setSize(5,8):show() local aButton = mainFrame:addButton("myFirstButton"):setSize(5,8):show()
basalt.debug(aButton:getHeight()) -- returns 8 basalt.debug(aButton:getHeight()) -- returns 8
```` ```
**parameters:**-<br>
**returns:** number height/width<br>
## isVisible ## isVisible
returns if the object is currently visible Returns if the object is currently visible
````lua #### Returns:
1. `boolean`
#### Usage:
* Prints boolean visibility of object to debug console
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setSize(5,8):show() local aButton = mainFrame:addButton("myFirstButton"):setSize(5,8):show()
basalt.debug(aButton:isVisible()) -- returns true basalt.debug(aButton:isVisible()) -- returns true
```` ```
**parameters:**-<br>
**returns:** boolean<br>
## getName ## getName
returns the given name of that object Returns the given name of the object
````lua
#### Returns:
1. `string` name
#### Usage:
* Prints name of object to debug window
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
basalt.debug(mainFrame:getName()) -- returns myFirstFrame basalt.debug(mainFrame:getName()) -- returns myFirstFrame
```` ```
**parameters:**-<br>
**returns:** string name<br>
# Object Events ## setShadow
These object events are available for all objects, if a object got some unique events, you can see them in their own category Sets the shadow color - default: colors.black
## onClick #### Parameters:
creates a mouse_click event 1. `number|color` Shadow color
````lua
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the shadow to green and shows it:
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() 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() local subFrame = mainFrame:addFrame("mySubFrame")
```` :setMoveable()
**parameters:** function func<br> :setSize(18,6)
**returns:** self<br> :setShadow(colors.green)
:showShadow(true)
:show()
```
## onClickUp ## showShadow
creates a click_up event Shows or hides the shadow
````lua
#### Parameters:
1. `boolean` Whether it should show or hide the shadow
#### Returns:
1. `object` The object in use
#### Usage:
* Shows the shadow:
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() 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() local subFrame = mainFrame:addFrame("mySubFrame")
```` :setMoveable()
**parameters:** function func<br> :setSize(18,6)
**returns:** self<br> :showShadow(true)
:show()
```
## onMouseDrag ## setBorder
creates a mouse_drag event Sets the border color - default: colors.black
````lua
#### Parameters:
1. `number|color` Border color
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the border to green and shows it:
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() 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() local subFrame = mainFrame:addFrame("mySubFrame")
```` :setMoveable()
**parameters:** function func<br> :setSize(18,6)
**returns:** self<br> :setBorder(colors.green)
:showBorder("left", "top", "right", "bottom")
:show()
```
## onChange ## showBorder
creates a change event (fires as soon as the value gets changed) Shows or hides the border
````lua
#### Parameters:
1. `strings` Whether it should show or hide the border on the specific sides ("left", "top", "right", "bottom")
#### Returns:
1. `object` The object in use
#### Usage:
* Shows the border:
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):onChange(function(self) basalt.debug("i got changed into "..self:getValue()) end):show() local subFrame = mainFrame:addFrame("mySubFrame")
```` :setMoveable()
**parameters:** function func<br> :setSize(18,6)
**returns:** self<br> :showBorder("left", "top", "right", "bottom")
:show()
## 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<br>
**returns:** self<br>
## 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<br>
**returns:** self<br>
## onGetFocus
creates a get focus event
````lua
local mainFrame = basalt.createFrame("myFirstFrame"):onGetFocus(function(self) basalt.debug("thanks!") end):show()
````
**parameters:** function func<br>
**returns:** self<br>

View File

@@ -7,10 +7,10 @@ Pane doesn't have any custom functionallity. If you want to change the color/pos
## Example: ## Example:
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aPane = mainFrame:addPane("myFirstBackground") local aPane = mainFrame:addPane("myFirstBackground")
aPane:setSize(30, 10) aPane:setSize(30, 10)
aPane:setBackground(colors.yellow) aPane:setBackground(colors.yellow)
aPane:show() aPane:show()
```` ```

View File

@@ -5,99 +5,99 @@ Remember Program inherits from [Object](objects/Object.md)
## getStatus ## getStatus
returns the current status returns the current status
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgram = mainFrame:addProgram("myFirstProgram"):show() local aProgram = mainFrame:addProgram("myFirstProgram"):show()
basalt.debug(aProgram:getStatus()) -- returns "running", "normal", "suspended" or "dead" basalt.debug(aProgram:getStatus()) -- returns "running", "normal", "suspended" or "dead"
```` ```
**parameters:**-<br> #### Parameters:-<br>
**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<br> #### 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<br>
## execute ## execute
executes the given path (-program) executes the given path (-program)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgram = mainFrame:addProgram("myFirstProgram"):show() local aProgram = mainFrame:addProgram("myFirstProgram"):show()
aProgram:execute("rom/programs/fun/worm.lua") -- executes worm aProgram:execute("rom/programs/fun/worm.lua") -- executes worm
```` ```
**parameters:** string filepath - (the path to the program you want to execute)<br> #### Parameters: string filepath - (the path to the program you want to execute)<br>
**returns:** self<br> #### Returns: self<br>
## stop ## 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 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 ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show() local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show()
mainFrame:addButton("myFirstButton"):setText("close"):onClick(function() aProgram:stop() end):show() mainFrame:addButton("myFirstButton"):setText("close"):onClick(function() aProgram:stop() end):show()
```` ```
**parameters:**-<br> #### Parameters:-<br>
**returns:** self<br> #### Returns: self<br>
## pause ## pause
pauses the program (prevents the program from receiving events) pauses the program (prevents the program from receiving events)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show() local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show()
mainFrame:addButton("myFirstButton"):setText("close"):onClick(function() aProgram:pause(true) end):show() mainFrame:addButton("myFirstButton"):setText("close"):onClick(function() aProgram:pause(true) end):show()
```` ```
**parameters:** boolean pause<br> #### Parameters: boolean pause<br>
**returns:** self<br> #### Returns: self<br>
## isPaused ## isPaused
returns if the program is currently paused returns if the program is currently paused
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):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() mainFrame:addButton("myFirstButton"):setText("pause"):onClick(function() basalt.debug(aProgram:isPaused()) end):show()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** boolean isPaused<br> #### Returns: boolean isPaused<br>
## injectEvent ## injectEvent
injects a event into the program manually injects a event into the program manually
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):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() 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<br> #### Parameters: string event, any parameter, any parameter, any parameter, any parameter, boolean ignorePause<br>
**returns:** self<br> #### Returns: self<br>
## injectEvents ## injectEvents
injects a event table into the program manually injects a event table into the program manually
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show() local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show()
--example will follow --example will follow
```` ```
**parameters:** string event, any parameter, any parameter, any parameter, any parameter, boolean ignorePause<br> #### Parameters: string event, any parameter, any parameter, any parameter, any parameter, boolean ignorePause<br>
**returns:** self<br> #### Returns: self<br>
## getQueuedEvents ## 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 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 it will inject these events
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):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() mainFrame:addButton("myFirstButton"):setText("inject"):onClick(function() basalt.debug(aProgram:getQueuedEvents()) end):show()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** table queuedEvents<br> #### Returns: table queuedEvents<br>
## updateQueuedEvents ## updateQueuedEvents
here you can manipulate the queuedEvents table with your own events table here you can manipulate the queuedEvents table with your own events table
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show() local aProgram = mainFrame:addProgram("myFirstProgram"):execute("rom/programs/shell.lua"):show()
--example will follow --example will follow
```` ```
**parameters:** table queuedEvents<br> #### Parameters: table queuedEvents<br>
**returns:** self<br> #### Returns: self<br>

110
docs/objects/Progressbar.md Normal file
View File

@@ -0,0 +1,110 @@
Progressbars are objects to visually display the current state of your progression. They always go from 0 to 100 (%) - no matter how big they are. which means if you
want to add some energy progress you have to do simple maths: currentValue / maxValue * 100
Here are all possible functions available for progessbars. Remember progressbar inherits from [Object](objects/Object.md)
## setDirection
Sets the direction in which the bar should be expanding.
#### Parameters:
1. `number` x direction (0 = left to right, 1 = top to bottom, 2 = right to left and 3 = bottom to top)
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a progressbar and sets the direction from bottom to top
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show()
aProgressbar:setDirection(3)
```
## setProgress
This is the function you need to call if you want the progression to change.
#### Parameters:
1. `number` a number from 0 to 100
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a progressbar and sets the current progress to 50
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show()
aProgressbar:setProgress(50)
```
## getProgress
Returns the current progress status
#### Returns:
1. `number` progress (0-100)
#### Usage:
* Creates a progressbar, sets the current progress to 50 and prints the current progress
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show()
aProgressbar:setProgress(50)
basalt.debug(aProgressbar:getProgress())
```
## setProgressBar
This function will change the visual display of your progress bar
#### Parameters:
1. `number|color` the expanding progress bar color
2. `char` optional - the bar symbol - default is " " (space)
3. `number|color` optional - the bar symbol color
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a progressbar and sets the progressbar color to green
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show()
aProgressbar:setProgressBar(colors.green)
```
## setBackgroundSymbol
Will change the default background symbol (default is " " - space)
#### Parameters:
1. `char` the background symbol
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a progressbar and sets the progressbar background symbol to X
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show()
aProgressbar:setBackgroundSymbol("X")
```
# Events
# onProgressDone
`onProgressDone(self)`<br>
A custom event which gets triggered as soon as the progress reaches 100.
Here is a example on how to add a onProgressDone event to your progressbar:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local aProgressbar = mainFrame:addProgressbar("myFirstProgressbar"):show()
function progressDone()
basalt.debug("The Progressbar reached 100%!")
end
aProgressbar:onProgressDone(progressDone)
```

View File

@@ -2,10 +2,10 @@ Radios are objects where you can create endless entrys the user can click on a b
Here is an example of how to create a standard radio: Here is an example of how to create a standard radio:
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aRadio = mainFrame:addRadio("myFirstRadio"):show() local aRadio = mainFrame:addRadio("myFirstRadio"):show()
```` ```
Here are all possible functions available for radios: <br> Here are all possible functions available for radios: <br>
Remember Radio inherits from [Object](objects/Object.md) Remember Radio inherits from [Object](objects/Object.md)
@@ -13,110 +13,110 @@ Remember Radio inherits from [Object](objects/Object.md)
## addItem ## addItem
Adds a item to the radio Adds a item to the radio
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aRadio = mainFrame:addRadio("myFirstRadio"):show() local aRadio = mainFrame:addRadio("myFirstRadio"):show()
aRadio:addItem("1. Entry",3,4) aRadio:addItem("1. Entry",3,4)
aRadio:addItem("2. Entry",3,5,colors.yellow) aRadio:addItem("2. Entry",3,5,colors.yellow)
aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) 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)<br> #### 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)<br>
**returns:** self<br> #### Returns: self<br>
## removeItem ## removeItem
Removes a item from the radio Removes a item from the radio
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aRadio = mainFrame:addRadio("myFirstRadio"):show() local aRadio = mainFrame:addRadio("myFirstRadio"):show()
aRadio:addItem("1. Entry",3,4) aRadio:addItem("1. Entry",3,4)
aRadio:addItem("2. Entry",3,5,colors.yellow) aRadio:addItem("2. Entry",3,5,colors.yellow)
aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
aRadio:removeItem(2) aRadio:removeItem(2)
```` ```
**parameters:** number index<br> #### Parameters: number index<br>
**returns:** self<br> #### Returns: self<br>
## editItem ## editItem
Edits a item on the radio Edits a item on the radio
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aRadio = mainFrame:addRadio("myFirstRadio"):show() local aRadio = mainFrame:addRadio("myFirstRadio"):show()
aRadio:addItem("1. Entry",3,4) aRadio:addItem("1. Entry",3,4)
aRadio:addItem("2. Entry",3,5,colors.yellow) aRadio:addItem("2. Entry",3,5,colors.yellow)
aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
aRadio:editItem(3,"3. Edited 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 ...<br> #### Parameters: number index, string text, number x, number y, number bgcolor, number fgcolor, any ...<br>
**returns:** self<br> #### Returns: self<br>
## setScrollable ## setScrollable
Makes the radio scrollable Makes the radio scrollable
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aRadio = mainFrame:addRadio("myFirstRadio"):show() local aRadio = mainFrame:addRadio("myFirstRadio"):show()
aRadio:addItem("1. Entry",3,4) aRadio:addItem("1. Entry",3,4)
aRadio:addItem("2. Entry",3,5,colors.yellow) aRadio:addItem("2. Entry",3,5,colors.yellow)
aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
aRadio:setScrollable(true) aRadio:setScrollable(true)
```` ```
**parameters:** boolean isScrollable<br> #### Parameters: boolean isScrollable<br>
**returns:** self<br> #### Returns: self<br>
## selectItem ## selectItem
selects a item in the radio (same as a player would click on a item) selects a item in the radio (same as a player would click on a item)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aRadio = mainFrame:addRadio("myFirstRadio"):show() local aRadio = mainFrame:addRadio("myFirstRadio"):show()
aRadio:addItem("1. Entry",3,4) aRadio:addItem("1. Entry",3,4)
aRadio:addItem("2. Entry",3,5,colors.yellow) aRadio:addItem("2. Entry",3,5,colors.yellow)
aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
aRadio:selectItem(1) aRadio:selectItem(1)
```` ```
**parameters:** number index<br> #### Parameters: number index<br>
**returns:** self<br> #### Returns: self<br>
## clear ## clear
clears the entire list (radio) clears the entire list (radio)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aRadio = mainFrame:addRadio("myFirstRadio"):show() local aRadio = mainFrame:addRadio("myFirstRadio"):show()
aRadio:addItem("1. Entry",3,4) aRadio:addItem("1. Entry",3,4)
aRadio:addItem("2. Entry",3,5,colors.yellow) aRadio:addItem("2. Entry",3,5,colors.yellow)
aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
aRadio:clear() aRadio:clear()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** self<br> #### Returns: self<br>
## getItemIndex ## getItemIndex
returns the item index of the currently selected item returns the item index of the currently selected item
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aRadio = mainFrame:addRadio("myFirstRadio"):show() local aRadio = mainFrame:addRadio("myFirstRadio"):show()
aRadio:addItem("1. Entry",3,4) aRadio:addItem("1. Entry",3,4)
aRadio:addItem("2. Entry",3,5,colors.yellow) aRadio:addItem("2. Entry",3,5,colors.yellow)
aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
aRadio:getItemIndex() aRadio:getItemIndex()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** number index<br> #### Returns: number index<br>
## setSelectedItem ## setSelectedItem
Sets the background of the item which is currently selected Sets the background of the item which is currently selected
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aRadio = mainFrame:addRadio("myFirstRadio"):show() local aRadio = mainFrame:addRadio("myFirstRadio"):show()
aRadio:addItem("1. Entry",3,4) aRadio:addItem("1. Entry",3,4)
aRadio:addItem("2. Entry",3,5,colors.yellow) aRadio:addItem("2. Entry",3,5,colors.yellow)
aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green) aRadio:addItem("3. Entry",3,6,colors.yellow,colors.green)
aRadio:setSelectedItem(colors.green, colors.blue) aRadio:setSelectedItem(colors.green, colors.blue)
```` ```
**parameters:** number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)<br> #### Parameters: number bgcolor, number fgcolor, boolean isActive (isActive means if different colors for selected item should be used)<br>
**returns:** self<br> #### Returns: self<br>

View File

@@ -1,48 +1,48 @@
Scrollbars are objects, the user can scroll vertically or horizontally, this can change the value.<br> Scrollbars are objects, the user can scroll vertically or horizontally, this can change the value.<br>
Here is a example of how to create a standard scrollbar: Here is a example of how to create a standard scrollbar:
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):show() local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):show()
```` ```
Here are all possible functions available for scrollbars. Remember Scrollbar inherits from [Object](objects/Object.md) Here are all possible functions available for scrollbars. Remember Scrollbar inherits from [Object](objects/Object.md)
## setSymbol ## setSymbol
Changes the symbol Changes the symbol
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setSymbol("X"):show() local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setSymbol("X"):show()
```` ```
**parameters:** char symbol<br> #### Parameters: char symbol<br>
**returns:** self<br> #### Returns: self<br>
## setBackgroundSymbol ## setBackgroundSymbol
Changes the background symbol color Changes the background symbol color
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setSymbol("X"):setBackgroundSymbol(colors.green):show() local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setSymbol("X"):setBackgroundSymbol(colors.green):show()
```` ```
**parameters:** number symbolcolor<br> #### Parameters: number symbolcolor<br>
**returns:** self<br> #### Returns: self<br>
## setBarType ## setBarType
If the bar goes vertically or horizontally If the bar goes vertically or horizontally
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setBarType("horizontal"):show() local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setBarType("horizontal"):show()
```` ```
**parameters:** string value ("vertical" or "horizontal")<br> #### Parameters: string value ("vertical" or "horizontal")<br>
**returns:** self<br> #### Returns: self<br>
## setMaxValue ## setMaxValue
the default max value is always the width (if horizontal) or height (if vertical), 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. the default max value is always the width (if horizontal) or height (if vertical), 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 ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setMaxValue(123):show() local aScrollbar = mainFrame:addScrollbar("myFirstScrollbar"):setMaxValue(123):show()
```` ```
**parameters:** any number<br> #### Parameters: any number<br>
**returns:** self<br> #### Returns: self<br>

View File

@@ -5,38 +5,38 @@ Remember slider also inherits from [object](https://github.com/NoryiE/Basalt/wik
## setSymbol ## setSymbol
this will change the foreground symbol this will change the foreground symbol
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aSlider = mainFrame:addSlider("myFirstSlider"):setSymbol("X"):show() local aSlider = mainFrame:addSlider("myFirstSlider"):setSymbol("X"):show()
```` ```
**parameters:** char symbol<br> #### Parameters: char symbol<br>
**returns:** self<br> #### Returns: self<br>
## setBackgroundSymbol ## setBackgroundSymbol
this will change the symbol background color this will change the symbol background color
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aSlider = mainFrame:addSlider("myFirstSlider"):setBackgroundSymbol(colors.yellow):show() local aSlider = mainFrame:addSlider("myFirstSlider"):setBackgroundSymbol(colors.yellow):show()
```` ```
**parameters:** number color<br> #### Parameters: number color<br>
**returns:** self<br> #### Returns: self<br>
## setSymbolColor ## setSymbolColor
this will change the symbol color this will change the symbol color
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aSlider = mainFrame:addSlider("myFirstSlider"):setSymbolColor(colors.red):show() local aSlider = mainFrame:addSlider("myFirstSlider"):setSymbolColor(colors.red):show()
```` ```
**parameters:** number color<br> #### Parameters: number color<br>
**returns:** self<br> #### Returns: self<br>
## setBarType ## setBarType
this will change the bar to vertical/horizontal (default is horizontal) this will change the bar to vertical/horizontal (default is horizontal)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aSlider = mainFrame:addSlider("myFirstSlider"):setBarType("vertical"):show() local aSlider = mainFrame:addSlider("myFirstSlider"):setBarType("vertical"):show()
```` ```
**parameters:** string value ("vertical", "horizontal"<br> #### Parameters: string value ("vertical", "horizontal"<br>
**returns:** self<br> #### Returns: self<br>

View File

@@ -1,10 +1,10 @@
Textfields are objects, where the user can write something on multiple lines. it act's like the default edit script (without coloring)<br> Textfields are objects, where the user can write something on multiple lines. it act's like the default edit script (without coloring)<br>
Here is a example of how to create a default textfield: Here is a example of how to create a default textfield:
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):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. 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.
@@ -13,60 +13,60 @@ A list of all possible functions available for textfields. Remember Textfield in
## getLines ## getLines
returns all lines returns all lines
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show()
basalt.debug(aTextfield:getLines()) basalt.debug(aTextfield:getLines())
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** table lines<br> #### Returns: table lines<br>
## getLine ## getLine
returns the line on index position returns the line on index position
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show()
basalt.debug(aTextfield:getLine(2)) basalt.debug(aTextfield:getLine(2))
```` ```
**parameters:** number index<br> #### Parameters: number index<br>
**returns:** string line<br> #### Returns: string line<br>
## editLine ## editLine
edits line on index position edits line on index position
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show()
aTextfield:editLine(2, "hellow") aTextfield:editLine(2, "hellow")
```` ```
**parameters:** number index, string text<br> #### Parameters: number index, string text<br>
**returns:** self<br> #### Returns: self<br>
## addLine ## addLine
adds a line on index position (if index is nil it just adds the line on the bottom) adds a line on index position (if index is nil it just adds the line on the bottom)
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show()
aTextfield:addLine("hellow") aTextfield:addLine("hellow")
```` ```
**parameters:** string text, number index<br> #### Parameters: string text, number index<br>
**returns:** self<br> #### Returns: self<br>
## removeLine ## removeLine
removes the line on index position removes the line on index position
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show()
aTextfield:removeLine(1) aTextfield:removeLine(1)
```` ```
**parameters:** number index<br> #### Parameters: number index<br>
**returns:** self<br> #### Returns: self<br>
## getTextCursor ## getTextCursor
returns the cursor position returns the cursor position
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show() local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show()
basalt.debug(aTextfield:getTextCursor()) basalt.debug(aTextfield:getTextCursor())
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** number x, number y<br> #### Returns: number x, number y<br>

View File

@@ -4,7 +4,7 @@ Here is a list of all available functions for threads: <br>
## start ## start
starts a new thread and executes the function starts a new thread and executes the function
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aThread = mainFrame:addThread("myFirstThread"):show() local aThread = mainFrame:addThread("myFirstThread"):show()
local function randomThreadFunction() local function randomThreadFunction()
@@ -14,23 +14,23 @@ local function randomThreadFunction()
end end
end end
aThread:start(randomThreadfunction) aThread:start(randomThreadfunction)
```` ```
**parameters:**function func<br> #### Parameters:function func<br>
**returns:** self<br> #### Returns: self<br>
## getStatus ## getStatus
gets the thread status gets the thread status
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aThread = mainFrame:addThread("myFirstThread"):show() local aThread = mainFrame:addThread("myFirstThread"):show()
basalt.debug(aThread:getStatus()) -- returns "running", "normal", "suspended" or "dead" basalt.debug(aThread:getStatus()) -- returns "running", "normal", "suspended" or "dead"
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** string "running" - if its running, "normal" - is active but not running (waiting for a event), "suspended" - is suspended<br> #### Returns: string "running" - if its running, "normal" - is active but not running (waiting for a event), "suspended" - is suspended<br>
## stop ## stop
stops the thread stops the thread
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aThread = mainFrame:addThread("myFirstThread"):show() local aThread = mainFrame:addThread("myFirstThread"):show()
local function randomThreadFunction() local function randomThreadFunction()
@@ -42,6 +42,6 @@ end
aThread:start(randomThreadfunction) aThread:start(randomThreadfunction)
local aButton = mainFrame:addButton("myFirstButton"):setText("Stop Thread"):onClick(function() aThread:stop() end):show() local aButton = mainFrame:addButton("myFirstButton"):setText("Stop Thread"):onClick(function() aThread:stop() end):show()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** self<br> #### Returns: self<br>

View File

@@ -4,39 +4,39 @@ Here is a list of all available functions for timers: <br>
## setTime ## setTime
sets the time the timer should wait after calling your function sets the time the timer should wait after calling your function
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTimer = mainFrame:addTimer("myFirstTimer") local aTimer = mainFrame:addTimer("myFirstTimer")
aTimer:setTime(5) aTimer:setTime(5)
```` ```
**parameters:**number time[, number repeats] - (time in seconds, if repeats is -1 it will call the function infinitly (every x seconds)<br> #### Parameters:number time[, number repeats] - (time in seconds, if repeats is -1 it will call the function infinitly (every x seconds)<br>
**returns:** self<br> #### Returns: self<br>
## start ## start
starts the timer starts the timer
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTimer = mainFrame:addTimer("myFirstTimer") local aTimer = mainFrame:addTimer("myFirstTimer")
aTimer:setTime(5):start() aTimer:setTime(5):start()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** self<br> #### Returns: self<br>
## cancel ## cancel
stops/cancels the timer stops/cancels the timer
````lua ```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show() local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTimer = mainFrame:addTimer("myFirstTimer") local aTimer = mainFrame:addTimer("myFirstTimer")
aTimer:setTime(5):start() aTimer:setTime(5):start()
aTimer:cancel() aTimer:cancel()
```` ```
**parameters:** -<br> #### Parameters: -<br>
**returns:** self<br> #### Returns: self<br>
## onCall ## onCall
adds a function to the timer adds a function to the timer
````lua ```lua
local function timerCall(self) local function timerCall(self)
basalt.debug("i got called!") basalt.debug("i got called!")
end end
@@ -44,6 +44,6 @@ local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTimer = mainFrame:addTimer("myFirstTimer") local aTimer = mainFrame:addTimer("myFirstTimer")
aTimer:setTime(5):onCall(timerCall):start() aTimer:setTime(5):onCall(timerCall):start()
```` ```
**parameters:** function func<br> #### Parameters: function func<br>
**returns:** self<br> #### Returns: self<br>

View File

@@ -4,7 +4,7 @@ To make this possible the button needs 1 onClick event, 1 onClickUp event and 1
Very interesting sidetip: events can hold multiple functions!<br> Very interesting sidetip: events can hold multiple functions!<br>
**Example snippet:** **Example snippet:**
````lua ```lua
local function buttonColoring() local function buttonColoring()
-- here you can add some coloring for your button -- here you can add some coloring for your button
end end
@@ -13,14 +13,14 @@ local function buttonLogic()
end end
local button = mainFrame:addButton("ExampleButton"):show() local button = mainFrame:addButton("ExampleButton"):show()
button:onClick(buttonColoring):onClick(buttonLogic) -- yes this would work, if not its a bug! 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. 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: 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:** **Example snippet:**
````lua ```lua
local basalt = dofile("basalt.lua") local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show() 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 button = mainFrame:addButton("firstButton"):setPosition(3,3):setSize(12,3):setText("Click me"):setBackground(colors.gray):setForeground(colors.black):show()
@@ -36,6 +36,6 @@ setupButtonColoring(button)
setupButtonColoring(button2) setupButtonColoring(button2)
basalt.autoUpdate() basalt.autoUpdate()
```` ```
Now you've got a function which sets your buttons up. Now you've got a function which sets your buttons up.

54
docs/tips/design.md Normal file
View File

@@ -0,0 +1,54 @@
Hello! This page contains some tips on how to create cool designs with Basalt
To understand this page, it is recommended to familiarize yourself with [Animations](../objects/Animation.md) as animations are important for creating complex designs
Let us begin with simple things:
## Recolor objects
Let's create a Button:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myFirstFrame"):setBackground(colors.black):show()
local aButton = mainFrame:addButton("myFirstButton"):setSize(10, 3):setText("Beautiful"):setBackground(colors.gray):show()
```
Here lets make use of the event system:<br>
```lua
local function changeButtonColor(self,event,typ,x,y)
if(event=="mouse_click")then
self:setBackground(colors.lightGray)
end
if(event=="mouse_up")then
self:setBackground(colors.gray)
end
end
local function buttonLogic()
-- here you can do some logic when button gets the mouse_up event
end
aButton:onClick(changeButtonColor) -- button color change on click
aButton:onClickUp(changeButtonColor) -- button color change on click up
aButton:onClickUp(buttonLogic) -- button logic on click up
aButton:onLoseFocus(function(self) self:setBackground(colors.gray) end) -- if user is clicking on the button and dragging out of button size this event will change the bg color back to gray
```
## Fade In/Out Objects
instead of recoloring we are also able to slowly reposition the button, something like fade in:<br>
```lua
local buttonAnimation = mainFrame:addAnimation("buttonFadeAnim")
local function fadeButtonIn(btn)
if(btn.x < 5)then
btn:setPosition(1,0,"r")
else
buttonAnimation:cancel() -- here you cancel the loop
end
end
buttonAnimation:wait(0.1):add(function() fadeButtonIn(aButton) end):play(true) -- with play(true) you will create a infinite loop
```
This is also possible with entire frames and its children objects. So keep that in mind if you want to create something like a bigger panel to the right or a menu bar
WIP

34
docs/tips/events.md Normal file
View File

@@ -0,0 +1,34 @@
## Short way of adding functions to events
Not everyone knows that a function (or in other words a method) does not need to have a name. Instead of a function name you are also able to add the function itself as a argument.
Both do the exact same thing:
```lua
local function clickButton()
basalt.debug("I got clicked!")
end
button:onClick(clickButton)
```
```lua
button:onClick(function()
basalt.debug("I got clicked!")
end)
```
## Using isKeyDown for shortcuts
there is also a function with which you can check if the user is holding a key down, it is called `basalt.isKeyDown()`. It's especially useful for click events.
Let us say you want a button to execute something, but if you are holding ctrl down, something in the execution should get changed. This is how you would
achieve that:
```lua
button:onClick(function()
if(basalt.isKeyDown(keys.leftCtrl)then
basalt.debug("Ctrl is down!")
else
basalt.debug("Ctrl is up!")
end
end)
```
Make sure to always use the available `keys` table: https://computercraft.info/wiki/Keys_(API)

View File

@@ -3,7 +3,7 @@ You question yourself how you can execute your own logic while basalt is also ac
## Method 1: ## Method 1:
Using parallel.waitForAll Using parallel.waitForAll
````lua ```lua
local basalt = dofile("basalt.lua") local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame and a button without functionality local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame and a button without functionality
@@ -17,13 +17,13 @@ local function yourCustomHandler()
end end
parallel.waitForAll(basalt.autoUpdate, yourCustomHandler) -- here it will handle your function (yourCustomHandler) and basalts handlers at the time 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 You can read [here (tweaked.cc)](https://tweaked.cc/module/parallel.html) what exactly parallel.waitForAll() does
## Method 2: ## Method 2:
Using threads Using threads
````lua ```lua
local basalt = dofile("basalt.lua") local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a thread local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a thread
@@ -37,12 +37,12 @@ local function yourCustomHandler()
end end
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. 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.
```` ```
## Method 3: ## Method 3:
Using timers Using timers
````lua ```lua
local basalt = dofile("basalt.lua") local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a timer local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a timer
@@ -53,4 +53,4 @@ local function yourCustomHandler()
-- add your logic here -- add your logic here
end end
timer:onCall(yourCustomHandler):setTime(1, -1):start() -- this will call your function every second until you :cancel() the timer timer:onCall(yourCustomHandler):setTime(1, -1):start() -- this will call your function every second until you :cancel() the timer
```` ```

View File

@@ -1,9 +1,9 @@
--Basalt configurated installer --Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
if not(fs.exists(filePath))then if not(fs.exists(filePath))then
shell.run("wget https://raw.githubusercontent.com/Pyroxenium/Basalt/master/basalt.lua "..filePath) shell.run("pastebin run ESs1mg7P "..filePath) -- this is an alternative to the wget command
end end
local basalt = dofile("basalt.lua") -- here you can change the variablename in any variablename you want default: basalt local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
local w, h = term.getSize() local w, h = term.getSize()
@@ -54,8 +54,8 @@ objFrame:addLabel("radio1Label"):setPosition(37,10):setText("Radio 1"):show()
objFrame:addLabel("radio2Label"):setPosition(37,12):setText("Radio 2"):show() objFrame:addLabel("radio2Label"):setPosition(37,12):setText("Radio 2"):show()
objFrame:addLabel("radio3Label"):setPosition(37,14):setText("Radio 3"):show() objFrame:addLabel("radio3Label"):setPosition(37,14):setText("Radio 3"):show()
objFrame:addScrollbar("exampleScrollbar"):setPosition(objFrame:getWidth(),1):setMaxValue(objFrame:getHeight()):setSize(1,objFrame:getHeight()):setSymbolSize(3):ignoreOffset():onChange(function(self) objFrame:setOffset(0, (self:getValue()-1)) end):setAnchor("right"):show():setZIndex(15) objFrame:addScrollbar("exampleScrollbar"):setPosition(objFrame:getWidth(),1):setMaxValue(objFrame:getHeight()):setSize(1,objFrame:getHeight()):setSymbolSize(3):ignoreOffset():onChange(function(self) objFrame:setOffset(0, (self:getValue()-1)) end):setAnchor("topRight"):show():setZIndex(15)
local prog = objFrame:addProgressbar("exampleProgressbar"):setAnchor("bottom"):setSize(30, 3):setBackground(colors.gray):setPosition(2,3):onProgressDone(function() local prog = objFrame:addProgressbar("exampleProgressbar"):setAnchor("bottomLeft"):setSize(30, 3):setBackground(colors.gray):setPosition(2,3):onProgressDone(function()
basalt.debug("Progress done!") basalt.debug("Progress done!")
end):show() end):show()

View File

@@ -0,0 +1,52 @@
-- This is a example on how to use progressbars for energy. I used the Mekanism Ultimate Energy Cube.
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
if not(fs.exists(filePath))then
shell.run("pastebin run ESs1mg7P "..filePath) -- this is an alternative to the wget command
end
local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
local energyCube = peripheral.find("ultimateEnergyCube")
local main = basalt.createFrame("main"):show()
local progressText = main:addLabel("currentEnergyValue")
:setText(0)
:setForeground(colors.gray)
:setBackground(false)
:setPosition(10, 3)
:setZIndex(6)
:show()
local energyProgress = main:addProgressbar("mainEnergyCube")
:setSize(20,3)
:setPosition(2,2)
:setBackground(colors.black)
:setProgressBar(colors.green)
:show()
energyProgress:onChange(function()
local energy = tostring(energyCube.getEnergy())
progressText:setText(energy)
progressText:setPosition(energyProgress:getWidth()/2+1 - math.floor(energy:len()/2), 3)
end)
local function checkCurrentEnergy()
while true do
energyCube = peripheral.find("ultimateEnergyCube")
if(energyCube~=nil)then
local energyCalculation = energyCube.getEnergy() / energyCube.getMaxEnergy() * 100
energyProgress:setProgress(energyCalculation)
else
energyProgress:setProgress(0)
os.sleep(3)
end
os.sleep(1)
end
end
main:addThread("energyThread"):start(checkCurrentEnergy)
basalt.autoUpdate()

File diff suppressed because one or more lines are too long

View File

@@ -5,11 +5,13 @@ local function Frame(name, parent)
local objects = {} local objects = {}
local objZIndex = {} local objZIndex = {}
local object = {} local object = {}
local focusedObject
local termObject = parentTerminal local termObject = parentTerminal
local monitors = {} local monSide = ""
local isMonitor = false local isMonitor = false
local monitorAttached = false
local dragXOffset = 0
local dragYOffset = 0
base:setZIndex(10) base:setZIndex(10)
@@ -24,7 +26,7 @@ local function Frame(name, parent)
if (parent ~= nil) then if (parent ~= nil) then
base.parent = parent base.parent = parent
base.width, base.height = parent.w, parent.h base.width, base.height = parent:getSize()
base.bgColor = theme.FrameBG base.bgColor = theme.FrameBG
base.fgColor = theme.FrameFG base.fgColor = theme.FrameFG
else else
@@ -97,14 +99,25 @@ local function Frame(name, parent)
end; end;
setFocusedObject = function(self, obj) setFocusedObject = function(self, obj)
if (focusedObject ~= nil) then
focusedObject:loseFocusHandler()
focusedObject = nil
end
if(obj~=nil)then
focusedObject = obj
obj:getFocusHandler()
end
return self
end;
setSize = function(self, w, h)
base.setSize(self, w, h)
for _, index in pairs(objZIndex) do for _, index in pairs(objZIndex) do
for _, value in pairs(objects[index]) do if (objects[index] ~= nil) then
if (value == obj) then for _, value in pairs(objects[index]) do
if (focusedObject ~= nil) then if (value.eventHandler ~= nil) then
focusedObject:loseFocusHandler() value:sendEvent("basalt_resize", value, self)
end end
focusedObject = obj
focusedObject:getFocusHandler()
end end
end end
end end
@@ -117,7 +130,7 @@ local function Frame(name, parent)
return self return self
end; end;
getFrameOffset = function(self) getFrameOffset = function(self) -- internal
return xOffset, yOffset return xOffset, yOffset
end; end;
@@ -133,25 +146,22 @@ local function Frame(name, parent)
return focusedObject return focusedObject
end; end;
show = function(self)
base:show()
if (self.parent == nil)and not(isMonitor) then
activeFrame = self
end
return self
end;
setCursor = function(self, _blink, _xCursor, _yCursor, color) setCursor = function(self, _blink, _xCursor, _yCursor, color)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) if(self.parent~=nil)then
cursorBlink = _blink or false local obx, oby = self:getAnchorPosition()
if (_xCursor ~= nil) then self.parent:setCursor(_blink or false, (_xCursor or 0)+obx-1, (_yCursor or 0)+oby-1, color or cursorColor)
xCursor = obx + _xCursor - 1 else
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
cursorBlink = _blink or false
if (_xCursor ~= nil) then
xCursor = obx + _xCursor - 1
end
if (_yCursor ~= nil) then
yCursor = oby + _yCursor - 1
end
cursorColor = color or cursorColor
self:setVisualChanged()
end end
if (_yCursor ~= nil) then
yCursor = oby + _yCursor - 1
end
cursorColor = color or cursorColor
self:setVisualChanged()
return self return self
end; end;
@@ -161,29 +171,36 @@ local function Frame(name, parent)
return self; return self;
end; end;
show = function(self)
addMonitor = function(self, mon) base.show(self)
local screen = peripheral.wrap(mon) if(self.parent==nil)then
monitors[mon] = {monitor=mon, frame=basalt.createFrame(self:getName().."_monitor_"..mon)} activeFrame = self;
monitors[mon].frame:setDisplay(screen):setFrameAsMonitor() if(isMonitor)then
monitors[mon].frame:setSize(screen:getSize()) monFrames[monSide] = self;
return monitors[mon].frame else
end; mainFrame = self;
setMonitorScale = function(self, scale, fullSize) -- 1,2,3,4,5,6,7,8,9,10
if(isMonitor)then
termObject.setTextScale(scale*0.5)
if(fullSize)then
self:setSize(termObject:getSize())
end end
end end
return self, isMonitor return self;
end; end;
setFrameAsMonitor = function(self, isMon) hide = function (self)
isMonitor = isMon or true base.hide(self)
if(self.parent==nil)then
if(activeFrame == self)then activeFrame = nil end
if(isMonitor)then
if(monFrames[monSide] == self)then
monFrames[monSide] = nil;
end
else
if(mainFrame == self)then
mainFrame = nil;
end
end
end
return self return self
end; end;
showBar = function(self, showIt) showBar = function(self, showIt)
self.barActive = showIt or not self.barActive self.barActive = showIt or not self.barActive
@@ -205,14 +222,23 @@ local function Frame(name, parent)
return self return self
end; end;
setDisplay = function(self, drawTerm) setMonitor = function(self, side)
termObject = drawTerm if(side~=nil)and(side~=false)then
if(peripheral.getType(side)=="monitor")then
termObject = peripheral.wrap(side)
monitorAttached = true
end
isMonitor = true
else
termObject = parentTerminal
isMonitor = false
if(monFrames[monSide]==self)then
monFrames[monSide] = nil
end
end
drawHelper = basaltDrawHelper(termObject) drawHelper = basaltDrawHelper(termObject)
return self monSide = side or nil
end; return self;
getDisplay = function(self)
return termObject
end; end;
getVisualChanged = function(self) getVisualChanged = function(self)
@@ -243,10 +269,14 @@ local function Frame(name, parent)
keyHandler = function(self, event, key) keyHandler = function(self, event, key)
if (focusedObject ~= nil) then if (focusedObject ~= nil) then
if (focusedObject.keyHandler ~= nil) then if(focusedObject~=self)then
if (focusedObject:keyHandler(event, key)) then if (focusedObject.keyHandler ~= nil) then
return true if (focusedObject:keyHandler(event, key)) then
return true
end
end end
else
base.keyHandler(self, event, key)
end end
end end
return false return false
@@ -276,6 +306,18 @@ local function Frame(name, parent)
end end
end end
end end
if(isMonitor)then
if(event == "peripheral")and(p1==monSide)then
if(peripheral.getType(monSide)=="monitor")then
monitorAttached = true
termObject = peripheral.wrap(monSide)
drawHelper = basaltDrawHelper(termObject)
end
end
if(event == "peripheral_detach")and(p1==monSide)then
monitorAttached = false
end
end
if (event == "terminate") then if (event == "terminate") then
termObject.clear() termObject.clear()
termObject.setCursorPos(1, 1) termObject.setCursorPos(1, 1)
@@ -283,7 +325,7 @@ local function Frame(name, parent)
end end
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseHandler = function(self, event, button, x, y)
local xO, yO = self:getOffset() local xO, yO = self:getOffset()
xO = xO < 0 and math.abs(xO) or -xO xO = xO < 0 and math.abs(xO) or -xO
yO = yO < 0 and math.abs(yO) or -yO yO = yO < 0 and math.abs(yO) or -yO
@@ -294,7 +336,7 @@ local function Frame(name, parent)
if (self.parent ~= nil) then if (self.parent ~= nil) then
parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition()) parentX, parentY = self.parent:getAbsolutePosition(self.parent:getAnchorPosition())
end end
self:setPosition(x + self.xToRem - (parentX - 1) + xO, y - (parentY - 1) + yO) self:setPosition(x + dragXOffset - (parentX - 1) + xO, y + dragYOffset - (parentY - 1) + yO)
end end
if (event == "mouse_up") then if (event == "mouse_up") then
self.drag = false self.drag = false
@@ -302,34 +344,35 @@ local function Frame(name, parent)
return true return true
end end
if (base.mouseClickHandler(self, event, button, x, y)) then local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
local yOff = false
if(objY-1 == y)and(self:getBorder("top"))then
y = y+1
yOff = true
end
if (base.mouseHandler(self, event, button, x, y)) then
local fx, fy = self:getAbsolutePosition(self:getAnchorPosition()) local fx, fy = self:getAbsolutePosition(self:getAnchorPosition())
if(event~="monitor_touch") or (isMonitor)then fx = fx + xOffset;fy = fy + yOffset;
for _, index in pairs(objZIndex) do for _, index in pairs(objZIndex) do
if (objects[index] ~= nil) then if (objects[index] ~= nil) then
for _, value in rpairs(objects[index]) do for _, value in rpairs(objects[index]) do
if (value.mouseClickHandler ~= nil) then if (value.mouseHandler ~= nil) then
if (value:mouseClickHandler(event, button, x + xO, y + yO)) then if (value:mouseHandler(event, button, x, y)) then
return true return true
end end
end end
end end
end end
end end
elseif not(isMonitor)then if (self.isMoveable) then
for _,v in pairs(monitors)do local fx, fy = self:getAbsolutePosition(self:getAnchorPosition())
if(button==v.monitor)then if (x >= fx) and (x <= fx + self.width - 1) and (y == fy) and (event == "mouse_click") then
v.frame:mouseClickHandler(event, button, x, y) self.drag = true
dragXOffset = fx - x
dragYOffset = yOff and 1 or 0
end end
end end
end
if (self.isMoveable) then
if (x >= fx) and (x <= fx + self.width - 1) and (y == fy) and (event == "mouse_click") then
self.drag = true
self.xToRem = fx - x
end
end
if (focusedObject ~= nil) then if (focusedObject ~= nil) then
focusedObject:loseFocusHandler() focusedObject:loseFocusHandler()
focusedObject = nil focusedObject = nil
@@ -343,9 +386,10 @@ local function Frame(name, parent)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (y >= 1) and (y <= self.height) then if (y >= 1) and (y <= self.height) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setText(math.max(x + (obx - 1), obx) - (self.parent.x - 1), oby + y - 1 - (self.parent.y - 1), sub(text, math.max(1 - x + 1, 1), self.width - x + 1)) local parentX, parentY = self.parent:getAnchorPosition()
self.parent:setText(math.max(x + (obx - 1), obx) - (parentX - 1), oby + y - 1 - (parentY - 1), sub(text, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)))
else else
drawHelper.setText(math.max(x + (obx - 1), obx), oby + y - 1, sub(text, math.max(1 - x + 1, 1), self.width - x + 1)) drawHelper.setText(math.max(x + (obx - 1), obx), oby + y - 1, sub(text, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1))) -- math.max(self.width - x + 1,1) now, before: self.width - x + 1
end end
end end
end; end;
@@ -354,9 +398,10 @@ local function Frame(name, parent)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (y >= 1) and (y <= self.height) then if (y >= 1) and (y <= self.height) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setBG(math.max(x + (obx - 1), obx) - (self.parent.x - 1), oby + y - 1 - (self.parent.y - 1), sub(bgCol, math.max(1 - x + 1, 1), self.width - x + 1)) local parentX, parentY = self.parent:getAnchorPosition()
self.parent:setBG(math.max(x + (obx - 1), obx) - (parentX - 1), oby + y - 1 - (parentY - 1), sub(bgCol, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)))
else else
drawHelper.setBG(math.max(x + (obx - 1), obx), oby + y - 1, sub(bgCol, math.max(1 - x + 1, 1), self.width - x + 1)) drawHelper.setBG(math.max(x + (obx - 1), obx), oby + y - 1, sub(bgCol, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)))
end end
end end
end; end;
@@ -365,9 +410,10 @@ local function Frame(name, parent)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (y >= 1) and (y <= self.height) then if (y >= 1) and (y <= self.height) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setFG(math.max(x + (obx - 1), obx) - (self.parent.x - 1), oby + y - 1 - (self.parent.y - 1), sub(fgCol, math.max(1 - x + 1, 1), self.width - x + 1)) local parentX, parentY = self.parent:getAnchorPosition()
self.parent:setFG(math.max(x + (obx - 1), obx) - (parentX - 1), oby + y - 1 - (parentY - 1), sub(fgCol, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)))
else else
drawHelper.setFG(math.max(x + (obx - 1), obx), oby + y - 1, sub(fgCol, math.max(1 - x + 1, 1), self.width - x + 1)) drawHelper.setFG(math.max(x + (obx - 1), obx), oby + y - 1, sub(fgCol, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)))
end end
end end
end; end;
@@ -376,9 +422,10 @@ local function Frame(name, parent)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (y >= 1) and (y <= self.height) then if (y >= 1) and (y <= self.height) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:writeText(math.max(x + (obx - 1), obx) - (self.parent.x - 1), oby + y - 1 - (self.parent.y - 1), sub(text, math.max(1 - x + 1, 1), self.width - x + 1), bgCol, fgCol) local parentX, parentY = self.parent:getAnchorPosition()
self.parent:writeText(math.max(x + (obx - 1), obx) - (parentX - 1), oby + y - 1 - (parentY - 1), sub(text, math.max(1 - x + 1, 1), self.width - x + 1), bgCol, fgCol)
else else
drawHelper.writeText(math.max(x + (obx - 1), obx), oby + y - 1, sub(text, math.max(1 - x + 1, 1), self.width - x + 1), bgCol, fgCol) drawHelper.writeText(math.max(x + (obx - 1), obx), oby + y - 1, sub(text, math.max(1 - x + 1, 1), math.max(self.width - x + 1,1)), bgCol, fgCol)
end end
end end
end; end;
@@ -388,7 +435,8 @@ local function Frame(name, parent)
height = (y < 1 and (height + y > self.height and self.height or height + y - 1) or (height + y > self.height and self.height - y + 1 or height)) height = (y < 1 and (height + y > self.height and self.height or height + y - 1) or (height + y > self.height and self.height - y + 1 or height))
width = (x < 1 and (width + x > self.width and self.width or width + x - 1) or (width + x > self.width and self.width - x + 1 or width)) width = (x < 1 and (width + x > self.width and self.width or width + x - 1) or (width + x > self.width and self.width - x + 1 or width))
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:drawBackgroundBox(math.max(x + (obx - 1), obx) - (self.parent.x - 1), math.max(y + (oby - 1), oby) - (self.parent.y - 1), width, height, bgCol) local parentX, parentY = self.parent:getAnchorPosition()
self.parent:drawBackgroundBox(math.max(x + (obx - 1), obx) - (parentX - 1), math.max(y + (oby - 1), oby) - (parentY - 1), width, height, bgCol)
else else
drawHelper.drawBackgroundBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), width, height, bgCol) drawHelper.drawBackgroundBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), width, height, bgCol)
end end
@@ -399,7 +447,8 @@ local function Frame(name, parent)
height = (y < 1 and (height + y > self.height and self.height or height + y - 1) or (height + y > self.height and self.height - y + 1 or height)) height = (y < 1 and (height + y > self.height and self.height or height + y - 1) or (height + y > self.height and self.height - y + 1 or height))
width = (x < 1 and (width + x > self.width and self.width or width + x - 1) or (width + x > self.width and self.width - x + 1 or width)) width = (x < 1 and (width + x > self.width and self.width or width + x - 1) or (width + x > self.width and self.width - x + 1 or width))
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:drawTextBox(math.max(x + (obx - 1), obx) - (self.parent.x - 1), math.max(y + (oby - 1), oby) - (self.parent.y - 1), width, height, symbol:sub(1, 1)) local parentX, parentY = self.parent:getAnchorPosition()
self.parent:drawTextBox(math.max(x + (obx - 1), obx) - (parentX - 1), math.max(y + (oby - 1), oby) - (parentY - 1), width, height, symbol:sub(1, 1))
else else
drawHelper.drawTextBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), width, height, symbol:sub(1, 1)) drawHelper.drawTextBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), width, height, symbol:sub(1, 1))
end end
@@ -410,36 +459,52 @@ local function Frame(name, parent)
height = (y < 1 and (height + y > self.height and self.height or height + y - 1) or (height + y > self.height and self.height - y + 1 or height)) height = (y < 1 and (height + y > self.height and self.height or height + y - 1) or (height + y > self.height and self.height - y + 1 or height))
width = (x < 1 and (width + x > self.width and self.width or width + x - 1) or (width + x > self.width and self.width - x + 1 or width)) width = (x < 1 and (width + x > self.width and self.width or width + x - 1) or (width + x > self.width and self.width - x + 1 or width))
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:drawForegroundBox(math.max(x + (obx - 1), obx) - (self.parent.x - 1), math.max(y + (oby - 1), oby) - (self.parent.y - 1), width, height, fgCol) local parentX, parentY = self.parent:getAnchorPosition()
self.parent:drawForegroundBox(math.max(x + (obx - 1), obx) - (parentX - 1), math.max(y + (oby - 1), oby) - (parentY - 1), width, height, fgCol)
else else
drawHelper.drawForegroundBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), width, height, fgCol) drawHelper.drawForegroundBox(math.max(x + (obx - 1), obx), math.max(y + (oby - 1), oby), width, height, fgCol)
end end
end; end;
draw = function(self) draw = function(self)
if(isMonitor)and not(monitorAttached)then return false end;
if (self:getVisualChanged()) then if (self:getVisualChanged()) then
if (base.draw(self)) then if (base.draw(self)) then
for _,v in pairs(monitors)do
v.frame:draw()
end
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition() local anchx, anchy = self:getAnchorPosition()
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:drawBackgroundBox(anchx, anchy, self.width, self.height, self.bgColor) if(self.bgColor~=false)then
self.parent:drawForegroundBox(anchx, anchy, self.width, self.height, self.fgColor) self.parent:drawBackgroundBox(anchx, anchy, self.width, self.height, self.bgColor)
self.parent:drawTextBox(anchx, anchy, self.width, self.height, " ") self.parent:drawTextBox(anchx, anchy, self.width, self.height, " ")
end
if(self.bgColor~=false)then self.parent:drawForegroundBox(anchx, anchy, self.width, self.height, self.fgColor) end
else else
drawHelper.drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) if(self.bgColor~=false)then
drawHelper.drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) drawHelper.drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
drawHelper.drawTextBox(obx, oby, self.width, self.height, " ") drawHelper.drawTextBox(obx, oby, self.width, self.height, " ")
end
if(self.fgColor~=false)then drawHelper.drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) end
end end
parentTerminal.setCursorBlink(false) termObject.setCursorBlink(false)
if (self.barActive) then if (self.barActive) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:writeText(anchx, anchy, getTextHorizontalAlign(self.barText, self.width, self.barTextAlign), self.barBackground, self.barTextcolor) self.parent:writeText(anchx, anchy, getTextHorizontalAlign(self.barText, self.width, self.barTextAlign), self.barBackground, self.barTextcolor)
else else
drawHelper.writeText(obx, oby, getTextHorizontalAlign(self.barText, self.width, self.barTextAlign), self.barBackground, self.barTextcolor) drawHelper.writeText(obx, oby, getTextHorizontalAlign(self.barText, self.width, self.barTextAlign), self.barBackground, self.barTextcolor)
end end
if(self:getBorder("left"))then
if (self.parent ~= nil) then
self.parent:drawBackgroundBox(anchx-1, anchy, 1, 1, self.barBackground)
if(self.bgColor~=false)then
self.parent:drawBackgroundBox(anchx-1, anchy+1, 1, self.height-1, self.bgColor)
end
end
end
if(self:getBorder("top"))then
if (self.parent ~= nil) then
self.parent:drawBackgroundBox(anchx-1, anchy-1, self.width+1, 1, self.barBackground)
end
end
end end
for _, index in rpairs(objZIndex) do for _, index in rpairs(objZIndex) do
@@ -463,10 +528,14 @@ local function Frame(name, parent)
end end
self:setVisualChanged(false) self:setVisualChanged(false)
end end
drawHelper.update()
end end
end; end;
drawUpdate = function(self)
if(isMonitor)and not(monitorAttached)then return false end;
drawHelper.update()
end;
addObject = function(self, obj) addObject = function(self, obj)
return addObject(obj) return addObject(obj)
end; end;
@@ -487,7 +556,6 @@ local function Frame(name, parent)
addLabel = function(self, name) addLabel = function(self, name)
local obj = Label(name) local obj = Label(name)
obj.name = name
obj.bgColor = self.bgColor obj.bgColor = self.bgColor
obj.fgColor = self.fgColor obj.fgColor = self.fgColor
return addObject(obj) return addObject(obj)
@@ -495,109 +563,95 @@ local function Frame(name, parent)
addCheckbox = function(self, name) addCheckbox = function(self, name)
local obj = Checkbox(name) local obj = Checkbox(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addInput = function(self, name) addInput = function(self, name)
local obj = Input(name) local obj = Input(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addProgram = function(self, name) addProgram = function(self, name)
local obj = Program(name) local obj = Program(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addTextfield = function(self, name) addTextfield = function(self, name)
local obj = Textfield(name) local obj = Textfield(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addList = function(self, name) addList = function(self, name)
local obj = List(name) local obj = List(name)
obj.name = name obj.name = nam
return addObject(obj) return addObject(obj)
end; end;
addDropdown = function(self, name) addDropdown = function(self, name)
local obj = Dropdown(name) local obj = Dropdown(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addRadio = function(self, name) addRadio = function(self, name)
local obj = Radio(name) local obj = Radio(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addTimer = function(self, name) addTimer = function(self, name)
local obj = Timer(name) local obj = Timer(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addAnimation = function(self, name) addAnimation = function(self, name)
local obj = Animation(name) local obj = Animation(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addSlider = function(self, name) addSlider = function(self, name)
local obj = Slider(name) local obj = Slider(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addScrollbar = function(self, name) addScrollbar = function(self, name)
local obj = Scrollbar(name) local obj = Scrollbar(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addMenubar = function(self, name) addMenubar = function(self, name)
local obj = Menubar(name) local obj = Menubar(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addThread = function(self, name) addThread = function(self, name)
local obj = Thread(name) local obj = Thread(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addPane = function(self, name) addPane = function(self, name)
local obj = Pane(name) local obj = Pane(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addImage = function(self, name) addImage = function(self, name)
local obj = Image(name) local obj = Image(name)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
addProgressbar = function(self, name) addProgressbar = function(self, name)
local obj = Progressbar(name) local obj = Progressbar(name)
obj.name = name return addObject(obj)
end;
addSwitch = function(self, name)
local obj = Switch(name)
return addObject(obj) return addObject(obj)
end; end;
addFrame = function(self, name) addFrame = function(self, name)
local obj = Frame(name, self) local obj = Frame(name, self)
obj.name = name
return addObject(obj) return addObject(obj)
end; end;
} }
setmetatable(object, base) setmetatable(object, base)
if (parent == nil) then
table.insert(frames, object)
end
return object return object
end end

View File

@@ -1,18 +1,21 @@
local function Object(name) local function Object(name)
-- Base object -- Base object
local objectType = "Object" -- not changeable local objectType = "Object" -- not changeable
--[[
local horizontalAnchor = "left"
local verticalAnchor = "top"
local ignYOffset = false
local ignXOffset = false ]]
local value local value
local zIndex = 1 local zIndex = 1
local hanchor = "left" local anchor = "topLeft"
local vanchor = "top"
local ignOffset = false local ignOffset = false
local isVisible = false local isVisible = false
local shadow = false
local borderLeft = false
local borderTop = false
local borderRight = false
local borderBottom = false
local shadowColor = colors.black
local borderColor = colors.black
local visualsChanged = true local visualsChanged = true
local eventSystem = BasaltEvents() local eventSystem = BasaltEvents()
@@ -43,10 +46,6 @@ local function Object(name)
return isVisible return isVisible
end; end;
getZIndex = function(self)
return zIndex;
end;
setFocus = function(self) setFocus = function(self)
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setFocusedObject(self) self.parent:setFocusedObject(self)
@@ -63,6 +62,10 @@ local function Object(name)
return self return self
end; end;
getZIndex = function(self)
return zIndex;
end;
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
@@ -108,6 +111,7 @@ local function Object(name)
setVisualChanged = function(self, change) setVisualChanged = function(self, change)
visualsChanged = change or true visualsChanged = change or true
if(change == nil)then visualsChanged = true end
return self return self
end; end;
@@ -147,6 +151,7 @@ local function Object(name)
setSize = function(self, width, height) setSize = function(self, width, height)
self.width, self.height = width, height self.width, self.height = width, height
eventSystem:sendEvent("basalt_resize", self)
visualsChanged = true visualsChanged = true
return self return self
end; end;
@@ -183,8 +188,104 @@ local function Object(name)
return self.fgColor return self.fgColor
end; end;
showShadow = function(self, show)
shadow = show or (not shadow)
return self
end;
setShadow = function(self, color)
shadowColor = color
return self
end;
isShadowActive = function(self)
return shadow;
end;
showBorder = function(self, ...)
for _,v in pairs(table.pack(...))do
if(v=="left")then
borderLeft = true
end
if(v=="top")then
borderTop = true
end
if(v=="right")then
borderRight = true
end
if(v=="bottom")then
borderBottom = true
end
end
return self
end;
setBorder = function(self, color)
shadowColor = color
return self
end;
getBorder = function(self, side)
if(side=="left")then
return borderLeft;
end
if(side=="top")then
return borderTop;
end
if(side=="right")then
return borderRight;
end
if(side=="bottom")then
return borderBottom;
end
end;
draw = function(self) draw = function(self)
if (isVisible) then if (isVisible) then
if(self.parent~=nil)then
local x, y = self:getAnchorPosition()
if(shadow)then
self.parent:drawBackgroundBox(x+1, y+self.height, self.width, 1, shadowColor)
self.parent:drawBackgroundBox(x+self.width, y+1, 1, self.height, shadowColor)
self.parent:drawForegroundBox(x+1, y+self.height, self.width, 1, shadowColor)
self.parent:drawForegroundBox(x+self.width, y+1, 1, self.height, shadowColor)
end
if(borderLeft)then
self.parent:drawTextBox(x-1, y, 1, self.height, "\149")
self.parent:drawForegroundBox(x-1, y, 1, self.height, borderColor)
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y, 1, self.height, self.bgColor) end
end
if(borderLeft)and(borderTop)then
self.parent:drawTextBox(x-1, y-1, 1, 1, "\151")
self.parent:drawForegroundBox(x-1, y-1, 1, 1, borderColor)
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x-1, y-1, 1, 1, self.bgColor) end
end
if(borderTop)then
self.parent:drawTextBox(x, y-1, self.width, 1, "\131")
self.parent:drawForegroundBox(x, y-1, self.width, 1, borderColor)
if(self.bgColor~=false)then self.parent:drawBackgroundBox(x, y-1, self.width, 1, self.bgColor) end
end
if(borderTop)and(borderRight)then
self.parent:drawTextBox(x+self.width, y-1, 1, 1, "\149")
self.parent:drawForegroundBox(x+self.width, y-1, 1, 1, borderColor)
end
if(borderRight)then
self.parent:drawTextBox(x+self.width, y, 1, self.height, "\149")
self.parent:drawForegroundBox(x+self.width, y, 1, self.height, borderColor)
end
if(borderRight)and(borderBottom)then
self.parent:drawTextBox(x+self.width, y+self.height, 1, 1, "\129")
self.parent:drawForegroundBox(x+self.width, y+self.height, 1, 1, borderColor)
end
if(borderBottom)then
self.parent:drawTextBox(x, y+self.height, self.width, 1, "\131")
self.parent:drawForegroundBox(x, y+self.height, self.width, 1, borderColor)
end
if(borderBottom)and(borderLeft)then
self.parent:drawTextBox(x-1, y+self.height, 1, 1, "\131")
self.parent:drawForegroundBox(x-1, y+self.height, 1, 1, borderColor)
end
end
return true return true
end end
return false return false
@@ -193,11 +294,8 @@ local function Object(name)
getAbsolutePosition = function(self, x, y) getAbsolutePosition = function(self, x, y)
-- relative position to absolute position -- relative position to absolute position
if (x == nil) then if (x == nil) or (y == nil) then
x = self.x x, y = self:getAnchorPosition()
end
if (y == nil) then
y = self.y
end end
if (self.parent ~= nil) then if (self.parent ~= nil) then
@@ -215,88 +313,164 @@ local function Object(name)
if (y == nil) then if (y == nil) then
y = self.y y = self.y
end end
if (hanchor == "right") then if (anchor == "top") then
x = self.parent.width - x - self.width + 2 x = math.floor(self.parent.width/2) + x - 1
end elseif(anchor == "topRight") then
if (vanchor == "bottom") then x = self.parent.width + x - 1
y = self.parent.height - y - self.height + 2 elseif(anchor == "right") then
x = self.parent.width + x - 1
y = math.floor(self.parent.height/2) + y - 1
elseif(anchor == "bottomRight") then
x = self.parent.width + x - 1
y = self.parent.height + y - 1
elseif(anchor == "bottom") then
x = math.floor(self.parent.width/2) + x - 1
y = self.parent.height + y - 1
elseif(anchor == "bottomLeft") then
y = self.parent.height + y - 1
elseif(anchor == "left") then
y = math.floor(self.parent.height/2) + y - 1
elseif(anchor == "center") then
x = math.floor(self.parent.width/2) + x - 1
y = math.floor(self.parent.height/2) + y - 1
end end
local xO, yO = self:getOffset() local xO, yO = self:getOffset()
if (ignOffset or ignOff) then if not(ignOffset or ignOff) then
return x, y return x+xO, y+yO
end end
return x + xO, y + yO return x, y
end; end;
getOffset = function(self) getOffset = function(self)
if (self.parent ~= nil) and (ignOffset == false) then if (self.parent ~= nil) then
return self.parent:getFrameOffset() return self.parent:getFrameOffset()
end end
return 0, 0 return 0, 0
end; end;
ignoreOffset = function(self, ignore) ignoreOffset = function(self, ignore)
ignOffset = ignore or true ignOffset = ignore
if(ignore==nil)then ignOffset = true end
return self return self
end; end;
setAnchor = function(self, ...) getBaseFrame = function(self)
for _, value in pairs(table.pack(...)) do if(self.parent~=nil)then
if (value == "right") or (value == "left") then return self.parent:getBaseFrame()
hanchor = value
end
if (value == "top") or (value == "bottom") then
vanchor = value
end
end end
return self
end;
setAnchor = function(self, newAnchor)
anchor = newAnchor
visualsChanged = true visualsChanged = true
return self return self
end; end;
getAnchor = function(self) getAnchor = function(self)
return hanchor, vanchor return anchor
end; end;
onChange = function(self, func) onChange = function(self, ...)
self:registerEvent("value_changed", func) for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("value_changed", v)
end
end
return self return self
end; end;
onClick = function(self, func) onClick = function(self, ...)
self:registerEvent("mouse_click", func) for _,v in pairs(table.pack(...))do
self:registerEvent("monitor_touch", func) if(type(v)=="function")then
self:registerEvent("mouse_click", v)
self:registerEvent("monitor_touch", v)
end
end
return self return self
end; end;
onEvent = function(self, func) onClickUp = function(self, ...)
self:registerEvent("custom_event_handler", func) for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_up", v)
end
end
return self return self
end; end;
onClickUp = function(self, func)
self:registerEvent("mouse_up", func) onScroll = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("mouse_scroll", v)
end
end
return self return self
end; end;
onKey = function(self, func) onDrag = function(self, ...)
self:registerEvent("key", func) for _,v in pairs(table.pack(...))do
self:registerEvent("char", func) if(type(v)=="function")then
self:registerEvent("mouse_drag", v)
end
end
return self return self
end; end;
onKeyUp = function(self, func) onEvent = function(self, ...)
self:registerEvent("key_up", func) for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("custom_event_handler", v)
end
end
return self return self
end; end;
onBackgroundKey = function(self, func) onKey = function(self, ...)
self:registerEvent("background_key", func) for _,v in pairs(table.pack(...))do
self:registerEvent("background_char", func) if(type(v)=="function")then
self:registerEvent("key", v)
self:registerEvent("char", v)
end
end
return self return self
end; end;
onBackgroundKeyUp = function(self, func) onResize = function(self, ...)
self:registerEvent("background_key_up", func) for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("basalt_resize", v)
end
end
return self
end;
onKeyUp = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("key_up", v)
end
end
return self
end;
onBackgroundKey = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("background_key", v)
self:registerEvent("background_char", v)
end
end
return self
end;
onBackgroundKeyUp = function(self, ...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("background_key_up", v)
end
end
return self return self
end; end;
@@ -307,13 +481,21 @@ local function Object(name)
return false return false
end; end;
onGetFocus = function(self, func) onGetFocus = function(self, ...)
self:registerEvent("get_focus", func) for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("get_focus", v)
end
end
return self return self
end; end;
onLoseFocus = function(self, func) onLoseFocus = function(self, ...)
self:registerEvent("lose_focus", func) for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
self:registerEvent("lose_focus", v)
end
end
return self return self
end; end;
@@ -329,13 +511,20 @@ local function Object(name)
return eventSystem:sendEvent(event, self, ...) return eventSystem:sendEvent(event, self, ...)
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseHandler = function(self, event, button, x, y)
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
local yOff = false
if(objY-1 == y)and(self:getBorder("top"))then
y = y+1
yOff = true
end
if (objX <= x) and (objX + self.width > x) and (objY <= y) and (objY + self.height > y) and (isVisible) then if (objX <= x) and (objX + self.width > x) and (objY <= y) and (objY + self.height > y) and (isVisible) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setFocusedObject(self) self.parent:setFocusedObject(self)
end end
eventSystem:sendEvent(event, self, event, button, x, y) local val = eventSystem:sendEvent(event, self, event, button, x, y)
if(val~=nil)then return val end
return true return true
end end
return false return false
@@ -343,14 +532,17 @@ local function Object(name)
keyHandler = function(self, event, key) keyHandler = function(self, event, key)
if (self:isFocused()) then if (self:isFocused()) then
eventSystem:sendEvent(event, self, event, key) local val = eventSystem:sendEvent(event, self, event, key)
if(val~=nil)then return val end
return true return true
end end
return false return false
end; end;
backgroundKeyHandler = function(self, event, key) backgroundKeyHandler = function(self, event, key)
eventSystem:sendEvent("background_" .. event, self, event, key) local val = eventSystem:sendEvent("background_"..event, self, event, key)
if(val~=nil)then return val end
return true
end; end;
valueChangedHandler = function(self) valueChangedHandler = function(self)
@@ -362,11 +554,15 @@ local function Object(name)
end; end;
getFocusHandler = function(self) getFocusHandler = function(self)
eventSystem:sendEvent("get_focus", self) local val = eventSystem:sendEvent("get_focus", self)
if(val~=nil)then return val end
return true
end; end;
loseFocusHandler = function(self) loseFocusHandler = function(self)
eventSystem:sendEvent("lose_focus", self) local val = eventSystem:sendEvent("lose_focus", self)
if(val~=nil)then return val end
return true
end; end;

View File

@@ -19,13 +19,19 @@ local function BasaltEvents()
end; end;
sendEvent = function(self, _event, ...) sendEvent = function(self, _event, ...)
local returnValue
if (events[_event] ~= nil) then if (events[_event] ~= nil) then
for _, value in pairs(events[_event]) do for _, value in pairs(events[_event]) do
value(...) local val = value(...)
if(val==false)then
returnValue = val
end
end end
end end
return returnValue
end; end;
} }
event.__index = event event.__index = event
return event return event
end end
local eventSystem = BasaltEvents()

View File

@@ -8,7 +8,7 @@ function process:new(path, window, ...)
newP.window = window newP.window = window
newP.processId = processId newP.processId = processId
newP.coroutine = coroutine.create(function() newP.coroutine = coroutine.create(function()
os.run({ basalt = basalt }, path, table.unpack(args)) os.run({ }, path, table.unpack(args))
end) end)
processes[processId] = newP processes[processId] = newP
processId = processId + 1 processId = processId + 1

View File

@@ -36,9 +36,8 @@ local function rpairs(t)
end, t, #t + 1 end, t, #t + 1
end end
-- shrink system is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/
local function shrink(bLittleData, bgColor) local function shrink(bLittleData, bgColor)
-- shrinkSystem is copy pasted (and slightly changed) from blittle by Bomb Bloke: http://www.computercraft.info/forums2/index.php?/topic/25354-cc-176-blittle-api/
local relations = { [0] = { 8, 4, 3, 6, 5 }, { 4, 14, 8, 7 }, { 6, 10, 8, 7 }, { 9, 11, 8, 0 }, { 1, 14, 8, 0 }, { 13, 12, 8, 0 }, { 2, 10, 8, 0 }, { 15, 8, 10, 11, 12, 14 }, local relations = { [0] = { 8, 4, 3, 6, 5 }, { 4, 14, 8, 7 }, { 6, 10, 8, 7 }, { 9, 11, 8, 0 }, { 1, 14, 8, 0 }, { 13, 12, 8, 0 }, { 2, 10, 8, 0 }, { 15, 8, 10, 11, 12, 14 },
{ 0, 7, 1, 9, 2, 13 }, { 3, 11, 8, 7 }, { 2, 6, 7, 15 }, { 9, 3, 7, 15 }, { 13, 5, 7, 15 }, { 5, 12, 8, 7 }, { 1, 4, 7, 15 }, { 7, 10, 11, 12, 14 } } { 0, 7, 1, 9, 2, 13 }, { 3, 11, 8, 7 }, { 2, 6, 7, 15 }, { 9, 3, 7, 15 }, { 13, 5, 7, 15 }, { 5, 12, 8, 7 }, { 1, 4, 7, 15 }, { 7, 10, 11, 12, 14 } }

View File

@@ -1,16 +1,37 @@
local function drawFrames()
mainFrame:draw()
mainFrame:drawUpdate()
for _,v in pairs(monFrames)do
v:draw()
v:drawUpdate()
end
end
local updaterActive = false local updaterActive = false
local function basaltUpdateEvent(event, p1, p2, p3, p4) local function basaltUpdateEvent(event, p1, p2, p3, p4)
if (event == "mouse_click") then if(eventSystem:sendEvent("basaltEventCycle", event, p1, p2, p3, p4)==false)then return end
activeFrame:mouseClickHandler(event, p1, p2, p3, p4) if(mainFrame~=nil)then
elseif (event == "mouse_drag") then if (event == "mouse_click") then
activeFrame:mouseClickHandler(event, p1, p2, p3, p4) mainFrame:mouseHandler(event, p1, p2, p3, p4)
elseif (event == "mouse_up") then activeFrame = mainFrame
activeFrame:mouseClickHandler(event, p1, p2, p3, p4) elseif (event == "mouse_drag") then
elseif (event == "mouse_scroll") then mainFrame:mouseHandler(event, p1, p2, p3, p4)
activeFrame:mouseClickHandler(event, p1, p2, p3, p4) activeFrame = mainFrame
elseif (event == "monitor_touch") then elseif (event == "mouse_up") then
activeFrame:mouseClickHandler(event, p1, p2, p3, p4) mainFrame:mouseHandler(event, p1, p2, p3, p4)
elseif (event == "key") or (event == "char") then activeFrame = mainFrame
elseif (event == "mouse_scroll") then
mainFrame:mouseHandler(event, p1, p2, p3, p4)
activeFrame = mainFrame
elseif (event == "monitor_touch") then
if(monFrames[p1]~=nil)then
monFrames[p1]:mouseHandler(event, p1, p2, p3, p4)
activeFrame = monFrames[p1]
end
end
end
if(event == "key") or (event == "char") then
activeFrame:keyHandler(event, p1) activeFrame:keyHandler(event, p1)
activeFrame:backgroundKeyHandler(event, p1) activeFrame:backgroundKeyHandler(event, p1)
end end
@@ -23,18 +44,16 @@ local function basaltUpdateEvent(event, p1, p2, p3, p4)
keyActive[p1] = false keyActive[p1] = false
end end
for _, value in pairs(frames) do for _, v in pairs(frames) do
value:eventHandler(event, p1, p2, p3, p4) v:eventHandler(event, p1, p2, p3, p4)
end
if (updaterActive) then
activeFrame:draw()
end end
drawFrames()
end end
function basalt.autoUpdate(isActive) function basalt.autoUpdate(isActive)
parentTerminal.clear() updaterActive = isActive
updaterActive = isActive or true if(isActive==nil)then updaterActive = true end
activeFrame:draw() drawFrames()
while updaterActive do while updaterActive do
local event, p1, p2, p3, p4 = os.pullEventRaw() -- change to raw later local event, p1, p2, p3, p4 = os.pullEventRaw() -- change to raw later
basaltUpdateEvent(event, p1, p2, p3, p4) basaltUpdateEvent(event, p1, p2, p3, p4)
@@ -42,10 +61,8 @@ function basalt.autoUpdate(isActive)
end end
function basalt.update(event, p1, p2, p3, p4) function basalt.update(event, p1, p2, p3, p4)
if (event ~= "nil") then if (event ~= nil) then
basaltUpdateEvent(event, p1, p2, p3, p4) basaltUpdateEvent(event, p1, p2, p3, p4)
else
activeFrame:draw()
end end
end end
@@ -78,33 +95,43 @@ function basalt.setActiveFrame(frame)
return false return false
end end
function basalt.onEvent(...)
for _,v in pairs(table.pack(...))do
if(type(v)=="function")then
eventSystem:registerEvent("basaltEventCycle", v)
end
end
end
function basalt.createFrame(name) function basalt.createFrame(name)
return Frame(name) for _, v in pairs(frames) do
if (v.name == name) then
return nil
end
end
local newFrame = Frame(name)
table.insert(frames, newFrame)
return newFrame
end end
function basalt.removeFrame(name) function basalt.removeFrame(name)
for key, value in pairs(frames) do frames[name] = nil
if (value.name == name) then
frames[key] = nil
return true
end
end
return false
end end
if (basalt.debugger) then if (basalt.debugger) then
basalt.debugFrame = basalt.createFrame("basaltDebuggingFrame"):showBar():setBackground(colors.lightGray):setBar("Debug", colors.black, colors.gray) basalt.debugFrame = basalt.createFrame("basaltDebuggingFrame"):showBar():setBackground(colors.lightGray):setBar("Debug", colors.black, colors.gray)
basalt.debugList = basalt.debugFrame:addList("debugList"):setSize(basalt.debugFrame.width - 2, basalt.debugFrame.height - 3):setPosition(2, 3):setScrollable(true):show() basalt.debugList = basalt.debugFrame:addList("debugList"):setSize(basalt.debugFrame.width - 2, basalt.debugFrame.height - 3):setPosition(2, 3):setScrollable(true):show()
basalt.debugFrame:addButton("back"):setAnchor("right"):setSize(1, 1):setText("\22"):onClick(function() basalt.oldFrame:show() end):setBackground(colors.red):show() basalt.debugFrame:addButton("back"):setAnchor("topRight"):setSize(1, 1):setText("\22"):onClick(function() basalt.oldFrame:show() end):setBackground(colors.red):show()
basalt.debugLabel = basalt.debugFrame:addLabel("debugLabel"):onClick(function() basalt.oldFrame = activeFrame basalt.debugFrame:show() end):setBackground(colors.black):setForeground(colors.white):setAnchor("bottom"):setZIndex(20):show() basalt.debugLabel = basalt.debugFrame:addLabel("debugLabel"):onClick(function() basalt.oldFrame = mainFrame basalt.debugFrame:show() end):setBackground(colors.black):setForeground(colors.white):setAnchor("bottomLeft"):ignoreOffset():setZIndex(20):show()
end end
if (basalt.debugger) then if (basalt.debugger) then
function basalt.debug(...) function basalt.debug(...)
local args = { ... } local args = { ... }
if (activeFrame.name ~= "basaltDebuggingFrame") then if (mainFrame.name ~= "basaltDebuggingFrame") then
if (activeFrame ~= basalt.debugLabel.frame) then if (mainFrame ~= basalt.debugFrame) then
basalt.debugLabel:setParent(activeFrame) basalt.debugLabel:setParent(mainFrame)
end end
end end
local str = "" local str = ""
@@ -117,6 +144,9 @@ if (basalt.debugger) then
basalt.debugList:removeItem(1) basalt.debugList:removeItem(1)
end end
basalt.debugList:setValue(basalt.debugList:getItem(basalt.debugList:getItemCount())) basalt.debugList:setValue(basalt.debugList:getItem(basalt.debugList:getItemCount()))
if(basalt.debugList.getItemCount() > basalt.debugList:getHeight())then
basalt.debugList:setIndexOffset(basalt.debugList:getItemCount() - basalt.debugList:getHeight())
end
basalt.debugLabel:show() basalt.debugLabel:show()
end end
end end

View File

@@ -1,7 +1,12 @@
local basalt = { debugger = true, version = 1 } local basalt = { debugger = true, version = 1 }
local activeFrame local keyActive = {}
local frames = {} local focusedObject
local keyActive = {} local frames = {}
local activeFrame
local mainFrame
local monFrames = {}
local parentTerminal = term.current() local parentTerminal = term.current()
local sub = string.sub local sub = string.sub

View File

@@ -35,15 +35,18 @@ local function Button(name)
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
local verticalAlign = getTextVerticalAlign(self.height, textVerticalAlign) local verticalAlign = getTextVerticalAlign(self.height, textVerticalAlign)
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) if(self.bgColor~=false)then
self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
self.parent:drawTextBox(obx, oby, self.width, self.height, " ") self.parent:drawTextBox(obx, oby, self.width, self.height, " ")
end
if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) end
for n = 1, self.height do for n = 1, self.height do
if (n == verticalAlign) then if (n == verticalAlign) then
self.parent:setText(obx, oby + (n - 1), getTextHorizontalAlign(self:getValue(), self.width, textHorizontalAlign)) self.parent:setText(obx, oby + (n - 1), getTextHorizontalAlign(self:getValue(), self.width, textHorizontalAlign))
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -17,8 +17,8 @@ local function Checkbox(name)
return objectType return objectType
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then if (base.mouseHandler(self, event, button, x, y)) then
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then
if (self:getValue() ~= true) and (self:getValue() ~= false) then if (self:getValue() ~= true) and (self:getValue() ~= false) then
self:setValue(false) self:setValue(false)
@@ -37,7 +37,7 @@ local function Checkbox(name)
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
local verticalAlign = getTextVerticalAlign(self.height, "center") local verticalAlign = getTextVerticalAlign(self.height, "center")
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) if(self.bgColor~=false)then self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) end
for n = 1, self.height do for n = 1, self.height do
if (n == verticalAlign) then if (n == verticalAlign) then
if (self:getValue() == true) then if (self:getValue() == true) then
@@ -48,6 +48,7 @@ local function Checkbox(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -18,7 +18,7 @@ local function Dropdown(name)
local dropdownH = 6 local dropdownH = 6
local closedSymbol = "\16" local closedSymbol = "\16"
local openedSymbol = "\31" local openedSymbol = "\31"
local state = 1 local isOpened = false
local object = { local object = {
getType = function(self) getType = function(self)
@@ -94,8 +94,8 @@ local function Dropdown(name)
return self return self
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseHandler = function(self, event, button, x, y)
if (state == 2) then if (isOpened) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then if ((event == "mouse_click") and (button == 1)) or (event == "monitor_touch") then
@@ -129,10 +129,10 @@ local function Dropdown(name)
end end
self:setVisualChanged() self:setVisualChanged()
end end
if (base.mouseClickHandler(self, event, button, x, y)) then if (base.mouseHandler(self, event, button, x, y)) then
state = 2 isOpened = true
else else
state = 1 isOpened = false
end end
end; end;
@@ -140,34 +140,28 @@ local function Dropdown(name)
if (base.draw(self)) then if (base.draw(self)) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) if(self.bgColor~=false)then self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) end
if (#list >= 1) then local val = self:getValue()
if (self:getValue() ~= nil) then local text = getTextHorizontalAlign((val~=nil and val.text or ""), self.width, align):sub(1, self.width - 1) .. (isOpened and openedSymbol or closedSymbol)
if (self:getValue().text ~= nil) then self.parent:writeText(obx, oby, text, self.bgColor, self.fgColor)
if (state == 1) then
self.parent:writeText(obx, oby, getTextHorizontalAlign(self:getValue().text, self.width, align):sub(1, self.width - 1) .. closedSymbol, self.bgColor, self.fgColor) if (isOpened) then
else for n = 1, dropdownH do
self.parent:writeText(obx, oby, getTextHorizontalAlign(self:getValue().text, self.width, align):sub(1, self.width - 1) .. openedSymbol, self.bgColor, self.fgColor) if (list[n + yOffset] ~= nil) then
end if (list[n + yOffset] == val) then
end if (selectionColorActive) then
end self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), itemSelectedBG, itemSelectedFG)
if (state == 2) then
for n = 1, dropdownH do
if (list[n + yOffset] ~= nil) then
if (list[n + yOffset] == self:getValue()) then
if (selectionColorActive) then
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), itemSelectedBG, itemSelectedFG)
else
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol)
end
else else
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol) self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol)
end end
else
self.parent:writeText(obx, oby + n, getTextHorizontalAlign(list[n + yOffset].text, dropdownW, align), list[n + yOffset].bgCol, list[n + yOffset].fgCol)
end end
end end
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -142,7 +142,7 @@ local function Image(name)
loadBlittleImage = function(self, path) -- not done yet loadBlittleImage = function(self, path) -- not done yet
--image = paintutils.loadImage(path) --image = paintutils.loadImage(path)
imageGotShrinked = true --imageGotShrinked = true
return self return self
end; end;
@@ -184,6 +184,7 @@ local function Image(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -78,7 +78,7 @@ local function Input(name)
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
showingText = "" showingText = ""
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setCursor(true, obx + textX - wIndex, oby, self.fgColor) self.parent:setCursor(true, obx + textX - wIndex, oby+math.floor(self.height/2), self.fgColor)
end end
end end
end; end;
@@ -181,14 +181,14 @@ local function Input(name)
cursorX = self.x + self.width - 1 cursorX = self.x + self.width - 1
end end
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setCursor(true, obx + cursorX, oby, self.fgColor) self.parent:setCursor(true, obx + cursorX, oby+math.floor(self.height/2), self.fgColor)
end end
internalValueChange = false internalValueChange = false
end end
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then if (base.mouseHandler(self, event, button, x, y)) then
if (event == "mouse_click") and (button == 1) then if (event == "mouse_click") and (button == 1) then
end end
@@ -203,7 +203,7 @@ local function Input(name)
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
local verticalAlign = getTextVerticalAlign(self.height, "center") local verticalAlign = getTextVerticalAlign(self.height, "center")
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) if(self.bgColor~=false)then self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) end
for n = 1, self.height do for n = 1, self.height do
if (n == verticalAlign) then if (n == verticalAlign) then
local val = tostring(base.getValue()) local val = tostring(base.getValue())
@@ -233,6 +233,7 @@ local function Input(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -57,17 +57,18 @@ local function Label(name)
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
local verticalAlign = getTextVerticalAlign(self.height, textVerticalAlign) local verticalAlign = getTextVerticalAlign(self.height, textVerticalAlign)
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) if(self.bgColor~=false)then
self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
self.parent:drawTextBox(obx, oby, self.width, self.height, " ") self.parent:drawTextBox(obx, oby, self.width, self.height, " ") end
if(self.fgColor~=false)then self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) end
if(fontsize==0)then if(fontsize==0)then
for n = 1, self.height do for n = 1, self.height do
if (n == verticalAlign) then if (n == verticalAlign) then
self.parent:writeText(obx, oby + (n - 1), getTextHorizontalAlign(self:getValue(), self.width, textHorizontalAlign), self.bgColor, self.fgColor) self.parent:setText(obx, oby + (n - 1), getTextHorizontalAlign(self:getValue(), self.width, textHorizontalAlign))
end end
end end
else else
local tData = makeText(fontsize, self:getValue(), self.fgColor, self.bgColor) local tData = makeText(fontsize, self:getValue(), self.fgColor, self.bgColor or colors.black)
if(autoSize)then if(autoSize)then
self.height = #tData[1]-1 self.height = #tData[1]-1
self.width = #tData[1][1] self.width = #tData[1][1]
@@ -81,13 +82,14 @@ local function Label(name)
for i = 1, cY do for i = 1, cY do
self.parent:setFG(obx, oby + i + n - 2, getTextHorizontalAlign(tData[2][i], self.width, textHorizontalAlign)) self.parent:setFG(obx, oby + i + n - 2, getTextHorizontalAlign(tData[2][i], self.width, textHorizontalAlign))
self.parent:setBG(obx, oby + i + n - 2, getTextHorizontalAlign(tData[3][i], self.width, textHorizontalAlign, tHex[self.bgColor])) self.parent:setBG(obx, oby + i + n - 2, getTextHorizontalAlign(tData[3][i], self.width, textHorizontalAlign, tHex[self.bgColor or colors.black]))
self.parent:setText(obx, oby + i + n - 2, getTextHorizontalAlign(tData[1][i], self.width, textHorizontalAlign)) self.parent:setText(obx, oby + i + n - 2, getTextHorizontalAlign(tData[1][i], self.width, textHorizontalAlign))
end end
end end
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -92,7 +92,7 @@ local function List(name)
return self return self
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseHandler = function(self, event, button, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (obx <= x) and (obx + self.width > x) and (oby <= y) and (oby + self.height > y) and (self:isVisible()) then if (obx <= x) and (obx + self.width > x) and (oby <= y) and (oby + self.height > y) and (self:isVisible()) then
if (((event == "mouse_click") or (event == "mouse_drag"))and(button==1))or(event=="monitor_touch") then if (((event == "mouse_click") or (event == "mouse_drag"))and(button==1))or(event=="monitor_touch") then
@@ -135,7 +135,9 @@ local function List(name)
if (base.draw(self)) then if (base.draw(self)) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) if(self.bgColor~=false)then
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
end
for n = 1, self.height do for n = 1, self.height do
if (list[n + yOffset] ~= nil) then if (list[n + yOffset] ~= nil) then
if (list[n + yOffset] == self:getValue()) then if (list[n + yOffset] == self:getValue()) then
@@ -150,6 +152,7 @@ local function List(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -15,15 +15,19 @@ local function Menubar(name)
local selectionColorActive = true local selectionColorActive = true
local align = "left" local align = "left"
local itemOffset = 0 local itemOffset = 0
local space = 2 local space = 1
local scrollable = false local scrollable = false
local function maxScroll() local function maxScroll()
local mScroll = 0 local mScroll = 0
local xPos = 1 local xPos = 0
for n = 1, #list do for n = 1, #list do
if (xPos + list[n].text:len() + space * 2 > object.w) then if (xPos + list[n].text:len() + space * 2 > object.width) then
mScroll = mScroll + list[n].text:len() + space * 2 if(xPos < object.width)then
mScroll = mScroll + (list[n].text:len() + space * 2-(object.width - xPos))
else
mScroll = mScroll + list[n].text:len() + space * 2
end
end end
xPos = xPos + list[n].text:len() + space * 2 xPos = xPos + list[n].text:len() + space * 2
@@ -68,7 +72,7 @@ local function Menubar(name)
return self return self
end; end;
setButtonOffset = function(self, offset) setPositionOffset = function(self, offset)
itemOffset = offset or 0 itemOffset = offset or 0
if (itemOffset < 0) then if (itemOffset < 0) then
itemOffset = 0 itemOffset = 0
@@ -81,8 +85,13 @@ local function Menubar(name)
return self return self
end; end;
getPositionOffset = function(self)
return itemOffset
end;
setScrollable = function(self, scroll) setScrollable = function(self, scroll)
scrollable = scroll scrollable = scroll
if(scroll==nil)then scrollable = true end
return self return self
end; end;
@@ -117,41 +126,42 @@ local function Menubar(name)
return self return self
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseHandler = function(self, event, button, x, y)
local objX, objY = self:getAbsolutePosition(self:getAnchorPosition()) if(base.mouseHandler(self, event, button, x, y))then
if (objX <= x) and (objX + self.width > x) and (objY <= y) and (objY + self.height > y) and (self:isVisible()) then local objX, objY = self:getAbsolutePosition(self:getAnchorPosition())
if (self.parent ~= nil) then if (objX <= x) and (objX + self.width > x) and (objY <= y) and (objY + self.height > y) and (self:isVisible()) then
self.parent:setFocusedObject(self) if (self.parent ~= nil) then
end self.parent:setFocusedObject(self)
if (event == "mouse_click") or (event == "monitor_touch") then end
local xPos = 1 if (event == "mouse_click") or (event == "monitor_touch") then
for n = 1 + itemOffset, #list do local xPos = 0
if (list[n] ~= nil) then for n = 1, #list do
if (xPos + list[n].text:len() + space * 2 <= self.width) then if (list[n] ~= nil) then
if (objX + (xPos - 1) <= x) and (objX + (xPos - 1) + list[n].text:len() + space * 2 > x) and (objY == y) then --if (xPos-1 + list[n].text:len() + space * 2 <= self.width) then
if (objX + xPos <= x + itemOffset) and (objX + xPos + list[n].text:len() + (space*2) > x + itemOffset) and (objY == y) then
self:setValue(list[n]) self:setValue(list[n])
self:getEventSystem():sendEvent("mouse_click", self, "mouse_click", 0, x, y, list[n]) self:getEventSystem():sendEvent(event, self, event, 0, x, y, list[n])
end end
xPos = xPos + list[n].text:len() + space * 2 xPos = xPos + list[n].text:len() + space * 2
else
break
end end
end end
end
end
if (event == "mouse_scroll") and (scrollable) then
itemOffset = itemOffset + button
if (itemOffset < 0) then
itemOffset = 0
end end
local mScroll = maxScroll() if (event == "mouse_scroll") and (scrollable) then
itemOffset = itemOffset + button
if (itemOffset < 0) then
itemOffset = 0
end
if (itemOffset > mScroll) then local mScroll = maxScroll()
itemOffset = mScroll
if (itemOffset > mScroll) then
itemOffset = mScroll
end
end end
self:setVisualChanged(true)
return true
end end
return true
end end
return false return false
end; end;
@@ -160,28 +170,29 @@ local function Menubar(name)
if (base.draw(self)) then if (base.draw(self)) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) if(self.bgColor~=false)then
local xPos = 0 self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
for _, value in pairs(list) do end
if (xPos + value.text:len() + space * 2 <= self.width) then local text = ""
if (value == self:getValue()) then local textBGCol = ""
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align), itemSelectedBG or value.bgCol, itemSelectedFG or value.fgCol) local textFGCol = ""
else for _, v in pairs(list) do
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align), value.bgCol, value.fgCol) local newItem = (" "):rep(space) .. v.text .. (" "):rep(space)
end text = text .. newItem
xPos = xPos + value.text:len() + space * 2 if(v == self:getValue())then
textBGCol = textBGCol .. tHex[itemSelectedBG or v.bgCol or self.bgColor]:rep(newItem:len())
textFGCol = textFGCol .. tHex[itemSelectedFG or v.FgCol or self.fgColor]:rep(newItem:len())
else else
if (xPos < self.width + itemOffset) then textBGCol = textBGCol .. tHex[v.bgCol or self.bgColor]:rep(newItem:len())
if (value == self:getValue()) then textFGCol = textFGCol .. tHex[v.FgCol or self.fgColor]:rep(newItem:len())
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align):sub(1, self.width + itemOffset - xPos), itemSelectedBG or value.bgCol, itemSelectedFG or value.fgCol)
else
self.parent:writeText(obx + (xPos - 1) + (-itemOffset), oby, getTextHorizontalAlign((" "):rep(space) .. value.text .. (" "):rep(space), value.text:len() + space * 2, align):sub(1, self.width + itemOffset - xPos), value.bgCol, value.fgCol)
end
xPos = xPos + value.text:len() + space * 2
end
end end
end end
self.parent:setText(obx, oby, text:sub(itemOffset+1, self.width+itemOffset))
self.parent:setBG(obx, oby, textBGCol:sub(itemOffset+1, self.width+itemOffset))
self.parent:setFG(obx, oby, textFGCol:sub(itemOffset+1, self.width+itemOffset))
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -15,6 +15,7 @@ local function Pane(name)
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.bgColor) self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.bgColor)
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -534,15 +534,16 @@ local function Program(name)
return self return self
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then if (base.mouseHandler(self, event, button, x, y)) then
if (curProcess == nil) then if (curProcess == nil) then
return false return false
end end
if not (curProcess:isDead()) then if not (curProcess:isDead()) then
if not (paused) then if not (paused) then
local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true)) local absX, absY = self:getAbsolutePosition(self:getAnchorPosition(nil, nil, true))
curProcess:resume(event, button, x - absX + 1, y - absY + 1) curProcess:resume(event, button, x - (absX - 1), y - (absY - 1))
basalt.debug(event, button, x - (absX - 1), y - (absY - 1))
end end
end end
return true return true
@@ -630,9 +631,12 @@ local function Program(name)
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
pWindow.basalt_reposition(obx, oby) pWindow.basalt_reposition(obx, oby)
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) if(self.bgColor~=false)then
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
end
pWindow.basalt_update() pWindow.basalt_update()
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -62,7 +62,7 @@ local function Progressbar(name)
end; end;
progressDoneHandler = function(self) progressDoneHandler = function(self)
self:sendEvent("progress_done") self:sendEvent("progress_done", self)
end; end;
draw = function(self) draw = function(self)
@@ -90,6 +90,7 @@ local function Progressbar(name)
self.parent:drawTextBox(obx, oby, self.width / 100 * progress, self.height, activeBarSymbol) self.parent:drawTextBox(obx, oby, self.width / 100 * progress, self.height, activeBarSymbol)
end end
end end
self:setVisualChanged(false)
end end
end; end;

View File

@@ -80,7 +80,7 @@ local function Radio(name)
return self return self
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseHandler = function(self, event, button, x, y)
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if ((event == "mouse_click")and(button==1))or(event=="monitor_touch") then if ((event == "mouse_click")and(button==1))or(event=="monitor_touch") then
if (#list > 0) then if (#list > 0) then
@@ -116,6 +116,7 @@ local function Radio(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -61,8 +61,8 @@ local function Scrollbar(name)
return self return self
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then if (base.mouseHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
if (barType == "horizontal") then if (barType == "horizontal") then
@@ -121,6 +121,7 @@ local function Scrollbar(name)
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -3,6 +3,7 @@ local function Slider(name)
local objectType = "Slider" local objectType = "Slider"
base.width = 8 base.width = 8
base.height = 1
base.bgColor = colors.lightGray base.bgColor = colors.lightGray
base.fgColor = colors.gray base.fgColor = colors.gray
base:setValue(1) base:setValue(1)
@@ -13,6 +14,7 @@ local function Slider(name)
local bgSymbol = "\140" local bgSymbol = "\140"
local maxValue = base.width local maxValue = base.width
local index = 1 local index = 1
local symbolSize = 1
local object = { local object = {
getType = function(self) getType = function(self)
@@ -25,6 +27,22 @@ local function Slider(name)
return self return self
end; end;
setSymbolSize = function(self, size)
symbolSize = tonumber(size) or 1
if (barType == "vertical") then
self:setValue(index - 1 * (maxValue / (self.height - (symbolSize - 1))) - (maxValue / (self.height - (symbolSize - 1))))
elseif (barType == "horizontal") then
self:setValue(index - 1 * (maxValue / (self.width - (symbolSize - 1))) - (maxValue / (self.width - (symbolSize - 1))))
end
self:setVisualChanged()
return self
end;
setMaxValue = function(self, val)
maxValue = val
return self
end;
setBackgroundSymbol = function(self, _bgSymbol) setBackgroundSymbol = function(self, _bgSymbol)
bgSymbol = string.sub(_bgSymbol, 1, 1) bgSymbol = string.sub(_bgSymbol, 1, 1)
self:setVisualChanged() self:setVisualChanged()
@@ -42,63 +60,38 @@ local function Slider(name)
return self return self
end; end;
setValue = function(self, val) mouseHandler = function(self, event, button, x, y)
index = math.floor(val / maxValue) if (base.mouseHandler(self, event, button, x, y)) then
if (barType == "horizontal") then
if(index<1)then index = 1
elseif(index>self.width)then index = self.width end
base.setValue(self, maxValue / self.width * (index))
elseif (barType == "vertical") then
if(index<1)then index = 1
elseif(index>self.height)then index = self.height end
base.setValue(self, maxValue / self.height * (index))
end
return self
end;
setIndex = function(self, _index)
if (barType == "horizontal") then
if(_index>=1)and(_index<=self.width)then
index = _index
base.setValue(self, maxValue / self.width * (index))
end
elseif(barType == "vertical") then
if(_index>=1)and(_index<=self.height)then
index = _index
base.setValue(self, maxValue / self.height * (index))
end
end
return self
end;
mouseClickHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (barType == "horizontal") then if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then
for _index = 0, self.width - 1 do if (barType == "horizontal") then
if (obx + _index == x) and (oby <= y) and (oby + self.height > y) then for _index = 0, self.width do
index = _index + 1 if (obx + _index == x) and (oby <= y) and (oby + self.height > y) then
base.setValue(self, maxValue / self.width * (index)) index = math.min(_index + 1, self.width - (symbolSize - 1))
self:setVisualChanged() self:setValue(maxValue / self.width * (index))
self:setVisualChanged()
end
end
end
if (barType == "vertical") then
for _index = 0, self.height do
if (oby + _index == y) and (obx <= x) and (obx + self.width > x) then
index = math.min(_index + 1, self.height - (symbolSize - 1))
self:setValue(maxValue / self.height * (index))
self:setVisualChanged()
end
end end
end end
end end
if (barType == "vertical") then if (event == "mouse_scroll") then
for _index = 0, self.height - 1 do index = index + button
if (oby + _index == y) and (obx <= x) and (obx + self.width > x) then if (index < 1) then
index = _index + 1 index = 1
base.setValue(self, maxValue / self.height * (index))
self:setVisualChanged()
end
end end
index = math.min(index, (barType == "vertical" and self.height or self.width) - (symbolSize - 1))
self:setValue(maxValue / (barType == "vertical" and self.height or self.width) * index)
end end
--[[if(event=="mouse_scroll")then return true
self:setValue(self:getValue() + (maxValue/(barType=="vertical" and self.height or self.width))*typ)
self:setVisualChanged()
end
if(self:getValue()>maxValue)then self:setValue(maxValue) end
if(self:getValue()<maxValue/(barType=="vertical" and self.height or self.width))then self:setValue(maxValue/(barType=="vertical" and self.height or self.width)) end
]]
end end
end; end;
@@ -108,23 +101,28 @@ local function Slider(name)
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
if (barType == "horizontal") then if (barType == "horizontal") then
self.parent:writeText(obx, oby, bgSymbol:rep(index - 1), self.bgColor, self.fgColor) self.parent:writeText(obx, oby, bgSymbol:rep(index - 1), self.bgColor, self.fgColor)
self.parent:writeText(obx + index - 1, oby, symbol, symbolColor, symbolColor) self.parent:writeText(obx + index - 1, oby, symbol:rep(symbolSize), symbolColor, symbolColor)
self.parent:writeText(obx + index, oby, bgSymbol:rep(self.width - (index)), self.bgColor, self.fgColor) self.parent:writeText(obx + index + symbolSize - 1, oby, bgSymbol:rep(self.width - (index + symbolSize - 1)), self.bgColor, self.fgColor)
end end
if (barType == "vertical") then if (barType == "vertical") then
for n = 0, self.height - 1 do for n = 0, self.height - 1 do
if (n + 1 == index) then
self.parent:writeText(obx, oby + n, symbol, symbolColor, symbolColor) if (index == n + 1) then
for curIndexOffset = 0, math.min(symbolSize - 1, self.height) do
self.parent:writeText(obx, oby + n + curIndexOffset, symbol, symbolColor, symbolColor)
end
else else
self.parent:writeText(obx, oby + n, bgSymbol, self.bgColor, self.fgColor) if (n + 1 < index) or (n + 1 > index - 1 + symbolSize) then
self.parent:writeText(obx, oby + n, bgSymbol, self.bgColor, self.fgColor)
end
end end
end end
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }
return setmetatable(object, base) return setmetatable(object, base)

View File

@@ -2,25 +2,45 @@ local function Switch(name)
local base = Object(name) local base = Object(name)
local objectType = "Switch" local objectType = "Switch"
base.width = 3 base.width = 2
base.height = 1 base.height = 1
base.bgColor = colors.lightGray base.bgColor = colors.lightGray
base.fgColor = colors.gray base.fgColor = colors.gray
base:setValue(false) base:setValue(false)
base:setZIndex(5) base:setZIndex(5)
local bgSymbol = colors.black
local inactiveBG = colors.red
local activeBG = colors.green
local object = { local object = {
getType = function(self) getType = function(self)
return objectType return objectType
end; end;
setSymbolColor = function(self, symbolColor)
bgSymbol = symbolColor
self:setVisualChanged()
return self
end;
mouseClickHandler = function(self, event, button, x, y) setActiveBackground = function(self, bgcol)
if (base.mouseClickHandler(self, event, button, x, y)) then activeBG = bgcol
self:setVisualChanged()
return self
end;
setInactiveBackground = function(self, bgcol)
inactiveBG = bgcol
self:setVisualChanged()
return self
end;
mouseHandler = function(self, event, button, x, y)
if (base.mouseHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
if (((event == "mouse_click") or (event == "mouse_drag")) and (button == 1))or(event=="monitor_touch") then if ((event == "mouse_click") and (button == 1))or(event=="monitor_touch") then
self:setValue(not self:getValue())
end end
return true return true
end end
@@ -30,8 +50,16 @@ local function Switch(name)
if (base.draw(self)) then if (base.draw(self)) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
if(self:getValue())then
self.parent:drawBackgroundBox(obx, oby, 1, self.height, activeBG)
self.parent:drawBackgroundBox(obx+1, oby, 1, self.height, bgSymbol)
else
self.parent:drawBackgroundBox(obx, oby, 1, self.height, bgSymbol)
self.parent:drawBackgroundBox(obx+1, oby, 1, self.height, inactiveBG)
end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -244,8 +244,8 @@ local function Textfield(name)
end end
end; end;
mouseClickHandler = function(self, event, button, x, y) mouseHandler = function(self, event, button, x, y)
if (base.mouseClickHandler(self, event, button, x, y)) then if (base.mouseHandler(self, event, button, x, y)) then
local obx, oby = self:getAbsolutePosition(self:getAnchorPosition()) local obx, oby = self:getAbsolutePosition(self:getAnchorPosition())
local anchx, anchy = self:getAnchorPosition() local anchx, anchy = self:getAnchorPosition()
if (event == "mouse_click")or(event=="monitor_touch") then if (event == "mouse_click")or(event=="monitor_touch") then
@@ -262,7 +262,7 @@ local function Textfield(name)
end end
end end
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex) self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
end end
end end
end end
@@ -280,7 +280,7 @@ local function Textfield(name)
end end
end end
if (self.parent ~= nil) then if (self.parent ~= nil) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex) self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
end end
end end
end end
@@ -297,7 +297,7 @@ local function Textfield(name)
if (self.parent ~= nil) then if (self.parent ~= nil) then
if (obx + textX - wIndex >= obx and obx + textX - wIndex <= obx + self.width) and (oby + textY - hIndex >= oby and oby + textY - hIndex <= oby + self.height) then if (obx + textX - wIndex >= obx and obx + textX - wIndex <= obx + self.width) and (oby + textY - hIndex >= oby and oby + textY - hIndex <= oby + self.height) then
self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex) self.parent:setCursor(true, anchx + textX - wIndex, anchy + textY - hIndex, self.fgColor)
else else
self.parent:setCursor(false) self.parent:setCursor(false)
end end
@@ -312,8 +312,12 @@ local function Textfield(name)
if (base.draw(self)) then if (base.draw(self)) then
if (self.parent ~= nil) then if (self.parent ~= nil) then
local obx, oby = self:getAnchorPosition() local obx, oby = self:getAnchorPosition()
self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor) if(self.bgColor~=false)then
self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.fgColor) self.parent:drawBackgroundBox(obx, oby, self.width, self.height, self.bgColor)
end
if(self.fgColor~=false)then
self.parent:drawForegroundBox(obx, oby, self.width, self.height, self.fgColor)
end
for n = 1, self.height do for n = 1, self.height do
local text = "" local text = ""
if (lines[n + hIndex - 1] ~= nil) then if (lines[n + hIndex - 1] ~= nil) then
@@ -328,6 +332,7 @@ local function Textfield(name)
self.parent:setText(obx, oby + n - 1, text) self.parent:setText(obx, oby + n - 1, text)
end end
end end
self:setVisualChanged(false)
end end
end; end;
} }

View File

@@ -6,6 +6,7 @@ local function Timer(name)
local repeats = 0 local repeats = 0
local timerObj local timerObj
local eventSystem = BasaltEvents() local eventSystem = BasaltEvents()
local timerIsActive = false
local object = { local object = {
name = name, name = name,
@@ -28,15 +29,24 @@ local function Timer(name)
end; end;
start = function(self) start = function(self)
if(timerIsActive)then
os.cancelTimer(timerObj)
end
repeats = savedRepeats repeats = savedRepeats
timerObj = os.startTimer(timer) timerObj = os.startTimer(timer)
timerIsActive = true
return self return self
end; end;
isActive = function(self)
return timerIsActive
end;
cancel = function(self) cancel = function(self)
if (timerObj ~= nil) then if (timerObj ~= nil) then
os.cancelTimer(timerObj) os.cancelTimer(timerObj)
end end
timerIsActive = false
return self return self
end; end;
@@ -46,7 +56,7 @@ local function Timer(name)
end; end;
eventHandler = function(self, event, tObj) eventHandler = function(self, event, tObj)
if (event == "timer") and (tObj == timerObj) then if event == "timer" and tObj == timerObj and timerIsActive then
eventSystem:sendEvent("timed_event", self) eventSystem:sendEvent("timed_event", self)
if (repeats >= 1) then if (repeats >= 1) then
repeats = repeats - 1 repeats = repeats - 1