changed eventHandler

- the event handler is now only listening to necessary events, which makes the overall event loop much smaller and makes other stuff also possible
- base frame is now auto. resizing
- setMoveable -> setMovable

Note: There may be some (ofc expected) bugs..
This commit is contained in:
Robert Jelic
2022-08-12 01:52:06 +02:00
parent 5f76a059cc
commit 6dcd4c2427
76 changed files with 1905 additions and 14981 deletions

View File

@@ -9,7 +9,7 @@ Here you can find information about how to use Basalt as well as examples of fun
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).
## Quick Demo
![Preview](https://media0.giphy.com/media/fvmNPshXKeU7FFA9iA/giphy.gif)
<img src="https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/basaltPreview2.gif" width="600">
## Questions & Bugs
@@ -21,4 +21,4 @@ Additionally, if you have questions about Basalt or how to make use of it, feel
Feel free to join our [discord](https://discord.gg/yNNnmBVBpE)!
<br><br>
<br><br>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

View File

@@ -2,7 +2,7 @@
To load the framework into your project, make use of the following code on top of your code.
```lua
local basalt = require("Basalt")
local basalt = require("basalt")
```
It does not matter if you have installed the single file version or the full folder project. <br>
@@ -43,11 +43,10 @@ The true keyword in the end is optional and would simply start BPM immediately.
Here is a fully functioning example of Basalt code
```lua
local basalt = require("Basalt") --> Load the Basalt framework
local basalt = require("basalt") --> 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
@@ -76,7 +75,7 @@ basalt.autoUpdate() --> Basalt#autoUpdate starts the event listener to detect us
```
If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above:
```lua
local basalt = require("Basalt")
local basalt = require("basalt")
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"

View File

@@ -6,9 +6,9 @@ This is just a script which helps you to setup your program to automatically ins
Here is a very basic one which just installs basalt.lua if don't exist:
```lua
--Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
local filePath = "basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
shell.run("pastebin run ESs1mg7P packed true "..filePath) -- this is an alternative to the wget command
shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt
```
@@ -18,7 +18,7 @@ This is a visual version, it asks the user if he wants to install basalt.lua (if
![](https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/installer.png)
```lua
--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
if not(fs.exists(filePath))then
local w,h = term.getSize()
term.clear()
@@ -51,7 +51,7 @@ if not(fs.exists(filePath))then
local event, p1,p2,p3,p4 = os.pullEvent()
if(event=="mouse_click")then
if(p3==math.floor(h/2+2))and(p2>=w/2-8)and(p2<=w/2-2)then
shell.run("pastebin run ESs1mg7P packed true "..filePath)
shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", ""))
_installerWindow.setVisible(false)
term.clear()
break

View File

@@ -171,8 +171,8 @@ end)
<button onClick="clickMe" text="Click me" />
```
## basalt.shedule
Shedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
## basalt.schedule
Schedules a function which gets called in a coroutine. After the coroutine is finished it will get destroyed immediatly. It's something like threads, but with some limits.
#### Parameters:
1. `function` a function which should get executed
@@ -181,11 +181,11 @@ Shedules a function which gets called in a coroutine. After the coroutine is fin
1. `function` it returns the function which you have to execute in order to start the coroutine
#### Usage:
* Creates a shedule which switches the color between red and gray
* Creates a schedule which switches the color between red and gray
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setText("Click me")
aButton:onClick(basalt.shedule(function(self)
aButton:onClick(basalt.schedule(function(self)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)

View File

@@ -399,11 +399,11 @@ local myFrame = basalt.createFrame():setScrollable():setImportantScroll(true)
*This is how you would implement frames via xml:
```xml
<frame>
<frame width="50%" bg="red">
<frame width="parent.w * 0.5" bg="red">
<button x="2" y="2" width="17" text="Example Button!"/>
</frame>
<frame x="50%+1" width="50%+1" bg="black">
<textfield bg="green" x="2" width="100%-2" />
<frame x="parent.w * 0.5 + 1" width="parent.w * 0.5 +1" bg="black">
<textfield bg="green" x="2" width="parent.w-2" />
</frame>
</frame>
```

View File

@@ -54,17 +54,17 @@ This is also possible with entire frames and its children objects. So keep that
## How To use XML
Here is a example on how to create a cool looking frame by using xml:
```xml
<frame width="50%" bg="gray" scrollable="true" importantScroll="true">
<button x="2" y="2" width="100%-2" bg="black" fg="lightGray" text="Example Button 1!"/>
<button x="2" y="6" width="100%-2" bg="black" fg="lightGray" text="Example Button 2!"/>
<button x="2" y="10" width="100%-2" bg="black" fg="lightGray" text="Example Button 3!"/>
<button x="2" y="14" width="100%-2" bg="black" fg="lightGray" text="Example Button 4!"/>
<button x="2" y="18" width="100%-2" bg="black" fg="lightGray" text="Example Button 5!"/>
<button x="2" y="22" width="100%-2" bg="black" fg="lightGray" text="Example Button 6!"/>
<button x="2" y="26" width="100%-2" bg="black" fg="lightGray" text="Example Button 7!"/>
<frame width="parent.w/2" bg="gray" scrollable="true" importantScroll="true">
<button x="2" y="2" width="parent.w-2" bg="black" fg="lightGray" text="Example Button 1!"/>
<button x="2" y="6" width="parent.w-2" bg="black" fg="lightGray" text="Example Button 2!"/>
<button x="2" y="10" width="parent.w-2" bg="black" fg="lightGray" text="Example Button 3!"/>
<button x="2" y="14" width="parent.w-2" bg="black" fg="lightGray" text="Example Button 4!"/>
<button x="2" y="18" width="parent.w-2" bg="black" fg="lightGray" text="Example Button 5!"/>
<button x="2" y="22" width="parent.w-2" bg="black" fg="lightGray" text="Example Button 6!"/>
<button x="2" y="26" width="parent.w-2" bg="black" fg="lightGray" text="Example Button 7!"/>
</frame>
<frame x="50%+1" width="50%+1" bg="black">
<textfield bg="gray" x="2" y="2" width="100%-2">
<frame x="parent.w/2+1" width="parent.w/2+1" bg="black">
<textfield bg="gray" x="2" y="2" width="parent.w-2">
<lines>
<line>This is line 1.</line>
<line>And this is line 2.</line>
@@ -79,4 +79,4 @@ local basalt = require("Basalt")
basalt.createFrame():addLayout("example.xml")
basalt.autoUpdate()
```
```