This commit is contained in:
Robert Jelic
2022-06-06 17:07:10 +02:00
13 changed files with 144 additions and 86 deletions

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

@@ -3,7 +3,7 @@
- [Quick Start](home/Quick-Start.md) - [Quick Start](home/Quick-Start.md)
- [Installer](home/installer) - [Installer](home/installer)
- Objects - Objects
- - [Object](objects/Object) - [Object](objects/Object)
- [Basalt](objects/Basalt) - [Basalt](objects/Basalt)
- [Button](objects/Button) - [Button](objects/Button)
- [Checkbox](objects/Checkbox) - [Checkbox](objects/Checkbox)
@@ -28,4 +28,4 @@
- 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)

View File

@@ -0,0 +1,63 @@
Here we will talk about mouse events and how you can manipulate them. There are 2 possible mouse events you can add to almost every visual object.
# onClick
`onClick(self, button, x, y)`<br>
The computercraft event which triggers this method is `mouse_click` and `monitor_touch`.
Any visual object can register onClick events.
Here is a example on how to add a onClick event to your button:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnClick()
basalt.debug("Button got clicked!")
end
button:onClick(buttonOnClick())
```
# onClickUp
`onClickUp(self, button, x, y)`<br>
The computercraft event which triggers this method is `mouse_up`.
Any visual object can register onClickUp events.
Here is a example on how to add a onClickUp event to your button:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnClick()
basalt.debug("Button got clicked!")
end
button:onClick(buttonOnClick)
function buttonOnRelease()
basalt.debug("Button got released!")
end
button:onClickUp(buttonOnRelease)
```
# onScroll
`onScroll(self, direction, x, y)`<br>
The computercraft event which triggers this method is `mouse_scroll`.
Any visual object can register a onScroll events.
Here is a example on how to add a onScroll event to your button:
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("myMainFrame"):show()
local button = mainFrame:addButton("myButton"):setPosition(3,3):setSize(12,3):setText("Click"):show()
function buttonOnScroll()
basalt.debug("Someone scrolls on me!")
end
button:onScroll(buttonOnScroll)
```

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

@@ -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

@@ -15,7 +15,7 @@ local basalt = dofile(filePath) -- here you can change the variablename in any v
## 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
@@ -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,8 @@
<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="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;

View File

@@ -68,8 +68,10 @@ Sets the frame's bar-text alignment
#### Parameters: #### Parameters:
1. `string` Can be supplied with "left", "center", or "right" 1. `string` Can be supplied with "left", "center", or "right"
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### 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
@@ -78,10 +80,13 @@ local mainFrame = myFrame:setBar("My first Frame!"):setBarTextAlign("right")
## showBar ## showBar
Toggles the frame's upper bar Toggles the frame's upper bar
#### Parameters: #### Parameters:
1. `boolean | nil` Whether the frame's bar is visible or if supplied `nil`, is automatically visible 1. `boolean | nil` Whether the frame's bar is visible or if supplied `nil`, is automatically visible
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### 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
@@ -90,10 +95,13 @@ local mainFrame = myFrame:setBar("Hello World!"):showBar()
## addMonitor ## addMonitor
adds a monitor to the active main frame. adds a monitor to the active main 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` returns a frame which you can use like normal frames
#### Usage: #### Usage:
* Adds a monitor to the mainFrame. Only as long as this frame is also the active Frame, the monitor will be shown. * Adds a monitor to the mainFrame. Only as long as this frame is also the active Frame, the monitor will be shown.
````lua ````lua
@@ -105,10 +113,13 @@ monitor1:setBar("Monitor 1"):showBar()
## setMonitorScale ## setMonitorScale
changes the monitor scale (almost the same as setTextScale()) changes the monitor scale (almost the same as setTextScale())
#### Parameters: #### 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) 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: #### Returns:
1. `monitor` The monitor being used 1. `monitor` The monitor being used
#### Usage: #### Usage:
* Changes the monitor scale to 2 * Changes the monitor scale to 2
````lua ````lua
@@ -124,8 +135,10 @@ Returns true if the user is currently holding the respective key down
#### Parameters: #### Parameters:
1. `number | string` - Any os.queueEvent("key") key, or you can use the following strings: "shift", "ctrl", "alt" 1. `number | string` - Any os.queueEvent("key") key, or you can use the following strings: "shift", "ctrl", "alt"
#### Returns: #### Returns:
1. `boolean` - Whether the user is holding the key down 1. `boolean` - Whether the user is holding the key down
#### Usage: #### Usage:
* Checks if the "shift" modifier is active on the myFrame frame * Checks if the "shift" modifier is active on the myFrame frame
````lua ````lua
@@ -150,8 +163,10 @@ Returns a child object of the frame
#### Parameters: #### Parameters:
1. `string` The name of the child object 1. `string` The name of the child object
#### Returns: #### Returns:
1. `object | nil` The object with the supplied name, or `nil` if there is no object present with the given name 1. `object | nil` The object with the supplied name, or `nil` if there is no object present with the given name
#### 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
@@ -161,10 +176,13 @@ local aButton = myFrame:getObject("myFirstButton")
## removeObject ## removeObject
Removes a child object from the frame Removes a child object from the frame
#### Parameters: #### Parameters:
1. `string` The name of the child object 1. `string` The name of the child object
#### Returns: #### Returns:
1. `boolean` Whether the object with the given name was properly removed 1. `boolean` Whether the object with the given name was properly removed
#### 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
@@ -177,8 +195,10 @@ Sets the currently focused object
#### Parameters: #### Parameters:
1. `object` The child object to focus on 1. `object` The child object to focus on
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### 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
@@ -187,10 +207,13 @@ myFrame:setFocusedObject(aButton)
```` ````
## removeFocusedObject ## removeFocusedObject
Removes the focus of the supplied object Removes the focus of the supplied object
#### Parameters: #### Parameters:
1. `object` The child object to remove focus from 1. `object` The child object to remove focus from
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### 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
@@ -200,9 +223,9 @@ myFrame:removeFocusedObject(aButton)
## getFocusedObject ## getFocusedObject
Gets the currently focused object Gets the currently focused object
#### Parameters:
#### Returns: #### Returns:
1. `object` The currently focused object 1. `object` 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
@@ -213,8 +236,10 @@ local focusedObject = myFrame:getFocusedObject()
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_
#### Parameters: #### Parameters:
1. `boolean` Whether the object is movable 1. `boolean` Whether the object is movable
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### Usage: #### Usage:
* Creates a frame with id "myFirstFrame" and makes it movable * Creates a frame with id "myFirstFrame" and makes it movable
````lua ````lua
@@ -227,8 +252,10 @@ local myFrame = basalt.createFrame("myFirstFrame"):setMovable(true)
Sets whether the frame can be moved. _In order to move the frame use the upper bar of the frame_ Sets whether the frame can be moved. _In order to move the frame use the upper bar of the frame_
#### Parameters: #### Parameters:
1. `boolean` Whether the object is movable 1. `boolean` Whether the object is movable
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### Usage: #### Usage:
* Creates a frame with id "myFirstFrame" and makes it movable * Creates a frame with id "myFirstFrame" and makes it movable
````lua ````lua
@@ -244,8 +271,10 @@ The function can be supplied negative offsets
#### Parameters: #### Parameters:
1. `number` The x direction offset (+/-) 1. `number` The x direction offset (+/-)
2. `number` The y direction offset (+/-) 2. `number` The y direction offset (+/-)
#### Returns: #### Returns:
1. `frame` The frame being used 1. `frame` The frame being used
#### 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

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

@@ -18,7 +18,7 @@ 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