Basalt 1.7 Update

- New Objects (Flexbox, Graph, Treeview)
- Pluginsystem to add/remove functionality
- Reworked the entire Object system, instead of one big Object Class we have multiple classes: Object, VisualObject, ChangeableObject
- Instead of one big Frame Class we have multiple Frame Classes: BaseFrame, Frame, MovableFrame, ScrollableFrame, MonitorFrame, Flexbox
- Removed the Animation Object, and added a animation plugin instead
- Removed the Graphic Object and merged it's functionality with the image object
- Updated currently existing objects
This commit is contained in:
Robert Jelic
2023-04-30 17:05:34 +02:00
parent e086c1abb2
commit bb1b1beb79
341 changed files with 15541 additions and 3862 deletions

View File

@@ -2,11 +2,18 @@
*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.
Basalt is a user-friendly UI framework for CC:Tweaked (also known as "ComputerCraft: Tweaked") - a popular Minecraft mod. It was developed to enhance user interaction through visual displays. In this wiki, you'll find information on how to use Basalt as well as examples of functional Basalt code.
## About Basalt
Basalt is intended to be an easy-to-understand UI Framework designed for CC:Tweaked (Also known as "ComputerCraft: Tweaked") - a popular minecraft mod. For more information about CC:Tweaked, checkout the project's [wiki](https://tweaked.cc/) or [download](https://modrinth.com/mod/cc-tweaked).
Basalt is an easy-to-understand UI framework designed to improve user interaction with CC:Tweaked. Some of its key features include:
- A set of pre-built UI components for creating interfaces quickly and easily.
- A flexible layout system that allows users to create custom designs.
- A powerful event handling system for managing user input and interaction.
- Support for multiple screen resolutions and aspect ratios.
- Extensive documentation and examples to help users get started quickly.
## Quick Demo

View File

@@ -1,3 +1 @@
---
Thanks for checking out our wiki, join our discord for more help: [discord.gg/yM7kndJdJJ](discord.gg/yNNnmBVBpE)
Thanks for checking out our wiki, join our discord for more help: [discord.gg/yM7kndJdJJ](discord.gg/yM7kndJdJJ)

View File

@@ -2,29 +2,38 @@
- [Home](home)
- [How To](home/How-To)
- [Download](home/download)
- [1.6 Docs](docs1_6)
- Objects
- [Basalt](objects/Basalt.md)
- [Object](objects/Object.md)
- [VisualObject](objects/VisualObject.md)
- [ChangeableObject](objects/ChangeableObject.md)
- [Container](objects/Container.md)
- [BaseFrame](objects/BaseFrame.md)
- [Frame](objects/Frame.md)
- [Flexbox](objects/Flexbox.md)
- [MovableFrame](objects/MovableFrame.md)
- [ScrollableFrame](objects/ScrollableFrame.md)
- [Button](objects/Button.md)
- [Checkbox](objects/Checkbox.md)
- [Dropdown](objects/Dropdown.md)
- [Frame](objects/Frame.md)
- [Graph](objects/Graph.md)
- [Image](objects/Image.md)
- [Input](objects/Input.md)
- [Label](objects/Label.md)
- [List](objects/List.md)
- [Menubar](objects/Menubar.md)
- [Dropdown](objects/Dropdown.md)
- [Menubar](objects/Menubar.md)
- [Radio](objects/Radio.md)
- [Pane](objects/Pane.md)
- [Program](objects/Program.md)
- [Progressbar](objects/Progressbar.md)
- [Radio](objects/Radio.md)
- [Scrollbar](objects/Scrollbar.md)
- [Slider](objects/Slider.md)
- [Textfield](objects/Textfield.md)
- [Animation](objects/Animation.md)
- [Thread](objects/Thread.md)
- [Treeview](objects/Treeview.md)
- [Timer](objects/Timer.md)
- Tips & Tricks
- Tutorials
- [Your Logic](tips/logic.md)
- [Button coloring](tips/buttonColoring.md)
- [Designing/Animating](tips/design.md)

0
docs/docs1_6/.nojekyll Normal file
View File

1
docs/docs1_6/CNAME Normal file
View File

@@ -0,0 +1 @@
basalt.madefor.cc

26
docs/docs1_6/Home.md Normal file
View File

@@ -0,0 +1,26 @@
# Welcome to The old Basalt Wiki!
This Basalt Wiki is outdated!
*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.
## About Basalt
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
<img src="https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/_media/basaltPreview2.gif" width="600">
## Questions & Bugs
Obviously NyoriE has implemented some easter eggs, *some people* call them "bugs". If you happen to discover one of these just make a new <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/Pyroxenium/Basalt/discussions">Basalt's Discussion Board</a>, or ask in our [discord](https://discord.gg/yNNnmBVBpE).
---
Feel free to join our [discord](https://discord.gg/yNNnmBVBpE)!
<br><br>

1
docs/docs1_6/_footer.md Normal file
View File

@@ -0,0 +1 @@
Thanks for checking out our wiki, join our discord for more help: [discord.gg/yM7kndJdJJ](discord.gg/yM7kndJdJJ)

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

4
docs/docs1_6/_navbar.md Normal file
View File

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

35
docs/docs1_6/_sidebar.md Normal file
View File

@@ -0,0 +1,35 @@
- About
- [Home](Home.md)
- [Quick Start](home/Quick-Start.md)
- [Installer](home/installer)
- Objects
- [Basalt](objects/Basalt)
- [Object](objects/Object)
- [Button](objects/Button)
- [Checkbox](objects/Checkbox)
- [Dropdown](objects/Dropdown)
- [Frame](objects/Frame)
- [Image](objects/Image)
- [Input](objects/Input)
- [Label](objects/Label)
- [List](objects/List)
- [Menubar](objects/Menubar)
- [Pane](objects/Pane)
- [Program](objects/Program)
- [Progressbar](objects/Progressbar)
- [Radio](objects/Radio)
- [Scrollbar](objects/Scrollbar)
- [Slider](objects/Slider)
- [Textfield](objects/Textfield)
- [Animation](objects/Animation.md)
- [Thread](objects/Thread)
- [Timer](objects/Timer)
- Events
- [Mouse Events](events/mouseEvents.md)
- [Keyboard Events](events/keyEvents.md)
- [Other Events](events/otherEvents.md)
- Tips & Tricks
- [Component Logic](tips/logic)
- [Changing Button Color](tips/buttons)
- [Advanced usage of Events](tips/events.md)
- [Example Designs](tips/design.md)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
docs/docs1_6/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@@ -0,0 +1,92 @@
## HowTo Use
To load the framework into your project, make use of the following code on top of your code.
```lua
local basalt = require("basalt")
```
It does not matter if you have installed the single file version or the full folder project. <br>
Both versions can be loaded by using `require("Basalt")`, you dont need to add `.lua`.
## Download
### Download the folder version
This version is for people who'd like to work with Basalt, change something in Basalt or checkout the project.<br>
But you are also able to just use it to create your own UI.<br>
To install the full project to your CC:Tweaked Computer, use the following command on your CC:Tweaked shell:
`pastebin run ESs1mg7P`
This will download the project as a folder called "Basalt". You are immediatly after the download is done able to use it in your projects.
### Download the single file version
This is the version you should use if you're done with programming. It is a little bit faster and it is also minified, which makes the project smaller.
To install the single filed project to your CC:Tweaked Computer, use the following command on your CC:Tweaked shell:
`pastebin run ESs1mg7P packed`
This will download the project as a single file called "basalt.lua". You are immediatly after the download is done able to use it in your projects.
### Basalt Package Manager
The Basalt Package Manager is still in alpha!<br><br>
The Basalt Package Manager is a visual installer, you are able to change some settings, also to choose which objects are necessary for your projects and which are not.
To install the BPM (Basalt Package Manager) use the following command on your CC:Tweaked shell:
`pastebin run ESs1mg7P bpm true`
The true keyword in the end is optional and would simply start BPM immediately.
## Example
Here is a fully functioning example of Basalt code
```lua
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
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 = 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"
: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

@@ -0,0 +1,74 @@
# Installer
This is just a script which helps you to setup your program to automatically install the Basalt UI Framework, if it doesn't exists. Means, you create your program (which requires basalt) and add this on the top of your program. Now, everytime you execute your program it checks if basalt.lua (or your custom filepath) exists or not, if not it installs it, or if you are using the advanced installer, it asks the user if the program is allowed to install basalt for you.
## Basic Installer
Here is a very basic one which just installs basalt.lua if don't exist:
```lua
--Basalt configurated installer
local filePath = "basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
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
```
## Advanced Installer
This is a visual version, it asks the user if he wants to install basalt.lua (if not found)<br>
![](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
if not(fs.exists(filePath))then
local w,h = term.getSize()
term.clear()
local _installerWindow = window.create(term.current(),w/2-8,h/2-3,18,6)
_installerWindow.setBackgroundColor(colors.gray)
_installerWindow.setTextColor(colors.black)
_installerWindow.write(" Basalt Installer ")
_installerWindow.setBackgroundColor(colors.lightGray)
for line=2,6,1 do
_installerWindow.setCursorPos(1,line)
if(line==3)then
_installerWindow.write(" No Basalt found! ")
elseif(line==4)then
_installerWindow.write(" Install it? ")
elseif(line==6)then
_installerWindow.setTextColor(colors.black)
_installerWindow.setBackgroundColor(colors.gray)
_installerWindow.write("Install")
_installerWindow.setBackgroundColor(colors.lightGray)
_installerWindow.write(string.rep(" ",5))
_installerWindow.setBackgroundColor(colors.red)
_installerWindow.write("Cancel")
else
_installerWindow.write(string.rep(" ",18))
end
end
_installerWindow.setVisible(true)
_installerWindow.redraw()
while(not(fs.exists(filePath))) do
local event, p1,p2,p3,p4 = os.pullEvent()
if(event=="mouse_click")then
if(p3==math.floor(h/2+2))and(p2>=w/2-8)and(p2<=w/2-2)then
shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", ""))
_installerWindow.setVisible(false)
term.clear()
break
end
if(p3==math.floor(h/2+2))and(p2<=w/2+9)and(p2>=w/2+4)then
_installerWindow.clear()
_installerWindow.setVisible(false)
term.setCursorPos(1,1)
term.clear()
return
end
end
end
term.setCursorPos(1,1)
term.clear()
end
local basalt = require(filePath:gsub(".lua", "")) -- here you can change the variablename in any variablename you want default: basalt
------------------------------
```

54
docs/docs1_6/index.html Normal file
View File

@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Basalt Documentation</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Basalt is an easy-to-understand UI Framework designed for CC:Tweaked - a popular minecraft mod. ">
<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="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>
:root {
--theme-color: #16CC27;
--mono-hue: 120;
--mono-saturation: 1%;
--mono-shade3: hsl(var(--mono-hue), var(--mono-saturation), 5%);
--mono-shade2: hsl(var(--mono-hue), var(--mono-saturation), 6%);
--mono-shade1: hsl(var(--mono-hue), var(--mono-saturation), 7%);
--mono-base: hsl(var(--mono-hue), var(--mono-saturation), 20%);
--mono-tint1: hsl(var(--mono-hue), var(--mono-saturation), 25%);
--mono-tint2: hsl(var(--mono-hue), var(--mono-saturation), 30%);
--mono-tint3: hsl(var(--mono-hue), var(--mono-saturation), 35%);
--base-background-color: hsl(var(--mono-hue), var(--mono-saturation), 10%);
--sidebar-nav-pagelink-background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='7' height='11.2' viewBox='0 0 7 11.2'%3E%3Cpath d='M1.5 1.5l4 4.1 -4 4.1' stroke-width='1.5' stroke='%23575d5e' fill='none' stroke-linecap='square' stroke-linejoin='miter' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
--sidebar-nav-pagelink-background-image--active: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11.2' height='7' viewBox='0 0 11.2 7'%3E%3Cpath d='M1.5 1.5l4.1 4 4.1-4' stroke-width='1.5' stroke='%23575d5e' fill='none' stroke-linecap='square' stroke-linejoin='miter' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
--sidebar-nav-pagelink-background-image--collapse: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='7' height='11.2' viewBox='0 0 7 11.2'%3E%3Cpath d='M1.5 1.5l4 4.1 -4 4.1' stroke-width='1.5' stroke='%23575d5e' fill='none' stroke-linecap='square' stroke-linejoin='miter' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
--sidebar-nav-pagelink-background-image--loaded: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11.2' height='7' viewBox='0 0 11.2 7'%3E%3Cpath d='M1.5 1.5l4.1 4 4.1-4' stroke-width='1.5' stroke='%23575d5e' fill='none' stroke-linecap='square' stroke-linejoin='miter' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
}
</style>
</head>
<body>
<div id="app">Did you know: Basalt is a Pyroxene?></div>
<script>
window.$docsify = {
logo: '/_media/logo.png',
loadNavbar: true,
loadSidebar: true,
autoHeader: true,
subMaxLevel: 1,
homepage: 'Home.md',
name: 'Basalt',
repo: 'https://github.com/Pyroxenium/Basalt',
auto2top: true
}
</script>
<!-- Docsify v4 -->
<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="//cdn.jsdelivr.net/npm/prismjs@1.28.0/components/prism-lua.min.js"></script>
</body>
</html>

View File

@@ -0,0 +1,303 @@
With animations, you can create a beautiful experience for users while interacting with objects.<br>
For now the animation class is very basic, it will be expanded in the future, but we have to say you can already do almost everything you can imagine!
Right now animation is a class which makes use of the timer event.<br>
You can find more information below:
`The animation object is still a WIP and the way you use it right now could change in the future!`
## add
Adds a new function to an animation
#### Parameters:
1. `function` The function containing animation logic
#### Returns:
1. `animation` Animation in use
#### Usage:
* This will set the button position to 3,3, waits 1 second, then sets position to 4,4, waits 2 seconds, and then sets the position to 5,5
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():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()
```
## wait
Sets a wait timer for the next function after the previous function got executed, no wait timer calls the next function immediately
#### Parameters:
1. `number` The length of delay between the functions _(in seconds)_
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():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()
```
## play
Plays the animation
#### Parameters:
1. `boolean` Whether it will loop forever, will most likely be replaced with a count in the future
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():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
```
## cancel
Cancels the animation
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():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()
```
## setObject
Sets the object which the animation should reposition/resize
#### Parameters:
1. `table` object
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton()
local aAnimation = mainFrame:addAnimation():setObject(testButton)
```
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
```
```xml
<animation object="buttonToAnimate" />
```
## move
Moves the object which got defined by setObject
#### Parameters:
1. `number` x coordinate
2. `number` y coordinate
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
* Takes 2 seconds to move the object from its current position to x15 y3
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):move(15,3,2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<move><x>15</x><y>6</y><duration>2</duration></move>
</animation>
```
## offset
Changes the offset on the object which got defined by setObject
#### Parameters:
1. `number` x offset
2. `number` y offset
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local subFrame = mainFrame:addFrame("frameToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(subFrame):offset(1,12,1):play()
```
```xml
<animation object="frameToAnimate" play="true">
<offset><x>1</x><y>12</y><duration>1</duration></offset>
</animation>
```
## size
Changes the size on the object which got defined by setObject
#### Parameters:
1. `number` width
2. `number` height
3. `number` duration in seconds
4. `number` time - time when this part should begin (offset to when the animation starts - default 0)
5. `table` object - optional, you could also define the object here
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):size(15,3,1):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<offset><w>15</w><h>3</h><duration>1</duration></offset>
</animation>
```
## changeText
Changes the text while animation is running
#### Parameters:
1. `table` multiple text strings - example: {"i", "am", "groot"}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeText({"i", "am", "groot"}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<text>
<text>i</text>
<text>am</text>
<text>groot</text>
<duration>2</duration>
</text>
</animation>
```
## changeTextColor
Changes the text color while the animation is running
#### Parameters:
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<textColor>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</textColor>
</animation>
```
## changeBackground
Changes the background color while the animation is running
#### Parameters:
1. `table` multiple color numbers - example: {colors.red, colors.yellow, colors.green}
2. `number` duration in seconds
3. `number` time - time when this part should begin (offset to when the animation starts - default 0)
#### Returns:
1. `animation` Animation in use
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
```
```xml
<animation object="buttonToAnimate" play="true">
<background>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</background>
</animation>
```
# Events
## onDone
`onDone(self)`<br>
This is a event which gets fired as soon as the animation has finished.
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame()
local testButton = mainFrame:addButton("buttonToAnimate")
local aAnimation = mainFrame:addAnimation():setObject(testButton):changeTextColor({colors.red, colors.yellow, colors.green}, 2):play()
aAnimation:onDone(function()
basalt.debug("The animation is done")
end)
```
In XML you are also able to queue multiple animations, like this:
```xml
<animation id="anim2" object="buttonToAnimate">
<textColor>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</textColor>
</animation>
<animation onDone="#anim2" object="buttonToAnimate" play="true">
<background>
<color>red</color>
<color>yellow</color>
<color>green</color>
<duration>2</duration>
</background>
</animation>
```

View File

@@ -0,0 +1,201 @@
Before you can access Basalt, you need to add the following code on top of your file:
`local basalt = require("Basalt")`
Now you are able to access the following methods:
## basalt.createFrame
Create a base-frame (main frame)
#### Parameters:
1. `string` name
#### Returns:
1. `frame` object
#### Usage:
* Create and show a frame with id "myFirstFrame"
```lua
local mainFrame = basalt.createFrame("myFirstFrame")
```
## basalt.removeFrame
Removes a base frame
#### Parameters:
1. `string` name
#### Usage:
* Removes the previously created frame with id "myFirstFrame"
```lua
local mainFrame = basalt.createFrame("myFirstFrame")
basalt.removeFrame("myFirstFrame")
```
## basalt.getFrame
Returns a base frame with the given name
#### Parameters:
1. `string` name
#### Returns:
1. `frame` object
#### Usage:
* Creates, fetches and shows the "myFirstFrame" object
```lua
basalt.createFrame("myFirstFrame"):hide()
basalt.getFrame("myFirstFrame"):show()
```
## basalt.getActiveFrame
Returns the currently active base frame
#### Returns:
1. `frame` The current frame
#### Usage:
* Displays the active frame name in the debug console
```lua
basalt.createFrame()
basalt.debug(basalt.getActiveFrame():getName()) -- returns the uuid
```
## basalt.autoUpdate
Starts the draw and event handler until basalt.stopUpdate() is called
#### Usage:
* Enable the basalt updates, otherwise the screen will not continue to update
```lua
local mainFrame = basalt.createFrame()
basalt.autoUpdate()
```
## basalt.update
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:
1. `string` The event to be received
2. `...` Additional event variables to capture
#### Usage:
* Creates and starts a custom update cycle
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setPosition(2,2)
while true do
basalt.update(os.pullEventRaw())
end
```
## basalt.stopUpdate
Stops the automatic draw and event handler which got started by basalt.autoUpdate()
#### Usage:
* When the quit button is clicked, the button stops basalt auto updates
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setPosition(2,2):setText("Stop Basalt!")
aButton:onClick(function()
basalt.stopUpdate()
end)
basalt.autoUpdate()
```
## basalt.isKeyDown
Checks if the user is currently holding a key
#### Parameters:
1. `number` key code (use the keys table for that)
#### Returns:
1. `boolean` true or false
#### Usage:
* Shows a debug message with true or false if the left ctrl key is down, as soon as you click on the button.
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setPosition(2,2):setText("Check Ctrl")
aButton:onClick(function()
basalt.debug(basalt.isKeyDown(keys.leftCtrl))
end)
basalt.autoUpdate()
```
## 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
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:
1. `...` (multiple parameters are possible, like print does)
#### Usage:
* Prints "Hello! ^-^" to the debug console
```lua
basalt.debug("Hello! ", "^-^")
```
## basalt.setTheme
Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua)
#### Parameters:
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
#### Usage:
* Sets the default theme of basalt.
```lua
basalt.setTheme({
ButtonBG = colors.yellow,
ButtonText = colors.red,
...,
})
```
## basalt.setVariable
This stores a variable which you're able to access via xml. You are also able to add a function, which then gets called by object events created in XML.
#### Parameters:
1. `string` a key name
1. `any` any variable
#### Usage:
* Adds a function to basalt.
```lua
basalt.setVariable("clickMe", function()
basalt.debug("I got clicked")
end)
```
```xml
<button onClick="clickMe" text="Click me" />
```
## 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
#### Returns:
1. `function` it returns the function which you have to execute in order to start the coroutine
#### Usage:
* 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.schedule(function(self)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
os.sleep(0.1)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
os.sleep(0.1)
self:setBackground(colors.red)
os.sleep(0.1)
self:setBackground(colors.gray)
end))
```

View File

@@ -0,0 +1,91 @@
Buttons are objects, which execute something by clicking on them.<br>
Remember button also inherits from [Object](objects/Object.md)
## setText
Sets the displayed button text
#### Parameters:
1. `string` the text the button should show
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a button with "Click me!" as text.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton():setText("Click me!")
```
```xml
<button text="Click me!" />
```
## setHorizontalAlign
Sets the horizontal align of the button text
#### Parameters:
1. `string` the position as string ("left", "center", "right") - default is center.
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button's horizontal text align to right.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
```
```xml
<button text="Click me!" horizontalAlign="right" />
```
## setVerticalAlign
Sets the vertical align of the button text
#### Parameters:
1. `string` the position as string ("top", "center", "bottom") - default is center.
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button's horizontal text align to right and the vertical text align to bottom.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
:setVerticalAlign("bottom")
```
```xml
<button text="Click me!" horizontalAlign="right" verticalAlign="bottom" />
```
# Example
This is a example on how you would create a fully working button:
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setText("Click")
aButton:onClick(function(self,event,button,x,y)
if(event=="mouse_click")and(button==1)then
basalt.debug("Left mousebutton got clicked!")
end
end)
```
and this would be the xml way to do it:
```lua
local mainFrame = basalt.createFrame():addLayout("example.xml")
basalt.setVariable("buttonClick", function(self,event,button,x,y)
if(event=="mouse_click")and(button==1)then
basalt.debug("Left mousebutton got clicked!")
end
end)
```
```xml
<button onClick="buttonClick" text="Click" />
```

View File

@@ -0,0 +1,33 @@
With checkbox objects the user can set a bool to true or false
Remember checkbox also inherits from [Object](objects/Object.md)
A checkbox does not have any custom methods. All required methods are provided by the base [object](objects/Object.md) class.
# Example
This is how you would create a event which gets fired as soon as the value gets changed:
```lua
local mainFrame = basalt.createFrame()
local aCheckbox = mainFrame:addCheckbox()
local function checkboxChange(self)
local checked = self:getValue()
basalt.debug("The value got changed into ", checked)
end
aCheckbox:onChange(checkboxChange)
```
also possible via xml:
```lua
local mainFrame = basalt.createFrame():addLayout("example.xml")
basalt.setVariable("checkboxChange", function(self)
local checked = self:getValue()
basalt.debug("The value got changed into ", checked)
end)
```
```xml
<checkbox onChange="checkboxChange" />
```

View File

@@ -0,0 +1,307 @@
Dropdowns are objects where the user can click on a button, this will open a list where the user can choose from.
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 = {}
}
```
Remember Dropdown also inherits from [Object](objects/Object.md)
## addItem
Adds a item into the dropdown
#### Parameters:
1. `string` The entry name
2. `number|color` unique default background color - optional
3. `number|color` unique default text color - optional
4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
```
```xml
<dropdown>
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>3. Entry</text><bg>yellow</bg><fg>green</fg></item>
</dropdown>
```
## removeItem
Removes a item from the dropdown
#### Parameters:
1. `number` The index which should get removed
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and removes the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:removeItem(2)
```
## editItem
Edits a item from the dropdown
#### Parameters:
1. `number` The index which should be edited
2. `string` The new item name
3. `number` the new item background color - optional
4. `number` The new item text color - optional
5. `any` New additional information - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown: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 dropdown with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getItem(2).text)
```
## getItemCount
Returns the current item count
#### Returns:
1. `number` The item list count
#### Usage:
* Creates a default dropdown with 3 entries and prints the current item count.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown: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()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aDropdown:getAll())
```
## selectItem
selects a item in the dropdown (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 dropdown with 3 entries and selects the second entry.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:selectItem(2)
```
## clear
Removes all items.
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown with 3 entries and removes them immediatley. Which makes no sense.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:clear()
```
## getItemIndex
returns the item index of the currently selected item
#### Returns:
1. `number` The current index
#### Usage:
* Creates a default dropdown with 3 entries selects the second entry and prints the currently selected index.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:selectItem(2)
basalt.debug(aDropdown: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 dropdown with 4 entries and sets the selection background color to green.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry",colors.yellow)
aDropdown:addItem("3. Entry",colors.yellow,colors.green)
aDropdown:addItem("4. Entry")
aDropdown:setSelectedItem(colors.green, colors.red)
```
```xml
<dropdown selectionBG="green" selectionFG="red">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>2. Entry</text><bg>yellow</bg><fg>green</fg></item>
</dropdown>
```
## setOffset
Sets the offset of the dropdown (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 dropdown with 6 entries and sets the offset to 3.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
```
```xml
<dropdown offset="3">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
<item><text>4. Entry</text></item>
<item><text>5. Entry</text></item>
<item><text>6. Entry</text></item>
</dropdown>
```
## getOffset
Returns the current index offset
#### Returns:
1. `number` offset value
#### Usage:
* Creates a default dropdown with 6 entries and sets the offset to 3, also prints the current offset.
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
basalt.debug(aDropdown:getOffset())
```
## setDropdownSize
Sets the size of the opened dropdown
#### Parameters:
1. `number` The width value
2. `number` The height value
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown, adds 3 entries and sets the dropdown size to 15w, 8h
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown():setDropdownSize(15,8)
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry")
aDropdown:addItem("3. Entry")
```
```xml
<dropdown dropdownWidth="15" dropdownHeight="8">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
</dropdown>
```

View File

@@ -0,0 +1,409 @@
<a href="https://i.imgur.com/aikc0K1.png"><img src="https://i.imgur.com/aikc0K1.png" height="500" /></a>
Frames are like containers, but are also normal objects.
In other words, you can add other objects _(even frames)_ to a frame; if the frame itself is visible
all sub-objects _(if they are set as visible)_ are also visible. A better description will follow.
## basalt.createFrame
Creates a new non-parent frame - in most cases it is the first thing you'll need.
#### Parameters:
1. `string` name (should be unique)
#### Returns:
1. `frame | nil` The frame created by createFrame, or `nil` if there is already a frame with the given name.
#### Usage:
* Create a frame with an id "myFirstFrame", stored in a variable named frame
```lua
local myFrame = basalt.createFrame("myFirstFrame")
```
## 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
#### Parameters:
1. `string` name (should be unique)
#### Returns:
1. `frame | nil` The frame created by addFrame, or `nil` if there is already a child frame with the given name.<br>
#### Usage:
* Create a new main frame and adds a child frame to it
```lua
local mainFrame = basalt.createFrame()
local myFrame = mainFrame:addFrame()
```
```xml
<frame></frame>
```
## setBar
Sets the text, background, and foreground of the upper bar of the frame, accordingly.
#### Parameters:
1. `string` The title text to set the bar to
2. `number` The background color
2. `number` The foreground color
#### Returns:
1. `frame` The frame being used
#### Usage:
* Set the title to "My first frame!", with a background of black and a foreground of light gray.
```lua
frame:setBar("My first Frame!", colors.black, colors.lightGray)
```
* Store the frame, use the named frame variable after assigning.
```lua
local mainFrame = basalt.createFrame()
local myFrame = MainFrame:addFrame()
myFrame:setBar("My first Frame!")
```
* This abuses the call-chaining that Basalt uses.
```lua
local mainFrame = basalt.createFrame()
local myFrame = mainFrame:addFrame():setBar("My first Frame!")
```
```xml
<frame barText="My first Frame!" barBG="black" barFG="lightGray"></frame>
```
## setBarTextAlign
Sets the frame's bar-text alignment
#### Parameters:
1. `string` Can be supplied with "left", "center", or "right"
#### Returns:
1. `frame` The frame being used
#### Usage:
* Set the title of myFrame to "My first frame!", and align it to the right.
```lua
myFrame:setBar("My first Frame!"):setBarTextAlign("right")
```
```xml
<frame barAlign="right"></frame>
```
## showBar
Toggles the frame's upper bar
#### Parameters:
1. `boolean | nil` Whether the frame's bar is visible or if supplied `nil`, is automatically visible
#### Returns:
1. `frame` The frame being used
#### Usage:
* Sets myFrame to have a bar titled "Hello World!" and subsequently displays it.
```lua
myFrame:setBar("Hello World!"):showBar()
```
```xml
<frame bar="true"></frame>
```
## setMonitor
Sets this frame as a monitor frame
#### Parameters:
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new monitor frame, you can use to show objects on a monitor.
```lua
local mainFrame = basalt.createFrame()
local monitorFrame = basalt.createFrame():setMonitor("right")
monitorFrame:setBar("Monitor 1"):showBar()
```
```xml
<frame monitor="right"></frame>
```
## setMirror
mirrors this frame to another peripheral monitor object.
#### Parameters:
1. `string` The monitor name ("right", "left",... "monitor_1", "monitor_2",...)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates mirror of your main frame to a monitor on the left side.
```lua
local mainFrame = basalt.createFrame():setMirror("left")
```
```xml
<frame mirror="left"></frame>
```
## getObject
Returns a child object of the frame
#### Parameters:
1. `string` The name of the child object
#### Returns:
1. `object | nil` The object with the supplied name, or `nil` if there is no object present with the given name
#### Usage:
* Adds a button with id "myFirstButton", then retrieves it again through the frame object
```lua
myFrame:addButton("myFirstButton")
local aButton = myFrame:getObject("myFirstButton")
```
## removeObject
Removes a child object from the frame
#### Parameters:
1. `string` The name of the child object
#### Returns:
1. `boolean` Whether the object with the given name was properly removed
#### Usage:
* Adds a button with the id "myFirstButton", then removes it with the aforementioned id
```lua
myFrame:addButton("myFirstButton")
myFrame:removeObject("myFirstButton")
```
## setFocusedObject
Sets the currently focused object
#### Parameters:
1. `object` The child object to focus on
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new button, sets the focused object to the previously mentioned button
```lua
local aButton = myFrame:addButton()
myFrame:setFocusedObject(aButton)
```
## removeFocusedObject
Removes the focus of the supplied object
#### Parameters:
1. `object` The child object to remove focus from
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new button then removes the focus from that button when clicking on it
```lua
local aButton = myFrame:addButton():setFocus():onClick(function()
myFrame:removeFocusedObject(aButton)
end)
```
## getFocusedObject
Gets the currently focused object
#### Returns:
1. `object` The currently focused object
#### Usage:
* Gets the currently focused object from the frame, storing it in a variable
```lua
local focusedObject = myFrame:getFocusedObject()
```
## setMovable
Sets whether the frame can be moved. _In order to move the frame click and drag 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():setMovable(true)
```
```xml
<frame moveable="true"></frame>
```
## setOffset
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)
The function can also be supplied with negative values
#### Parameters:
1. `number` The x direction offset (+/-)
2. `number` The y direction offset (+/-)
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame with x offset of 5 and a y offset of 3
```lua
local myFrame = basalt.createFrame():setOffset(5, 3)
```
* Creates with 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
local myFrame = basalt.createFrame():setOffset(5, -5)
```
```xml
<frame xOffset="5" yOffset="-5"></frame>
```
## addLayout
Adds a new XML Layout into your frame.
#### Parameters:
1. `string` Path to your layout
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds the mainframe.xml layout
```lua
local myFrame = basalt.createFrame():addLayout("mainframe.xml")
```
```xml
<frame layout="mainframe.xml"></frame>
```
## addLayoutFromString
Adds a new XML Layout as string into your frame.
#### Parameters:
1. `string` xml
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds the mainframe.xml layout
```lua
local myFrame = basalt.createFrame():addLayoutFromString("<button x='12' y='5' bg='black' />")
```
## getLastLayout
returns a table of all objects this frame has created via xml (useful if you'd like to access all of them for some reason)
#### Returns:
1. `table` table with objects
## setTheme
Sets the default theme of that frame children objects always try to get the theme of its parent frame, if it does not exist it goes to its parent parent frame, and so on until it reaches the basalt managers theme - which is sotred in theme.lua (Please checkout [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for how it could look like.
#### Parameters:
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and adds a new theme which only changes the default color of buttons.
```lua
local myFrame = basalt.createFrame():setTheme({
ButtonBG = colors.yellow,
ButtonText = colors.red,
})
```
## setScrollable
Makes the frame scrollable with mousewheel.
#### Parameters:
1. `bool` scrollable or not
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable
```lua
local myFrame = basalt.createFrame():setScrollable()
```
```xml
<frame scrollable="true"></frame>
```
## setMinScroll
Sets the minimum offset it is allowed to scroll (default 0)
#### Parameters:
1. `number` minimum y offset
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable and sets the minimum amount to -5
```lua
local myFrame = basalt.createFrame():setScrollable():setMinScroll(-5)
```
```xml
<frame minScroll="-5"></frame>
```
## setMaxScroll
Sets the maximum offset it is allowed to scroll (default 10)
#### Parameters:
1. `number` maximum y offset
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable and sets the maximum amount to 25
```lua
local myFrame = basalt.createFrame():setScrollable():setMaxScroll(25)
```
```xml
<frame maxScroll="25"></frame>
```
## setImportantScroll
By default if you hovering your mouse over children objects, you wont scroll the frame, if you set this to true the frame scrolling becomes more important
#### Parameters:
1. `bool` important or not
#### Returns:
1. `frame` The frame being used
#### Usage:
* Creates a new base frame and makes it scrollable and defines it as important
```lua
local myFrame = basalt.createFrame():setScrollable():setImportantScroll(true)
```
```xml
<frame importantScroll="true"></frame>
```
# XML Example
*This is how you would implement frames via xml:
```xml
<frame>
<frame width="parent.w * 0.5" bg="red">
<button x="2" y="2" width="17" text="Example Button!"/>
</frame>
<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

@@ -0,0 +1,41 @@
The image object is for adding more advanced backgrounds.
It also provides a :shrink() function, where you can shrink the images to smaller ones. This functionallity is fully provided by the blittle library created by Bomb Bloke. I did not ask for permission to add it into the framework. If the creator wants me to remove the blittle part, just text me on discord!
The image object is still not done. in the future i will provide more image formats.
Remember image inherits from [Object](objects/Object.md)
## loadImage
loads a default .nfp file into the object.
#### Parameters:
1. `string` the absolute file path
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default image and loads a test.nfp file
```lua
local mainFrame = basalt.createFrame():show()
local aImage = mainFrame:addImage():loadImage("test.nfp")
```
```xml
<image path="test.nfp" />
```
## shrink
Shrinks the current image into a blittle image.
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default image and loads a test.nfp file
```lua
local mainFrame = basalt.createFrame()
local aImage = mainFrame:addImage():loadImage("test.nfp"):shrink()
```
```xml
<image path="test.nfp" shrink="true" />
```

View File

@@ -0,0 +1,91 @@
With input's you are able to create a object where the user can type something in.<br>
Here are all possible functions available for inputs:<br>
Remember Input inherits from [Object](objects/Object.md)
## setInputType
Changes the input type. default: text
#### Parameters:
1. `string` input type ("text", "password", "number")
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default input and sets it to numbers only.
```lua
local mainFrame = basalt.createFrame()
local aInput = mainFrame:addInput():setInputType("number")
```
```xml
<input type="number" />
```
## getInputType
Gets the current input type
#### Returns:
1. `string` input type
#### Usage:
* Creates a default input and sets it to numbers only. Also prints the current input type to log.
```lua
local mainFrame = basalt.createFrame()
local aInput = mainFrame:addInput():setInputType("number")
basalt.debug(aInput:getInputType())
```
## setDefaultText
Sets the default text. This will only be displayed if there is no input set by the user.
#### Parameters:
1. `string` input type ("text", "password", "number")
2. `number|color` default background color - optional
3. `number|color` default text color - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default input and sets the default text to "...".
```lua
local mainFrame = basalt.createFrame()
local aInput = mainFrame:addInput():setDefaultText("...")
```
```xml
<input default="..." />
```
## setInputLimit
Sets a character limit to the input.
#### Parameters:
1. `number` character limit
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default input and sets the character limit to 8.
```lua
local mainFrame = basalt.createFrame()
local aInput = mainFrame:addInput():setInputLimit(8)
```
```xml
<input limit="8" />
```
## getInputLimit
Returns the input limit.
#### Returns:
1. `number` character limit
#### Usage:
* Creates a default input and sets the character limit to 8. Prints the current limit.
```lua
local mainFrame = basalt.createFrame()
local aInput = mainFrame:addInput():setInputLimit(8)
basalt.debug(aInput:getInputLimit())
```

View File

@@ -0,0 +1,77 @@
A label is for adding simple text.
By default label's width is auto sizing based on the length of the text. If you change the size with setSize it will automatically stop autosizing the width.
The fontsize feature is calculated by bigfonts, a library made by Wojbie (http://www.computercraft.info/forums2/index.php?/topic/25367-bigfont-api-write-bigger-letters-v10/)
Here are all possible functions available for labels.<br>
Remember Label inherits from [Object](objects/Object.md)
## setText
Sets the text which gets displayed.
#### Parameters:
1. `string` The text which should be displayed
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default label with text "Some random text".
```lua
local mainFrame = basalt.createFrame()
local aLabel = mainFrame:addLabel():setText("Some random text")
```
```xml
<label text="Some random text" />
```
## setFontSize
Sets the font size, calculated by bigfonts. Default size is 1.
#### Parameters:
1. `number` The size (1, 2, 3, 4)
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default label, sets the text to "Basalt!" and its font size to 2.
```lua
local mainFrame = basalt.createFrame()
local aLabel = mainFrame:addLabel():setText("Basalt!"):setFontSize(2)
```
```xml
<label font="2" />
```
## getFontSize
Returns the current font size
#### Returns:
1. `number` font size
#### Usage:
* Creates a default label, sets the text to "Basalt!" and its font size to 2. Also prints the current fontsize.
```lua
local mainFrame = basalt.createFrame()
local aLabel = mainFrame:addLabel():setText("Basalt!"):setFontSize(2)
basalt.debug(aLabel:getFontSize())
```
## setTextAlign
Changes the text align
#### Returns:
1. `string` horizontal ("left", "center", "right")
1. `string` vertical ("top", "center", "bottom")
#### Usage:
* Creates a default label, sets the text to "Basalt!" changes the horizontal align to right
```lua
local mainFrame = basalt.createFrame()
local aLabel = mainFrame:addLabel():setText("Basalt!"):setTextAlign("right")
```
```xml
<label horizontalAlign="right" verticalAlign="center" />
```

View File

@@ -0,0 +1,279 @@
Lists are objects where you can create endless entries, and the user is able to select one of them
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 = {}
}
```
Remember Lists also inherits from [Object](objects/Object.md)
## addItem
Adds a item into the list
#### Parameters:
1. `string` The entry name
2. `number|color` unique default background color - optional
3. `number|color` unique default text color - optional
4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default list with 3 entries
```lua
local mainFrame = basalt.createFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
```
```xml
<list>
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>3. Entry</text><bg>yellow</bg><fg>green</fg></item>
</list>
```
## removeItem
Removes a item from the list
#### Parameters:
1. `number` The index which should get removed
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default list with 3 entries and removes the second one.
```lua
local mainFrame = basalt.createFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:removeItem(2)
```
## editItem
Edits a item from the list
#### Parameters:
1. `number` The index which should be edited
2. `string` The new item name
3. `number` the new item background color - optional
4. `number` The new item text color - optional
5. `any` New additional information - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default list with 3 entries and changes the second one.
```lua
local mainFrame = basalt.createFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList: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 list with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aList:getItem(2).text)
```
## getItemCount
Returns the current item count
#### Returns:
1. `number` The item list count
#### Usage:
* Creates a default list with 3 entries and prints the current item count.
```lua
local mainFrame = basalt.createFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aList: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()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aList:getAll())
```
## 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 list with 3 entries and selects the second entry.
```lua
local mainFrame = basalt.createFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:selectItem(2)
```
## clear
Removes all items.
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default list with 3 entries and removes them immediatley. Which makes no sense.
```lua
local mainFrame = basalt.createFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:clear()
```
## getItemIndex
returns the item index of the currently selected item
#### Returns:
1. `number` The current index
#### Usage:
* Creates a default list with 3 entries selects the second entry and prints the currently selected index.
```lua
local mainFrame = basalt.createFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:selectItem(2)
basalt.debug(aList: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 list with 4 entries and sets the selection background color to green.
```lua
local mainFrame = basalt.createFrame()
local aList = mainFrame:addList()
aList:addItem("1. Entry")
aList:addItem("2. Entry",colors.yellow)
aList:addItem("3. Entry",colors.yellow,colors.green)
aList:addItem("4. Entry")
aList:setSelectedItem(colors.green, colors.red)
```
```xml
<list selectionBG="green" selectionFG="red">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>2. Entry</text><bg>yellow</bg><fg>green</fg></item>
</list>
```
## setOffset
Sets the offset of the list (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 list with 6 entries and sets the offset to 3.
```lua
local mainFrame = basalt.createFrame()
local aList = mainFrame:addList()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
```
```xml
<list offset="3">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
<item><text>4. Entry</text></item>
<item><text>5. Entry</text></item>
<item><text>6. Entry</text></item>
</list>
```
## getOffset
Returns the current index offset
#### Returns:
1. `number` offset value
#### Usage:
* Creates a default list with 6 entries and sets the offset to 3, also prints the current offset.
```lua
local mainFrame = basalt.createFrame()
local aList = mainFrame:addList()
:addItem("1. Entry")
:addItem("2. Entry")
:addItem("3. Entry")
:addItem("4. Entry")
:addItem("5. Entry")
:addItem("6. Entry")
:setOffset(3)
basalt.debug(aList:getOffset())
```

View File

@@ -0,0 +1,337 @@
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 = {}
}
```
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 - optional
3. `number|color` unique default text color - optional
4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default menubar with 3 entries
```lua
local mainFrame = basalt.createFrame()
local aMenubar = mainFrame:addMenubar()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
```
```xml
<menubar>
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>3. Entry</text><bg>yellow</bg><fg>green</fg></item>
</menubar>
```
## 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()
local aMenubar = mainFrame:addMenubar()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:removeItem(2)
```
## editItem
Edits a 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 - optional
4. `number` The new item text color - optional
5. `any` New additional information - optional
#### 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()
local aMenubar = mainFrame:addMenubar()
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()
local aMenubar = mainFrame:addMenubar()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
basalt.debug(aMenubar:getItem(2).text)
```
## 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()
local aMenubar = mainFrame:addMenubar()
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()
local aMenubar = mainFrame:addMenubar()
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()
local aMenubar = mainFrame:addMenubar()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:setSpace(3)
```
```xml
<menubar space="3">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>3. Entry</text><bg>yellow</bg><fg>green</fg></item>
</menubar>
```
## 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()
local aMenubar = mainFrame:addMenubar()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry",colors.yellow)
aMenubar:addItem("3. Entry",colors.yellow,colors.green)
aMenubar:setScrollable(true)
```
```xml
<menubar scrollable="true">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text><bg>yellow</bg></item>
<item><text>3. Entry</text><bg>yellow</bg><fg>green</fg></item>
</menubar>
```
## 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()
local aMenubar = mainFrame:addMenubar()
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()
local aMenubar = mainFrame:addMenubar()
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()
local aMenubar = mainFrame:addMenubar()
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()
local aMenubar = mainFrame:addMenubar()
aMenubar:addItem("1. Entry")
aMenubar:addItem("2. Entry")
aMenubar:addItem("3. Entry")
aMenubar:addItem("4. Entry")
aMenubar:setSelectedItem(colors.green, colors.yellow)
```
```xml
<menubar selectionBG="green" selectionFG="yellow">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
<item><text>4. Entry</text></item>
</menubar>
```
## setOffset
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()
local aMenubar = mainFrame:addMenubar()
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:setOffset(3)
```
```xml
<menubar offset="3">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
<item><text>4. Entry</text></item>
<item><text>5. Entry</text></item>
<item><text>6. Entry</text></item>
</menubar>
```
## getOffset
returns the current offset
#### Returns:
1. `number` Current offset
#### Usage:
* Creates a default menubar with 6 entries and sets the offset to 3, prints the current offset.
```lua
local mainFrame = basalt.createFrame()
local aMenubar = mainFrame:addMenubar()
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:getOffset(3)
basalt.debug(aMenubar:getOffset())
```

View File

@@ -0,0 +1,395 @@
This is the base class for all visual objects. Which means, if you create a button, label, frame or something else (no timers, threads or animations) the following methods apply:
## show
Shows the object (only if the parent frame is already visible)
#### Returns:
1. `object` The object in use
#### Usage:
* Shows a frame
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
button:show()
```
```xml
<button visible="true" />
```
## hide
Hides the object
#### Returns:
1. `object` The object in use
#### Usage:
* Hides a frame
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton():setText("Close"):onClick(function() mainFrame:hide() end)
```
```xml
<button visible="false" />
```
## setPosition
Changes the position relative to its parent frame
#### Parameters:
1. `number` x coordinate
2. `number` y coordinate
3. `boolean` Whether it will add/remove to the current coordinates instead of setting them
#### 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()
mainFrame:addButton():setPosition(2,3)
```
```xml
<button x="2" y="3" />
```
## setBackground
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.
#### Parameters:
1. `number|color` Background color
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a frame, and sets its background color to `colors.gray`
```lua
local mainFrame = basalt.createFrame():setBackground(colors.gray)
```
```xml
<button bg="gray" />
```
## setForeground
Changes the object text color
#### Parameters:
1. `number|color` Foreground color
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a frame, and sets its foreground color to `colors.green`
```lua
local mainFrame = basalt.createFrame():setForeground(colors.green)
```
```xml
<button fg="green" />
```
## setSize
Changes the object size
#### Parameters:
1. `number` width
2. `number` height
#### 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()
local subFrame = mainFrame:addFrame():setSize(15,12)
```
```xml
<frame width="15" height="12" />
```
## setFocus
Sets the object to be the focused object.
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 should also use :setFocus()
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button to the focused object
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setFocus()
```
## setZIndex
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.
#### Parameters:
1. `number` z-index
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the buttons z-index to `1` and the labels z-index to `2`
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setZIndex(1):setPosition(2,2)
local aLabel = mainFrame:addButton():setZIndex(2):setPosition(2,2):setText("I am a label!")
```
```xml
<button x="2" y="2" zIndex="1" />
<label x="2" y="2" text="I am a label!" zIndex="2" />
```
## setParent
Sets the parent frame of the object
#### 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()
local aRandomFrame = basalt.createFrame()
local aButton = mainFrame:addButton():onClick(
function()
aRandomFrame:setParent(mainFrame)
end
)
```
## isFocused
Returns if the object is currently the focused object of the parent frame
#### Returns:
1. `boolean` Whether the object is focused
#### Usage:
* Prints whether the button is focused to the debug console
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton()
basalt.debug(aButton:isFocused()) -- shows true or false as a debug message
```
## getAnchorPosition
Converts the x and y coordinates into the anchor coordinates of the object
#### 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():setSize(15,15)
local aButton = mainFrame:addButton()
:setAnchor("bottomRight")
:setSize(8,1)
:setPosition(1,1)
basalt.debug(aButton:getAnchorPosition()) -- returns 7,14 (framesize - own size) instead of 1,1
```
## setAnchor
Sets the anchor of the object
#### Parameters:
1. `string` Anchor sides `("topLeft" "top", "topRight", "right", "bottomRight", "bottom", "bottomLeft", "left", "center")`
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the button to have an anchor of `bottomRight`
```lua
local mainFrame = basalt.createFrame():show()
local aButton = mainFrame:addButton()
:setAnchor("bottomRight")
:setSize(8,1)
:setPosition(-8,1)
```
```xml
<button anchor="bottomRight" />
```
## getAbsolutePosition
Converts the relative coordinates into absolute coordinates
#### 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():setPosition(3,3)
local aButton = mainFrame:addButton():setSize(8,1):setPosition(4,2)
basalt.debug(aButton:getAbsolutePosition()) -- returns 7,5 (frame coords + own coords) instead of 4,2
```
## setValue
Sets the value of that object (input, label, checkbox, textfield, scrollbar,...)
#### 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()
local aCheckbox = mainFrame:addCheckbox():setValue(true)
```
```xml
<checkbox value="true" />
```
## getValue
Returns the currently saved value
#### Returns:
1. `any` Object's value
#### Usage:
* Prints the value of the checkbox to the debug console
```lua
local mainFrame = basalt.createFrame()
local aCheckbox = mainFrame:addCheckbox():setValue(true)
basalt.debug(aCheckbox:getValue()) -- returns true
```
## getHeight/getWidth
Returns the respective height/width of the object
#### Returns:
1. `number` height/width
#### Usage:
* Prints the height of the object to the debug console
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setSize(5,8)
basalt.debug(aButton:getHeight()) -- returns 8
```
## isVisible
Returns if the object is currently visible
#### Returns:
1. `boolean`
#### Usage:
* Prints boolean visibility of object to debug console
```lua
local mainFrame = basalt.createFrame()
local aButton = mainFrame:addButton():setSize(5,8)
basalt.debug(aButton:isVisible()) -- returns true
```
## getName
Returns the given name of the object
#### Returns:
1. `string` name
#### Usage:
* Prints name of object to debug window
```lua
local mainFrame = basalt.createFrame()
basalt.debug(mainFrame:getName()) -- returns myFirstFrame
```
## setShadow
Sets the shadow color - default: colors.black
#### Parameters:
1. `number|color` Shadow color
#### Returns:
1. `object` The object in use
#### Usage:
* Sets the shadow to green and shows it:
```lua
local mainFrame = basalt.createFrame()
local subFrame = mainFrame:addFrame()
:setMoveable()
:setSize(18,6)
:setShadow(colors.green)
:showShadow(true)
```
```xml
<frame width="18" height="6" shadow="true" shadowColor="green" moveable="true" />
```
## showShadow
Shows or hides the shadow
#### 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()
local subFrame = mainFrame:addFrame()
:setMoveable()
:setSize(18,6)
:showShadow(true)
```
```xml
<frame width="18" height="6" shadow="true" moveable="true" />
```
## setBorder
Sets the border color - default: colors.black
#### 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()
local subFrame = mainFrame:addFrame()
:setMoveable()
:setSize(18,6)
:setBorder(colors.green)
:showBorder("left", "top", "right", "bottom")
```
```xml
<frame width="18" height="6" border="true" borderColor="green" moveable="true" />
```
## showBorder
Shows or hides the border
#### 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()
local subFrame = mainFrame:addFrame()
:setMoveable()
:setSize(18,6)
:showBorder("left", "top", "bottom")
```
```xml
<frame width="18" height="6" border="true" borderColor="green" borderRight="false" moveable="true" />
```

View File

@@ -0,0 +1,19 @@
Panes are very simple sizeable background objects.
The following list is only available to panes: <br>
Remember Pane also inherits from [Object](objects/Object.md)
Pane doesn't have any custom functionallity. If you want to change the color/position or size, just check out the [object](https://github.com/NoryiE/basalt/wiki/Object) wikipage.
## Example:
```lua
local mainFrame = basalt.createFrame()
local aPane = mainFrame:addPane()
aPane:setSize(30, 10)
aPane:setBackground(colors.yellow)
aPane:show()
```
```xml
<pane width="30" height="10" bg="yellow" />
```

View File

@@ -0,0 +1,167 @@
Program objects are here for opening other executable programs in your main program. You can execute worms, shell or any custom program you've made.
<br>
Remember Program inherits from [Object](objects/Object.md)
## getStatus
returns the current process status
#### Returns:
1. `string` current status ("running", "normal, "suspended", or "dead")
#### Usage:
* Prints current status
```lua
local mainFrame = basalt.createFrame()
local aProgram = mainFrame:addProgram()
basalt.debug(aProgram:getStatus())
```
## execute
Executes the given path or program
#### Parameters:
1. `string|function` the path to your file as string, or function which should be called
#### Returns:
1. `object` The object in use
#### Usage:
* Executes worm
```lua
local mainFrame = basalt.createFrame()
local aProgram = mainFrame:addProgram()
aProgram:execute("rom/programs/fun/worm.lua") -- executes worm
```
```xml
<program path="rom/programs/fun/worm.lua" execute="true" />
```
## stop
Stops a currently running program
#### Returns:
1. `object` The object in use
#### Usage:
* Stops worm by clicking a button
```lua
local mainFrame = basalt.createFrame()
local aProgram = mainFrame:addProgram()
aProgram:execute("rom/programs/fun/worm.lua") -- executes worm
mainFrame:addButton():setText("Pause"):onClick(function() aProgram:stop() end):show()
```
## pause
pauses the current program (prevents the program from receiving events)
#### Parameters:
1. `boolean` true, false or nothing
#### Returns:
1. `object` The object in use
#### Usage:
* Pauses worm by clicking a button
```lua
local mainFrame = basalt.createFrame():show()
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
mainFrame:addButton():setText("Pause"):onClick(function() aProgram:pause(true) end):show()
```
## isPaused
returns if the program is paused
#### Returns:
1. `boolean` pause status
#### Usage:
* Prints the pause status of the program
```lua
local mainFrame = basalt.createFrame():show()
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
basalt.debug(aProgram:isPaused())
```
## injectEvent
injects a event into the program manually. For example you could inject w a s and d for worm, by clicking buttons.
#### Parameters:
1. `string` event
2. `any` parameter
3. `any` parameter
4. `any` parameter
5. `any` parameter
6. `boolean` if this is true, the injected event will be executed even if the program is paused
#### Returns:
1. `object` The object in use
#### Usage:
* injects a event by clicking a button
```lua
local mainFrame = basalt.createFrame():show()
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
mainFrame:addButton():setText("inject"):onClick(function() aProgram:injectEvent("char", "w") end):show()
```
## injectEvents
Injects multiple events
#### Parameters:
1. `table` a table, items should be {event="event", args={para1, para2, para3, para4}}
#### Returns:
1. `object` The object in use
#### Usage:
* injects a multiple char events by clicking a button
```lua
local mainFrame = basalt.createFrame():show()
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
local events = {
{event="char", args={"h"}},
{event="char", args={"e"}},
{event="char", args={"y"}}
}
mainFrame:addButton():setText("inject"):onClick(function() aProgram:injectEvents(events) end):show()
```
## getQueuedEvents
If the program is paused, incomming events will be inserted into a queued events table. As soon as the program is unpaused, the queued events table will be empty
#### Returns:
1. `table` a table - {event="event", args={"a", "b",...}}
#### Usage:
* prints the queued events table
```lua
local mainFrame = basalt.createFrame():show()
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
mainFrame:addButton():setText("inject"):onClick(function() basalt.debug(aProgram:getQueuedEvents()) end):show()
```
## updateQueuedEvents
Here you can manipulate the queued events table
#### Parameters:
1. `table` a table, items should be {event="event", args={para1, para2, para3, para4}}
#### Returns:
1. `object` The object in use
```lua
local mainFrame = basalt.createFrame():show()
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
mainFrame:addButton():setText("inject"):onClick(function()
local events = aProgram:getQueuedEvents()
table.insert(events,1,{event="char", args={"w"}}
aProgram:updateQueuedEvents(events)
end):show()
```

View File

@@ -0,0 +1,134 @@
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()
local aProgressbar = mainFrame:addProgressbar()
aProgressbar:setDirection(3)
```
```xml
<frame direction="3"></frame>
```
## 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()
local aProgressbar = mainFrame:addProgressbar()
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()
local aProgressbar = mainFrame:addProgressbar()
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()
local aProgressbar = mainFrame:addProgressbar()
aProgressbar:setProgressBar(colors.green, colors.yellow, colors.red)
```
```xml
<progressbar progressColor="green" progressSymbol="yellow" progressSymbolColor="red" />
```
## 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()
local aProgressbar = mainFrame:addProgressbar()
aProgressbar:setBackgroundSymbol("X")
```
```xml
<progressbar backgroundSymbol="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 = require("Basalt")
local mainFrame = basalt.createFrame()
local aProgressbar = mainFrame:addProgressbar()
function progressDone()
basalt.debug("The Progressbar reached 100%!")
end
aProgressbar:onProgressDone(progressDone)
```
Here is also a example how this is done with xml:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame()
basalt.setVariable("progressDone", function()
basalt.debug("The Progressbar reached 100%!")
end)
```
```xml
<progressbar onDone="progressDone" />
```

View File

@@ -0,0 +1,229 @@
Radios are objects which you can freely place, and the user is then able to select a single item.
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 = {}
}
```
Remember Radios also inherits from [Object](objects/Object.md)
## addItem
Adds a item to the radio
#### Parameters:
1. `string` The entry name
2. `number` x position
3. `number` y position
2. `number|color` unique default background color - optional
3. `number|color` unique default text color - optional
4. `any` any value - you could access this later in a :onChange() event (you need to use :getValue()) - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default radio with 3 entries
```lua
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
```
```xml
<radio>
<item><text>1. Entry</text><x>5</x><y>2</y></item>
<item><text>2. Entry</text><x>5</x><y>4</y><bg>yellow</bg></item>
<item><text>3. Entry</text><x>5</x><y>6</y><bg>yellow</bg><fg>green</fg></item>
</radio>
```
## removeItem
Removes a item from the radio
#### Parameters:
1. `number` The index which should get removed
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default radio with 3 entries and removes the second one.
```lua
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:removeItem(2)
```
## editItem
Edits a item from the radio
#### Parameters:
1. `number` The index which should be edited
2. `string` The new item name
3. `number` the new x position
4. `number` the new y position
3. `number|color` the new item background color - optional
4. `number|color` The new item text color - optional
5. `any` New additional information - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default radio with 3 entries and changes the second one.
```lua
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:editItem(2, "Still 2. Entry", 5, 4, 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 radio with 3 entries and edits the second one.
```lua
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
basalt.debug(aRadio:getItem(2).text)
```
## getItemCount
Returns the current item count
#### Returns:
1. `number` The item radio count
#### Usage:
* Creates a default radio with 3 entries and prints the current item count.
```lua
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
basalt.debug(aRadio: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()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
basalt.debug(aRadio:getAll())
```
## selectItem
selects a item in the radio (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 radio with 3 entries and selects the second entry.
```lua
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:selectItem(2)
```
## clear
Removes all items.
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default radio with 3 entries and removes them immediatley. Which makes no sense.
```lua
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:clear()
```
## getItemIndex
returns the item index of the currently selected item
#### Returns:
1. `number` The current index
#### Usage:
* Creates a default radio with 3 entries selects the second entry and prints the currently selected index.
```lua
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:selectItem(2)
basalt.debug(aRadio: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 radio with 4 entries and sets the selection background color to green.
```lua
local mainFrame = basalt.createFrame()
local aRadio = mainFrame:addRadio()
aRadio:addItem("1. Entry",5,2)
aRadio:addItem("2. Entry",5,4,colors.yellow)
aRadio:addItem("3. Entry",5,6,colors.yellow,colors.green)
aRadio:addItem("4. Entry",5,8)
aRadio:setSelectedItem(colors.green, colors.red)
```
```xml
<radio selectionBG="green" selectionFG="red">
<item><text>1. Entry</text><x>5</x><y>2</y></item>
<item><text>2. Entry</text><x>5</x><y>4</y><bg>yellow</bg></item>
<item><text>3. Entry</text><x>5</x><y>6</y><bg>yellow</bg><fg>green</fg></item>
</radio>
```

View File

@@ -0,0 +1,108 @@
Scrollbars are objects, the user can scroll vertically or horizontally, this will change a value, which you can access by :getValue().<br>
Remember scrollbar also inherits from [Object](objects/Object.md)
## setSymbol
Changes the scrollbar symbol, default is " "
#### Parameters:
1. `string` symbol
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a new scrollbar and changes the symbol to X
```lua
local mainFrame = basalt.createFrame()
local scrollbar = mainFrame:addScrollbar():setSymbol("X")
```
```xml
<scrollbar symbol="X" />
```
## setBackgroundSymbol
Changes the symbol in the background, default is "\127"
#### Parameters:
1. `string` symbol
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a new scrollbar and changes the background symbol to X
```lua
local mainFrame = basalt.createFrame()
local scrollbar = mainFrame:addScrollbar():setBackgroundSymbol("X")
```
```xml
<scrollbar backgroundSymbol="X" />
```
## setBarType
Changes the scrollbar to be vertical or horizontal, default is vertical
#### Parameters:
1. `string` vertical or horizontal
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a new scrollbar and changes the bar type to horizontal
```lua
local mainFrame = basalt.createFrame()
local scrollbar = mainFrame:addScrollbar():setBarType("horizontal")
```
```xml
<scrollbar barType="horizontal" />
```
## 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.
#### Parameters:
1. `number` maximum
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a new scrollbar and changes the max value to 20
```lua
local mainFrame = basalt.createFrame()
local scrollbar = mainFrame:addScrollbar():setMaxValue(20)
```
```xml
<scrollbar maxValue="20" />
```
## setIndex
Changes the current index to your choice, for example you could create a button which scrolls up to 1 by using :setIndex(1)
#### Parameters:
1. `number` the index
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a new scrollbar and changes the index to 1 as soon as the button got clicked
```lua
local mainFrame = basalt.createFrame()
local scrollbar = mainFrame:addScrollbar():setMaxValue(20)
local button = mainFrame:addButton(function()
scrollbar:setIndex(1)
end)
```
```xml
<scrollbar index="2" />
```
## getIndex
Returns the current index
#### Returns:
1. `number` index

View File

@@ -0,0 +1,108 @@
Sliders are objects, the user can scroll vertically or horizontally, this will change a value, which you can access by :getValue().<br>
Remember slider also inherits from [Object](objects/Object.md)
## setSymbol
Changes the slider symbol, default is " "
#### Parameters:
1. `string` symbol
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a new slider and changes the symbol to X
```lua
local mainFrame = basalt.createFrame()
local slider = mainFrame:addSlider():setSymbol("X")
```
```xml
<slider symbol="X" />
```
## setBackgroundSymbol
Changes the symbol in the background, default is "\140"
#### Parameters:
1. `string` symbol
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a new slider and changes the background symbol to X
```lua
local mainFrame = basalt.createFrame()
local slider = mainFrame:addSlider():setBackgroundSymbol("X")
```
```xml
<slider backgroundSymbol="X" />
```
## setBarType
Changes the slider to be vertical or horizontal, default is horizontal
#### Parameters:
1. `string` vertical or horizontal
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a new slider and changes the bar type to horizontal
```lua
local mainFrame = basalt.createFrame()
local slider = mainFrame:addSlider():setBarType("vertical")
```
```xml
<slider barType="vertical" />
```
## 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.
#### Parameters:
1. `number` maximum
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a new slider and changes the max value to 20
```lua
local mainFrame = basalt.createFrame()
local slider = mainFrame:addSlider():setMaxValue(20)
```
```xml
<slider maxValue="20" />
```
## setIndex
Changes the current index to your choice, for example you could create a button which scrolls up to 1 by using :setIndex(1)
#### Parameters:
1. `number` the index
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a new slider and changes the index to 1 as soon as the button got clicked
```lua
local mainFrame = basalt.createFrame()
local slider = mainFrame:addSlider():setMaxValue(20)
local button = mainFrame:addButton(function()
slider:setIndex(1)
end)
```
```xml
<slider index="2" />
```
## getIndex
Returns the current index
#### Returns:
1. `number` index

View File

@@ -0,0 +1,161 @@
Textfields are objects, where the user can write something on multiple lines. it act's like the default edit script (without coloring)<br>
Remember textfield inherits from [Object](objects/Object.md)
## getLines
Returns all lines
#### Returns:
1. `table` lines
#### Usage:
* Prints all lines
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show()
basalt.debug(aTextfield:getLines())
```
## getLine
Returns the line on index position
#### Parameteres:
1. `number` index
#### Returns:
1. `string` line
#### Usage:
* Prints one line
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show()
basalt.debug(aTextfield:getLine(1))
```
## editLine
Edits the line on index position
#### Parameteres:
1. `number` index
2. `string` text
#### Returns:
1. `object` The object in use
#### Usage:
* Edits the line
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show()
basalt.debug(aTextfield:editLine(1, "Hello!"))
```
## addLine
Adds a line on index position
#### Parameteres:
1. `string` text
2. `number` index
#### Returns:
1. `object` The object in use
#### Usage:
* Adds a line
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show()
basalt.debug(aTextfield:addLine("Hello!", 1))
```
```xml
<textfield>
<lines>
<line>Hello!</line>
</lines>
</textfield>
```
## removeLine
Removes the line on index position
#### Parameteres:
1. `number` index
2. `string` text
#### Returns:
1. `object` The object in use
#### Usage:
* Removes a line
```lua
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aTextfield = mainFrame:addTextfield("myFirstTextfield"):show()
basalt.debug(aTextfield:removeLine())
```
## getTextCursor
Gets text cursor position
#### Returns:
1. `number` x position
2. `number` y position
## addKeywords
Adds keywords for special coloring
#### Parameteres:
1. `number|color` color of your choice
2. `table` a list of keywords which should be colored example: {"if", "else", "then", "while", "do"}
#### Returns:
1. `object` The object in use
#### Usage:
* Changes the color of some words to purple
```lua
local mainFrame = basalt.createFrame()
local aTextfield = mainFrame:addTextfield():addKeywords(colors.purple, {"if", "else", "then", "while", "do", "hello"})
```
```xml
<textfield>
<keywords>
<purple>
<keyword>if</keyword>
<keyword>else</keyword>
<keyword>then</keyword>
<keyword>while</keyword>
<keyword>do</keyword>
<keyword>hello</keyword>
</purple>
</keywords>
</textfield>
```
## addRule
Adds a new rule for special coloring
#### Parameteres:
1. `string` a pattern - check out this page: (https://riptutorial.com/lua/example/20315/lua-pattern-matching)
2. `number|color` text color
3. `number|color` background color - optional
#### Returns:
1. `object` The object in use
#### Usage:
* Changes the color of all numbers
```lua
local mainFrame = basalt.createFrame()
local aTextfield = mainFrame:addTextfield():addRule("%d", colors.lightBlue)
```
```xml
<textfield>
<rules>
<rule>
<pattern>%d</pattern>
<fg>lightBlue</fg>
</rule>
</rules>
</textfield>
```

View File

@@ -0,0 +1,65 @@
Threads are being executed simultaneously.
<br>
## start
starts a new thread and executes the function
#### Parameters:
1. `function` the function which should be executed
#### Returns:
1. `object` The object in use
#### Usage:
* Starts a new thread
```lua
local mainFrame = basalt.createFrame()
local aThread = mainFrame:addThread()
local function randomThreadFunction()
while true do
basalt.debug("Thread is active")
os.sleep(1) -- a sleep/coroutine.yield() or pullEvent is required otherwise we will never come back to the main program (error)
end
end
aThread:start(randomThreadfunction)
```
you are also able to start threads via xml:
```lua
basalt.setVariable("myThread", function() while true do os.sleep(1) end end)
```
```xml
<thread thread="myThread" start="true"/>
```
## stop
stops the thread
#### Returns:
1. `object` The object in use
#### Usage:
* Stops the current running thread by clicking on a button
```lua
local mainFrame = basalt.createFrame()
local aThread = mainFrame:addThread()
local function randomThreadFunction()
while true do
basalt.debug("Thread is active")
os.sleep(1) -- a sleep/coroutine.yield() or pullEvent is required otherwise we will never come back to the main program (error)
end
end
aThread:start(randomThreadfunction)
local aButton = mainFrame:addButton():setText("Stop Thread"):onClick(function() aThread:stop() end)
```
## getStatus
gets the current thread status
#### Returns:
1. `string` current status - ("running", "normal", "suspended", "dead")
#### Usage:
```lua
local mainFrame = basalt.createFrame()
local aThread = mainFrame:addThread()
basalt.debug(aThread:getStatus())
```

View File

@@ -0,0 +1,84 @@
Timers can call your functions delay and repeat it as often as you wish
<br>
## setTime
sets the time the timer should wait after calling your function
#### Parameters:
1. `number` the time to delay
2. `number` how often it should be repeated -1 is infinite
#### Returns:
1. `object` The object
```lua
local mainFrame = basalt.createFrame()
local aTimer = mainFrame:addTimer()
aTimer:setTime(2)
```
```xml
<timer time="2" repeat="1"/>
```
## start
Starts the timer
#### Returns:
1. `object` The object
```lua
local mainFrame = basalt.createFrame()
local aTimer = mainFrame:addTimer()
aTimer:setTime(2):start()
```
```xml
<timer time="2" start="true"/>
```
## cancel
Cancels the timer
#### Returns:
1. `object` The object
```lua
local mainFrame = basalt.createFrame()
local aTimer = mainFrame:addTimer()
aTimer:setTime(2):start()
aTimer:cancel()
```
# Events
## onCall
`onCall(self)`<br>
A custom event which gets triggered as soon as the current timer has finished
Here is a example on how to add a onCall event to your timer:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame()
local aTimer = mainFrame:addTimer()
function call()
basalt.debug("The timer has finished!")
end
aTimer:onCall(call)
```
Here is also a example how this is done with xml:
```lua
local basalt = require("Basalt")
local mainFrame = basalt.createFrame()
basalt.setVariable("call", function()
basalt.debug("The timer has finished!")
end)
```
```xml
<progressbar onDone="call" />
```

View File

@@ -0,0 +1,41 @@
Here I want to explain to you how you would create a button with the default color gray, and as long as the user is clicking on the button it will change its color to black (the default frame-background is lightGray).
To make this possible the button needs 1 onClick event, 1 onClickUp event and 1 onLoseFocus event.
Very interesting sidetip: events can hold multiple functions!<br>
**Example snippet:**
```lua
local function buttonColoring()
-- here you can add some coloring for your button
end
local function buttonLogic()
-- here you can add some logic for your button
end
local button = mainFrame:addButton("ExampleButton"):show()
button:onClick(buttonColoring):onClick(buttonLogic) -- yes this would work, if not its a bug!
```
This means you can create a function wich handles only the coloring side of your button, and if your button also needs some logic you just create your own unique function for that and add it to your button.
With this knowledge we create now a function where we pass a button-object as parameter and this will setup the coloring of our button:
**Example snippet:**
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show()
local button = mainFrame:addButton("firstButton"):setPosition(3,3):setSize(12,3):setText("Click me"):setBackground(colors.gray):setForeground(colors.black):show()
local button2 = mainFrame:addButton("secondButton"):setPosition(25,3):setSize(16,3):setText("Another Btn"):setBackground(colors.gray):setForeground(colors.black):show()
local function setupButtonColoring(btn)
btn:onClick(function() btn:setBackground(colors.black) btn:setForeground(colors.lightGray) end)
btn:onClickUp(function() btn:setBackground(colors.gray) btn:setForeground(colors.black) end)
btn:onLoseFocus(function() btn:setBackground(colors.gray) btn:setForeground(colors.black) end)
end
setupButtonColoring(button)
setupButtonColoring(button2)
basalt.autoUpdate()
```
Now you've got a function which sets your buttons up.

View File

@@ -0,0 +1,82 @@
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 = require("Basalt")
local mainFrame = basalt.createFrame():setBackground(colors.black):show()
local aButton = mainFrame:addButton():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()
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
## How To use XML
Here is a example on how to create a cool looking frame by using xml:
```xml
<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="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>
</lines>
</textfield>
<label anchor="bottomLeft" x="2" y="0" text="I love labels!" fg="lightGray"/>
</frame>
```
in your lua code you just have to add this layout to your frame:
```lua
local basalt = require("Basalt")
basalt.createFrame():addLayout("example.xml")
basalt.autoUpdate()
```

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

@@ -0,0 +1,56 @@
You question yourself how you can execute your own logic while basalt is also active? There are multiple ways of doing that:
## Method 1:
Using parallel.waitForAll
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame and a button without functionality
mainFrame:addButton("aButton"):onClick(function() end):show()
local function yourCustomHandler()
while true do
-- add your logic here
os.sleep(1) -- you need something which calls coroutine.yield(), yes os.sleep does that os.pullEvent() aswell
end
end
parallel.waitForAll(basalt.autoUpdate, yourCustomHandler) -- here it will handle your function (yourCustomHandler) and basalts handlers at the time
```
You can read [here (tweaked.cc)](https://tweaked.cc/module/parallel.html) what exactly parallel.waitForAll() does
## Method 2:
Using threads
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a thread
mainFrame:addButton("aButton"):onClick(function() end):show()
local thread = mainFrame:addThread("customHandlerExecutingThread")
local function yourCustomHandler()
while true do
-- add your logic here
os.sleep(1) -- you need something which calls coroutine.yield(), yes os.sleep does that os.pullEvent() aswell
end
end
thread:start(yourCustomHandler) -- this will create a coroutine and starts the coroutine, os.sleep does the rest, so you just have to call start once.
```
## Method 3:
Using timers
```lua
local basalt = dofile("basalt.lua")
local mainFrame = basalt.createFrame("mainFrame"):show()-- lets create a frame, a button without functionality and a timer
mainFrame:addButton("aButton"):onClick(function() end):show()
local timer = mainFrame:addTimer("customHandlerExecutingTimer")
local function yourCustomHandler()
-- add your logic here
end
timer:onCall(yourCustomHandler):setTime(1, -1):start() -- this will call your function every second until you :cancel() the timer
```

View File

@@ -1,48 +1,47 @@
# How-To
After downloading the project you can finally start creating your own program and use basalt. The first thing you want to use in your program is always:
After downloading the project, you can start creating your own program and use Basalt. The first thing you want to include in your program is always:
```lua
local basalt = require("basalt")
```
It doesn't matter if you're using the source folder or the minified/packed version of basalt. Both can be found by using require("basalt") without .lua.
It doesn't matter if you're using the source folder or the minified/packed version of Basalt. Both can be found by using require("basalt") without .lua.
Also to really run basalt you should use
To run Basalt, you should use:
```lua
basalt.autoUpdate()
```
somewhere on the bottom of your program. basalt.autoUpdate() starts the event listener and the draw handler.
This should be placed at the bottom of your program. basalt.autoUpdate() starts the event listener and the draw handler.
## Example
Here is a fully working example of how a program could look like:
Here's a fully working example of how a program could look like:
```lua
local basalt = require("basalt") --> Load the basalt framework into the variable called "basalt"
local basalt = require("basalt") --> Load the Basalt framework into the variable called "basalt"
--> Now we want to create a base frame, we call the variable "main" - by default everything you create is visible. (you don't need to use :show())
local main = basalt.createFrame()
local button = main:addButton() --> Here we add our first button
button:setPosition(4, 4) -- of course we want to change the default position of our button
button:setSize(16, 3) -- and the default size.
button:setText("Click me!") --> This method displays what the text of our button should look like
button:setPosition(4, 4) -- We want to change the default position of our button
button:setSize(16, 3) -- And the default size.
button:setText("Click me!") --> This method sets the text displayed on our button
local function buttonClick() --> Let us create a function we want to call when the button gets clicked
local function buttonClick() --> Create a function we want to call when the button gets clicked
basalt.debug("I got clicked!")
end
-- Now we just need to register the function to the buttons onClick event handlers, this is how we can achieve that:
-- Now we just need to register the function to the button's onClick event handlers, this is how we can achieve that:
button:onClick(buttonClick)
basalt.autoUpdate() -- As soon as we call basalt.autoUpdate, the event and draw handlers will listen to any incomming events (and draw if necessary)
basalt.autoUpdate() -- As soon as we call basalt.autoUpdate, the event and draw handlers will listen to any incoming events (and draw if necessary)
```
If you're like us and strive for succinct and beautiful code, here is a cleaner implementation of the code above:
If you strive for succinct and beautiful code, here's a cleaner implementation of the code above:
```lua
local basalt = require("basalt")
@@ -50,11 +49,11 @@ local basalt = require("basalt")
local main = basalt.createFrame()
local button = main --> Basalt returns an instance of the object on most methods, to make use of "call-chaining"
:addButton() --> This is an example of call chaining
:setPosition(4,4)
:setPosition(4, 4)
:setText("Click me!")
:onClick(
function()
basalt.debug("I got clicked!")
function()
basalt.debug("I got clicked!")
end)
basalt.autoUpdate()

View File

@@ -1,36 +1,36 @@
Basalt provides multiple unique versions. A source version, a minified version and a web version.
Basalt offers three unique versions for different use cases: a Source version, a Minified/Packed version, and a Web version.
## Source
## Source Version
This version is, like the name already says, the source code of basalt. If you want to dig into the code, add additional content or just prefer to use the source, then you should aim for the source-version.
The Source version, as the name suggests, contains the unmodified source code of Basalt. Use this version if you want to explore the code, add custom content, or prefer working with the original source.
The following command allows you to download the source-version on your computer:
To download the Source version, use the following command:
`wget run https://basalt.madefor.cc/install.lua source [foldername] [branch]`
The first optional argument is the folder name you wish that basalt should be installed into, by default the folder is called basalt.
The second optional argument is the branch you want to use. If you don't know what this means please ignore it (the 2 options are master and dev)
- `foldername` (optional): The folder name for the Basalt installation (default: `basalt`).
- `branch` (optional): Choose between `master` and `dev` branches (default: `master`).
## Minified / Packed
## Minified/Packed Version
This version is the minified version, i also call it the packed version. There are 2 changes, the first one is that the code will be shown minified which makes the size much smaller, the second change is that you will recieve a file instead of a folder.
The Minified/Packed version is a compressed version of the Basalt code. It reduces the file size and combines the code into a single file instead of a folder, making it easier to manage.
The following command allows you to download the packed-version on your computer:
To download the Minified/Packed version, use the following command:
`wget run https://basalt.madefor.cc/install.lua packed [filename] [branch]`
The first optional argument is the file name you wish that the installer should use, by default the file is called basalt.lua.
The second optional argument is the branch you want to use. If you don't know what this means please ignore it (the 2 options are master and dev)
- `filename` (optional): The file name for the Basalt installation (default: `basalt.lua`).
- `branch` (optional): Choose between `master` and `dev` branches (default: `master`).
## Web
## Web Version
The web version is a special version, used if your goal is to keep your project's size as small as possible. I suggest you to use the web version only if you don't restart your program over and over again. For example if you designed your program to reboot after the user made a bad choice (leads into a error or something like that) it is better to use the minified/source version.
The Web version is designed for minimal project size and fetches the required code from the web when needed. This version is recommended for projects that don't require frequent restarts. If your program reboots often due to user input or errors, it's better to use the Source or Minified versions.
The following command allows you to download the web-version on your computer:
To download the Web version, use the following command:
`wget run https://basalt.madefor.cc/install.lua web [version] [filename]`
By default the first argument is the latest version of basalt's releases. [Here](https://github.com/Pyroxenium/Basalt/tree/master/docs/versions) you can see which versions are available to use.
For example: wget run https://basalt.madefor.cc/install.lua web basalt-1.6.3.lua - the second argument is just the file name, default is basaltWeb.lua.
- `version` (optional): Specify the desired version of Basalt (default: latest version). [Click here](https://github.com/Pyroxenium/Basalt/tree/master/docs/versions) to see the available versions.
- `filename` (optional): The file name for the Basalt installation (default: `basaltWeb.lua`).
Remember to rename `local basalt = require("basalt")` into `local basalt = require("basaltWeb")` if you want to use the web-version
**Note**: If using the Web version, remember to change `local basalt = require("basalt")` to `local basalt = require("basaltWeb")` in your code.

View File

@@ -0,0 +1,59 @@
After downloading the project, you can finally start creating your own program and using Basalt. The first thing you will want to use in your program is always:
```lua
local basalt = require("basalt")
```
It doesn't matter if you are using the source folder or the minified/packed version of Basalt. Both can be found using require("basalt") without the .lua extension.
To actually start using Basalt, you should include the following line at the bottom of your program:
```lua
basalt.autoUpdate()
```
This will start the event listener and the draw handler.
## Example
Here is a fully functional example of how a program could look:
```lua
local basalt = require("basalt") --> Load the Basalt framework into the variable "basalt"
--> Now we want to create a base frame, we call the variable "main" - by default everything you create is visible (you don't need to use :show())
local main = basalt.createFrame()
local button = mainFrame:addButton() --> Here we add our first button
button:setPosition(4, 4) -- Of course we want to change the default position of our button
button:setSize(16, 3) -- And the default size.
button:setText("Click me!") --> This method displays what the text of our button should look like
local function buttonClick() --> Let us create a function we want to call when the button gets clicked
basalt.debug("I got clicked!")
end
-- Now we just need to register the function to the button's onClick event handlers, this is how we can achieve that:
button:onClick(buttonClick)
basalt.autoUpdate() -- As soon as we call basalt.autoUpdate, the event and draw handlers will listen for any incoming events (and draw if necessary)
```
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 main = basalt.createFrame()
local button = main --> Basalt returns an instance of the object on most methods, to make use of "call-chaining"
:addButton() --> This is an example of call chaining
:setPosition(4,4)
:setText("Click me!")
:onClick(
function()
basalt.debug("I got clicked!")
end)
basalt.autoUpdate()
```

View File

@@ -1,6 +1,5 @@
# Basalt
This is the UI Manager and the starting point for your project. The following functions allow you to influence the default behavior of Basalt.
This is the UI Manager and the first thing you want to access.
Before you can access Basalt, you need to add the following code on top of your file:
```lua
@@ -22,6 +21,7 @@ You are now able to access the following list of methods:
|[getVersion](objects/Basalt/getVersion.md)|Returns the Basalt version
|[isKeyDown](objects/Basalt/isKeyDown.md)|Returns if the key is held down
|[log](objects/Basalt/log.md)|Writes something into the log file
|[memory](objects/Basalt/log.md)|Returns the current memory usage of Basalt
|[onEvent](objects/Basalt/onEvent.md)|Event listener
|[removeFrame](objects/Basalt/removeFrame.md)|Removes a previously created base frame
|[schedule](objects/Basalt/schedule.md)|Schedules a new task
@@ -29,20 +29,21 @@ You are now able to access the following list of methods:
|[setTheme](objects/Basalt/setTheme.md)|Changes the base theme of basalt
|[setMouseDragThrottle](objects/Basalt/setMouseDragThrottle.md)|Changes the mouse drag throttle amount
|[setMouseMoveThrottle](objects/Basalt/setMouseMoveThrottle.md)|CraftOS-PC: Changes the mouse move throttle amount
|[setRenderingThrottle](objects/Basalt/setMouseMoveThrottle.md)|Sets the rendering throttle amount
|[setVariable](objects/Basalt/setVariable.md)|Sets a variable which you can access via XML
|[stopUpdate / stop](objects/Basalt/stopUpdate.md)|Stops the currently active event and draw listener
|[update](objects/Basalt/update.md)|Starts the event and draw listener once
## Examples
Here is a lua example on how to create a empty base frame and start basalt's listener.
Here is a Lua example on how to create an empty base frame and start Basalt's listener.
```lua
local basalt = require("basalt") -- Loads Basalt into our project
local main = basalt.createFrame() -- Creates a base frame. On that frame we are able to add object's
local main = basalt.createFrame() -- Creates a base frame. On that frame, we are able to add objects
-- Here we would add additional object's
-- Here we would add additional objects
basalt.autoUpdate() -- Starts listening to incoming events and draw stuff on the screen. This should nearly always be the last line.
```

View File

@@ -1,7 +1,7 @@
# Basalt
## autoUpdate
### Description
This starts the event and draw handler for you. The listeners will run until you stop them.
### Parameters
@@ -13,6 +13,12 @@ This starts the event and draw handler for you. The listeners will run until you
* Enables the basalt listeners, otherwise the screen will not continue to update
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
basalt.autoUpdate()
basalt.autoUpdate() -- Start the event and draw listeners
-- Some code here...
basalt.autoUpdate(false) -- Stop the event and draw listeners
```

View File

@@ -1,15 +1,14 @@
# Basalt
## createFrame
Creates a new base-frame, you can have as many base-frames as you want, but only 1 can be active (visible) at the same time.
You can always switch between your base frames.
### Description
Only the currently active base-frame listens to incoming events (except for some events like time-events and peripheral-events)
Creates a new base frame, which is essentially a frame without a parent. You can have as many base frames as you want, but only one can be active (visible) at a time. You can always switch between your base frames.
Only the currently active base frame listens to incoming events (except for some events like time-events and peripheral-events).
### Parameters
1. `string` id - optional (if you dont set a id it will automatically create a uuid for you)
1. `string` id - optional (if you don't set an ID, it will automatically create a UUID for you)
### Returns
@@ -24,7 +23,7 @@ local main1 = basalt.createFrame() -- Visible base frame on program start
local main2 = basalt.createFrame()
local main3 = basalt.createFrame()
main1:addButton()
:setPosition(2,2)
:setPosition(2, 2)
:setText("Switch")
:onClick(function()
main2:show() -- this function automatically "hides" the first one and shows the second one

View File

@@ -1,11 +1,10 @@
# Basalt
## debug
Creates a label with some information on the main frame on the bottom left. When you click on that label it will open a log view for you. See it as the new print for debugging
### Description
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.
Creates a label with some information on the main frame in the bottom left corner. When you click on that label, it will open a log view for you. Think of 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.
`basalt.debugFrame` and `basalt.debugList` are also available.
@@ -19,11 +18,4 @@ which returns the debug Label.
```lua
basalt.debug("Hello! ", "^-^")
```
* Changes the debug label's anchor
```lua
basalt.debugLabel:setAnchor("topLeft") -- default anchor is bottomLeft
basalt.debug("Hello!")
```
```

View File

@@ -1,7 +1,7 @@
# Basalt
## getActiveFrame
### Description
Returns the currently active/visible base frame.
### Returns

View File

@@ -1,7 +1,7 @@
# Basalt
## getFrame
### Description
Returns a base frame by the given id.
### Parameters

View File

@@ -1,9 +1,8 @@
# Basalt
## getTheme
## basalt.getTheme
### Description
Returns the current base-theme. This base-theme can be set using setTheme.md.
A list of base-theme keys can be found [here](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua).
Returns the current base-theme. This base-theme can be set using setTheme.lua.
### Returns

View File

@@ -1,7 +1,7 @@
# Basalt
## getVariable
### Description
Returns a variable defined with [setVariable](objects/Basalt/setVariable)
### Returns

View File

@@ -1,7 +1,7 @@
# Basalt
## getVersion
### Description
Returns the currently active/visible base frame.
### Returns

View File

@@ -1,7 +1,7 @@
# Basalt
## isKeyDown
### Description
Checks if the user is currently holding a key
### Parameters

View File

@@ -1,13 +1,13 @@
# Basalt
## log
This writes something into a file. The main goal is to make debugging errors easier. Lets say you'r program is crashing and you don't know why, you could use basalt.log The log files will automatically removed after you start your program again.
### Description
Writes a message to the log file. This can be useful for debugging errors or keeping a record of events in your application. Log files are automatically removed when you start your program again.
### Parameters
1. `string` The text to write into the log file
2. `string` - optional (default: "Debug") - the type to write
2. `string` - The type or category of the log message
### Usage
@@ -17,12 +17,12 @@ This writes something into a file. The main goal is to make debugging errors eas
basalt.log("Hello!")
```
This should result in there beeing a file called `basaltLog.txt`. In the file it should say `[Basalt][Debug]: Hello!`.
This should result in a file called `basaltLog.txt`. In the file it should say `[Basalt][Debug]: Hello!`.
* Writes "Config file missing" into the log file, with warning as prefix.
* Writes "Config file missing" into the log file, with "WARNING" as the prefix.
```lua
basalt.log("Config file is missing", "WARNING")
```
This should result in there beeing a file called `basaltLog.txt`. In the file it should say `[Basalt][WARNING]: Config file is missing`.
This should result in a file called `basaltLog.txt`. In the file, it should say `[Basalt][WARNING]: Config file is missing`.

View File

@@ -0,0 +1,18 @@
## memory
### Description
Returns the amount of memory used by Basalt in bytes. This can be useful for monitoring your application's memory usage and performance.
### Returns
1. `number` The amount of memory used by Basalt in bytes.
### Usage
* Display the memory usage in the debug console
```lua
local memoryUsage = basalt.memory()
basalt.debug("Memory usage: ", memoryUsage, " bytes")
```

View File

@@ -1,8 +1,8 @@
# Basalt
## onEvent
This is the top-level method to intercept an event before sending it to the object event handlers. If you use return false, the event is not passed to the event handlers.
### Description
This is the top-level method to intercept an event before sending it to the object event handlers. If you use `return false`, the event is not passed to the event handlers.
### Parameters
@@ -10,6 +10,8 @@ This is the top-level method to intercept an event before sending it to the obje
### Usage
* Prevents the "terminate" event from stopping the program
```lua
local basalt = require("basalt")

View File

@@ -1,7 +1,7 @@
# Basalt
## removeFrame
### Description
Removes the base frame by it's id. **This only works for base-frames.**
### Parameters

View File

@@ -1,7 +1,7 @@
# Basalt
## schedule
### Description
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.
**A guide can be found [here](/tips/logic).**

View File

@@ -1,8 +1,8 @@
# Basalt
## setActiveFrame
Sets what should be the active baseframe.
### Description
Sets the active base frame.
### Parameters
@@ -10,4 +10,23 @@ Sets what should be the active baseframe.
### Usage
TODO
```lua
local basalt = require("basalt")
local main1 = basalt.createFrame("firstBaseFrame")
local main2 = basalt.createFrame("secondBaseFrame")
main1:addButton()
:setText("Switch to main2")
:onClick(function()
basalt.setActiveFrame(main2)
end)
main2:addButton()
:setText("Switch to main1")
:onClick(function()
basalt.setActiveFrame(main1)
end)
basalt.autoUpdate()
```

View File

@@ -1,17 +1,19 @@
# Basalt
## setMouseDragThrottle
### Description
Changes the drag throttle of all drag events. Default value is 50ms - which is 0.05s.
Instead of sending all mouse_drag events to the :onDrag handlers basalt sends every 0.05s (while dragging) the most recent drag event to all
drag handlers. If you need all drag events - just change the value to 0.
### Parameters
1. `number` A number in miliseconds.
1. `number` throttle - A number in milliseconds representing the drag throttle.
### Usage
* Set the drag throttle to 0, which sends all drag events to the handlers
```lua
local basalt = require("basalt")
basalt.setMouseDragThrottle(0)

View File

@@ -1,19 +1,21 @@
# Basalt
## setMouseMoveThrottle
### Description
This feature is only available for [CraftOS-PC](https://www.craftos-pc.cc).
CraftOS-PC has a builtin mouse_move event, which is disabled by default. By using this method it will also enable the event for you. Remember - basalt does not disable the event after closing the program, which means the event stays active. If you want to disable the event please use config.set("mouse_move_throttle", -1) in your lua prompt or your program.
CraftOS-PC has a built-in `mouse_move` event, which is disabled by default. By using this method, it will also enable the event for you. Remember, Basalt does not disable the event after closing the program, which means the event stays active. If you want to disable the event, please use `config.set("mouse_move_throttle", -1)` in your Lua prompt or your program.
Sidenote: a very low amount can make the program laggy - because it litterally spams the mouse_move event. So use it carefully.
Sidenote: A very low amount can make the program laggy because it literally spams the `mouse_move` event. So, use it carefully.
### Parameters
1. `number` A number in miliseconds.
1. `number` throttle - A number in milliseconds representing the mouse move throttle.
### Usage
* Set the mouse move throttle to 50 milliseconds
```lua
local basalt = require("basalt")
basalt.setMouseMoveThrottle(50)

View File

@@ -0,0 +1,18 @@
## setRenderingThrottle
### Description
Sets the rendering throttle for Basalt's automatic update process. This determines how often the screen is updated during the auto-update loop. A higher value means the screen updates less frequently, potentially reducing CPU usage and improving performance, while a lower value results in more frequent updates, ensuring smoother animations and responsiveness.
### Parameters
1. `number` throttle - The throttle value in milliseconds. Default value is 50ms (0.05 seconds).
### Usage
* Sets the rendering throttle to 100ms (0.1 seconds).
```lua
local basalt = require("basalt")
basalt.setMouseMoveThrottle(100)
```

View File

@@ -1,16 +1,16 @@
# Basalt
## setTheme
Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua). The theme can also be gotten with [`basalt.getTheme()`](objects/Basalt/getTheme)
### Description
Sets the base theme of the project! Make sure to cover all existing objects, otherwise it will result in errors. A good example is [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua). The theme can also be retrieved with [`basalt.getTheme()`](objects/Basalt/getTheme)
### Parameters
1. `table` theme layout look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for a example
1. `table` theme - A table containing the theme layout. Look into [theme](https://github.com/Pyroxenium/Basalt/blob/master/Basalt/theme.lua) for an example
### Usage
* Sets the default theme of basalt.
* Sets the default theme of Basalt.
```lua
basalt.setTheme({

View File

@@ -1,17 +1,17 @@
# Basalt
## setVariable
This stores a variable which you're able to access via xml. You are also able to add a function, which then gets called by object events created in XML.
### Description
This method stores a variable that you can access via XML. You can also add a function, which is then called by object events created in XML.
### Parameters
1. `string` a key name
2. `any` any variable
1. `string` key - A key name to store the variable.
2. `any` value - Any variable to store under the key.
### Usage
* Adds a function to basalt.
* Adds a reusable function to Basalt.
```lua
basalt.setVariable("clickMe", function()

View File

@@ -1,13 +1,13 @@
# Basalt
## stopUpdate / stop
Stops the automatic draw and event handler which got started by `basalt.autoUpdate()`.
`basalt.autoUpdate(false)` also does the same.
### Description
This method stops the automatic draw and event handler that was started by `basalt.autoUpdate()`.
`basalt.autoUpdate(false)` achieves the same result.
### Usage
* When the quit button is clicked, the button stops basalt's event listeners and draw handlers
* When the quit button is clicked, the button stops Basalt's event listeners and draw handlers.
```lua
local main = basalt.createFrame()

View File

@@ -1,5 +1,3 @@
# Basalt
## update
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.

10
docs/objects/BaseFrame.md Normal file
View File

@@ -0,0 +1,10 @@
BaseFrame is a subclass of the Container class. It serves as the foundation for other frame types and provides additional functionality specific to the BaseFrame. The main difference between BaseFrame and other frame types is that BaseFrame does not have a parent.
If you want to create a BaseFrame, you will have to use [basalt.createFrame](objects/basalt/createFrame.md)
In addition to the Object, VisualObject and Container methods, baseframe also has the following methods:
| | |
|---|---|
|[getOffset](objects/BaseFrame/getOffset.md)|Returns the current offset of the BaseFrame object
|[setOffset](objects/BaseFrame/setOffset.md)|Sets a new offset for the BaseFrame object

View File

@@ -0,0 +1,21 @@
## getOffset
### Description
Returns the offset
### Returns
1. `number` x position
2. `number` y position
### Usage
* Prints the offset amount to the console
```lua
local main = basalt.createFrame()
local button = mainFrame:addButton()
basalt.debug(main:getOffset())
```

View File

@@ -0,0 +1,26 @@
## setOffset
### Description
Sets the frame's offset, this offset is beeing used to move all children object's by the offset's position
### Parameters
1. `number` x position
2. `number` y position
### Returns
1. `number` x position
2. `number` y position
### Usage
* Sets the baseframes offset by y5.
```lua
local main = basalt.createFrame()
local button = mainFrame:addButton()
main:setOffset(0, 5)
```

View File

@@ -1,6 +1,6 @@
The button object is for creating buttons If you click on them, they should execute something. You decide what should happen when clicking on them.
The Button object is derived from the VisualObject class and is used for creating interactive buttons in the Basalt framework. When a button is clicked, it can execute a predefined function, such as navigating to another screen or performing a specific action.
[Object](objects/Object.md) methods also apply for buttons.
In addition to the Object and VisualObject methods, buttons also have the following methods:
| | |
|---|---|
@@ -8,9 +8,10 @@ The button object is for creating buttons If you click on them, they should exec
|[setHorizontalAlign](objects/Button/setHorizontalAlign.md)|Changes the horizontal text position
|[setVerticalAlign](objects/Button/setVerticalAlign.md)|Changes the vertical text position
# Example
This is a example on how you would create a fully working button:
Here's an example of how to create a fully functional button using the Button object:
```lua
local main = basalt.createFrame()
local aButton = main:addButton():setText("Click")
@@ -22,16 +23,16 @@ aButton:onClick(function(self,event,button,x,y)
end)
```
and this would be the xml way:
```lua
basalt.setVariable("buttonClick", function(self,event,button,x,y)
if(event=="mouse_click")and(button==1)then
basalt.debug("Left mousebutton got clicked!")
end
end)
Alternatively, you can create a button using an XML layout:
local main = basalt.createFrame():addLayout("example.xml")
```
```xml
<button onClick="buttonClick" text="Click" />
```
<button onClick="buttonClick" text="Click">
<onClick>
if(event=="mouse_click")and(button==1)then
basalt.debug("Left mousebutton got clicked!")
end
</onClick>
</button>
```
In these examples, a button is created with the text "Click". When the left mouse button is clicked on the button, the message "Left mouse button got clicked!" is printed.

View File

@@ -1,20 +1,28 @@
## setHorizontalAlign
### Description
Sets the horizontal align of the button text
#### Parameters:
### Parameters
1. `string` the position as string ("left", "center", "right") - default is center.
#### Returns:
### Returns
1. `object` The object in use
#### Usage:
* Sets the button's horizontal text align to right.
### Usage
* Sets the button's horizontal text align to right.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
:setText("Click me!")
:setHorizontalAlign("right")
```
```xml
<button text="Click me!" horizontalAlign="right" />
```
```

View File

@@ -1,17 +1,26 @@
## setText
### Description
Sets the displayed button text
#### Parameters:
### Parameters
1. `string` the text the button should show
#### Returns:
### Returns
1. `object` The object in use
#### Usage:
### Usage
* Creates a button with "Click me!" as text.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton():setText("Click me!")
```
```xml
<button text="Click me!" />
```
```

View File

@@ -1,14 +1,21 @@
## setVerticalAlign
### Description
Sets the vertical align of the button text
#### Parameters:
### Parameters
1. `string` the position as string ("top", "center", "bottom") - default is center.
#### Returns:
### Returns
1. `object` The object in use
#### Usage:
### Usage
* Sets the button's horizontal text align to right and the vertical text align to bottom.
```lua
local mainFrame = basalt.createFrame()
local button = mainFrame:addButton()
@@ -16,6 +23,7 @@ local button = mainFrame:addButton()
:setHorizontalAlign("right")
:setVerticalAlign("bottom")
```
```xml
<button text="Click me!" horizontalAlign="right" verticalAlign="bottom" />
```
```

View File

@@ -0,0 +1,38 @@
The ChangeableObject class is a subclass of VisualObject and Object that provides additional methods for handling changes to objects.
In addition to the Object and VisualObject methods, changeableObjects also have the following methods:
| | |
|---|---|
|[setValue](objects/Button/setText.md)|Changes the button text
|[getValue](objects/Button/setHorizontalAlign.md)|Changes the horizontal text position
|[onChange](objects/Button/setVerticalAlign.md)|Changes the vertical text position
# Example
Here's an example of how to create a fully functional button using the Button object:
```lua
local main = basalt.createFrame()
local aButton = main:addButton():setText("Click")
aButton:onClick(function(self,event,button,x,y)
if(event=="mouse_click")and(button==1)then
basalt.debug("Left mousebutton got clicked!")
end
end)
```
Alternatively, you can create a button using an XML layout:
```xml
<button onClick="buttonClick" text="Click">
<onClick>
if(event=="mouse_click")and(button==1)then
basalt.debug("Left mousebutton got clicked!")
end
</onClick>
</button>
```
In these examples, a button is created with the text "Click". When the left mouse button is clicked on the button, the message "Left mouse button got clicked!" is printed.

View File

@@ -0,0 +1,21 @@
## getValue
### Description
Gets the value of your object
### Returns
1. `any` The current value of the object
### Usage
* Retrieves the value of a Slider.
```lua
local mainFrame = basalt.createFrame()
local slider = mainFrame:addSlider():setValue(50)
local currentValue = slider:getValue()
basalt.debug("The current value of the slider is:", currentValue)
```

View File

@@ -0,0 +1,33 @@
## onChange
### Description
`onChange(self, event, value)`
The onChange event is triggered when the value of a ChangeableObject, such as a Slider, is changed by the user.
### Returns
1. `object` The object in use
### Usage
* Add an onChange event to a Slider:
```lua
local basalt = require("basalt")
local main = basalt.createFrame()
local slider = main:addSlider()
:setPosition(3,3)
:setSize(12,3)
:setValue(50)
function sliderOnChange(self, event, value)
basalt.debug("Slider value changed to", value)
end
slider:onChange(sliderOnChange)
basalt.autoUpdate()
```

View File

@@ -0,0 +1,22 @@
## setValue
### Description
Sets the value of your object
### Parameters
1. `any` new value
### Returns
1. `object` The object in use
### Usage
* Creates a Slider with a value of 50.
```lua
local mainFrame = basalt.createFrame()
local slider = mainFrame:addSlider():setValue(50)
```

View File

@@ -1,36 +1,34 @@
With checkboxes the user can set a boolean to true or false by clicking on them.
The Checkbox object is derived from the VisualObject class and allows users to set a boolean value to true or false by clicking on it. Checkboxes are commonly used in forms and settings to enable or disable specific options.
[Object](objects/Object.md) methods also apply for checkboxes.
In addition to the Object and VisualObject methods, checkboxes also have the following method:
| | |
|---|---|
|[setSymbol](objects/Checkbox/setSymbol.md)|Changes the symbol when checkbox is checked
# Example
This is how you would create a event which gets fired as soon as the value gets changed:
Here's an example of how to create a Checkbox object and attach an event that gets fired when the value changes:
```lua
local main = basalt.createFrame()
local aCheckbox = main:addCheckbox()
local function checkboxChange(self)
local checked = self:getValue()
basalt.debug("The value got changed into ", checked)
local checked = self:getValue()
basalt.debug("The value got changed into ", checked)
end
aCheckbox:onChange(checkboxChange)
```
also possible via xml:
```lua
local main = basalt.createFrame():addLayout("example.xml")
basalt.setVariable("checkboxChange", function(self)
local checked = self:getValue()
basalt.debug("The value got changed into ", checked)
end)
```
```xml
<checkbox onChange="checkboxChange" />
<checkbox onChange="checkboxChange">
<onChange>
local checked = self:getValue()
basalt.debug("The value got changed into ", checked)
</onChange>
</checkbox>
```
In these examples, a checkbox is created, and when the value changes, a debug message prints the new value of the checkbox.

View File

@@ -1,18 +1,26 @@
## setSymbol
### Description
Changes the checkbox symbol, default is "\42"
#### Parameters:
### Parameters
1. `string` symbol
#### Returns:
### Returns
1. `object` The object in use
#### Usage:
### Usage
* Creates a new checkbox and changes the symbol to o
```lua
local main = basalt.createFrame()
local checkbox = main:addCheckbox():setSymbol("o")
```
```xml
<checkbox symbol="o" />
```
```

17
docs/objects/Container.md Normal file
View File

@@ -0,0 +1,17 @@
Container is the base class for all frame types. It provides the basic structure and functionality for all frame objects. Container objects can contain other container objects, thus forming the foundation for the hierarchy of frame objects.
In addition to the Object and VisualObject methods, container objects have the following methods:
| | |
|---|---|
|[addObject](objects/Container/addObject.md)|Adds a new object to the container
|[getObject](objects/Container/getObject.md)|Returns an object in the container by its ID
|[getDeepObject](objects/Container/getDeepObject.md)|Returns an object in the container or its sub-containers by its ID
|[removeObject](objects/Container/removeObject.md)|Removes an object from the container by its ID
|[updateZIndex](objects/Container/updateZIndex.md)|Updates the Z-index of an object in the container
|[setImportant](objects/Container/setImportant.md)|Marks an object as important, so it is displayed on top if needed
|[sortElementOrder](objects/Container/sortElementOrder.md)|Sorts the order of elements in the container based on their Z-indices
|[removeFocusedObject](objects/Container/removeFocusedObject.md)|Removes focus from an object in the container
|[setFocusedObject](objects/Container/setFocusedObject.md)|Sets focus on a specific object in the container
A Container Object inherits from VisualObject, but won't draw children objects.

View File

@@ -0,0 +1,13 @@
## addObject
### Description
Adds a object to the container
### Parameters
1. `object` any object
### Returns
1. `object` The object which got added

View File

@@ -0,0 +1,30 @@
## getDeepObject
### Description
Retrieves an object from the container or its descendants by its ID. This method searches recursively through all child containers to find the object.
### Parameters
1. `string` id - The ID of the object you want to retrieve.
### Returns
1. `object` The object with the specified ID, or nil if no object with that ID is found.
### Usage
```lua
local main = basalt.createFrame()
local container = main:addFrame("container")
local button = container:addButton("myButton")
:setPosition(2, 2)
:setText("My Button")
-- Get the button object by its ID, searching through all containers
local retrievedButton = main:getDeepObject("myButton")
if retrievedButton then
basalt.debug("Button found!")
end
basalt.autoUpdate()
```

View File

@@ -0,0 +1,30 @@
## getObject
### Description
Retrieves an object from the container by its ID.
### Parameters
1. `string` id - The ID of the object you want to retrieve.
### Returns
1. `object` The object with the specified ID, or nil if no object with that ID is found.
### Usage
```lua
local main = basalt.createFrame()
local button = main:addButton("myButton")
:setPosition(2, 2)
:setText("My Button")
-- Get the button object by its ID
local retrievedButton = main:getObject("myButton")
if retrievedButton then
basalt.debug("Button found!")
end
basalt.autoUpdate()
```

View File

@@ -0,0 +1,32 @@
## removeFocusedObject
### Description
Removes the focus from the currently focused object within the container. If no object is focused, this method has no effect.
### Returns
1. `object` The object in use
### Usage
```lua
local main = basalt.createFrame()
local container = main:addFrame()
local inputField1 = container:addInputField()
:setPosition(2, 2)
local inputField2 = container:addInputField()
:setPosition(2, 4)
container:setFocusedObject(inputField1)
main:addButton()
:setPosition(2, 6)
:setText("Remove focus from input fields")
:onClick(function()
container:removeFocusedObject()
basalt.debug("Focus removed from input fields!")
end)
basalt.autoUpdate()
```

View File

@@ -0,0 +1,37 @@
## removeObject
### Description
Removes an object from the container by its ID. If the object is not a direct child of the container, this method will not remove it.
### Parameters
1. `string` id - The ID of the object you want to retrieve.
### Returns
1. `boolean` true if the object was removed
### Usage
```lua
local main = basalt.createFrame()
local container = main:addFrame("container")
local button = container:addButton("removableButton")
:setPosition(2, 2)
:setText("Remove me")
main:addButton()
:setPosition(2, 4)
:setText("Remove the button above")
:onClick(function()
local removed = container:removeObject("removableButton")
if removed then
basalt.debug("Button removed!")
else
basalt.debug("Button not found!")
end
end)
basalt.autoUpdate()
```

View File

@@ -0,0 +1,38 @@
## setFocusedObject
### Description
Sets the focused object within the container. When an object is focused, it will receive keyboard events. Only one object can be focused at a time within a container.
### Parameters
1. `object` object - The object to set as the focused object.
### Returns
1. `object` The object in use
### Usage
```lua
local main = basalt.createFrame()
local container = main:addFrame()
local inputField1 = container:addInput("inputField1")
:setPosition(2, 2)
local inputField2 = container:addInput("inputField2")
:setPosition(2, 4)
main:addButton()
:setPosition(2, 6)
:setText("Focus on inputField1")
:onClick(function()
local focused = container:setFocusedObject(inputField1)
if focused then
basalt.debug("InputField1 is now focused!")
else
basalt.debug("Failed to set focus on InputField1!")
end
end)
basalt.autoUpdate()
```

View File

@@ -0,0 +1,36 @@
## setImportant
### Description
Sets the specified object as "important" within the container. This means the object will be reordered on the same z-index level, making it more important than other objects on the same level. This can be useful when you want to prioritize event handling or drawing order for specific objects.
### Parameters
1. `string` The object to set as important
### Returns
1. `object` the object in use
### Usage
```lua
local main = basalt.createFrame()
local container = main:addFrame()
local inputField1 = container:addInput()
:setPosition(2, 2)
local inputField2 = container:addInput()
:setPosition(2, 4)
inputField1:onKey(function(event, key)
basalt.debug("InputField1 received key press: ", key)
end)
inputField2:onKey(function(event, key)
basalt.debug("InputField2 received key press: ", key)
end)
container:setImportant(inputField1)
basalt.autoUpdate()
```

View File

@@ -0,0 +1,11 @@
## sortElementOrder
### Description
This function is called internally and automatically after objects are added or removed from the container. It sorts all objects by their z-index and the time they were added, ensuring the correct order is maintained. This is essential for proper event handling and drawing order of objects within the container.
As a user, you don't need to call this function directly, as it's automatically taken care of by the library.
### Usage
No direct usage example is provided since this function is called automatically by the library when needed.

View File

@@ -0,0 +1,25 @@
## setFocusedObject
### Description
Updates the z-index of a specified object within the container. This is useful when you need to change the z-index of an object after it has been added to the container.
### Parameters
1. `object` The object whose z-index you want to update.
2. `number` The new z-index value for the object.
### Returns
1. `object` The object in use
### Usage
```lua
local frame = basalt.createFrame()
local button1 = frame:addButton():setZIndex(1)
local button2 = frame:addButton():setZIndex(2)
-- Update button1's z-index to be above button2
frame:updateZIndex(button1, 3)
```

View File

@@ -1,24 +1,12 @@
Dropdowns are objects where the user can click on a button, this will open a list where the user can choose from.
Dropdowns are objects where the user can click on a button, which opens a list from which the user can choose an item.
[Object](objects/Object.md) methods also apply for dropdowns.
List Object methods also apply for dropdowns.
In addition to the Object, VisualObject and List methods, Dropdowns also have the following methods:
| | |
|---|---|
|[addItem](objects/Dropdown/addItem.md)|Adds a new item into the list
|[removeItem](objects/Dropdown/removeItem.md)|Removes a item from the list
|[editItem](objects/Dropdown/editItem.md)|Changes a already existing item in the list
|[getItem](objects/Dropdown/getItem.md)|Returns a item by its index
|[getItemCount](objects/Dropdown/getItemCount.md)|Returns the item count
|[getAll](objects/Dropdown/getAll.md)|Returns the entire list as a table
|[selectItem](objects/Dropdown/selectItem.md)|Selects a item
|[clear](objects/Dropdown/clear.md)|Makes the entire list empty
|[getItemIndex](objects/Dropdown/getItemIndex.md)|Returns the currently active item index
|[setSelectedItem](objects/Dropdown/setSelectedItem.md)|Changes the default bg and fg, when the user selects a item
|[setOffset](objects/Dropdown/setOffset.md)|Changes the list offset
|[getOffset](objects/Dropdown/getOffset.md)|Returns the current offset
|[setDropdownSize](objects/Dropdown/setDropdownSize.md)|Changes the dropdown size
A item-table in dropdowns looks like the following example:
```lua
@@ -28,4 +16,33 @@ item = {
fgCol=colors.white -- the foreground color
args = {} -- custom args you want to pass, which you will be able to access in for example onChange events
}
```
```
Here's an example of how to create a fully functional dropdown using the Dropdown object:
Lua:
```lua
local main = basalt.createFrame()
local aDropdown = main:addDropdown()
aDropdown:addItem("Item 1")
aDropdown:addItem("Item 2", colors.yellow)
aDropdown:addItem("Item 3", colors.yellow, colors.green)
aDropdown:onChange(function(self, item)
basalt.debug("Selected item: ", item.text)
end)
```
XML:
```xml
<dropdown>
<item><text>Item 1</text></item>
<item><text>Item 2</text><bg>yellow</bg></item>
<item><text>Item 3</text><bg>yellow</bg><fg>green</fg></item>
<onChange>
basalt.debug("Selected item: ", item.text)
</onChange>
</dropdown>
```

View File

@@ -1,26 +1,23 @@
## setDropdownSize
Sets the size of the opened dropdown
#### Parameters:
1. `number` The width value
2. `number` The height value
### Description
Sets the width and height of the dropdown menu for a Dropdown object.
### Parameters
1. `width`
2. `height`
### Returns
#### Returns:
1. `object` The object in use
#### Usage:
* Creates a default dropdown, adds 3 entries and sets the dropdown size to 15w, 8h
#### Usage
```lua
local mainFrame = basalt.createFrame()
local aDropdown = mainFrame:addDropdown():setDropdownSize(15,8)
aDropdown:addItem("1. Entry")
aDropdown:addItem("2. Entry")
aDropdown:addItem("3. Entry")
local main = basalt.createFrame()
local aDropdown = main:addDropdown()
aDropdown:setDropdownSize(10, 5)
```
```xml
<dropdown dropdownWidth="15" dropdownHeight="8">
<item><text>1. Entry</text></item>
<item><text>2. Entry</text></item>
<item><text>3. Entry</text></item>
</dropdown>
```

12
docs/objects/Flexbox.md Normal file
View File

@@ -0,0 +1,12 @@
A Flexbox is a layout container that is designed to make it easier to create flexible and responsive UI designs. It allows you to arrange and align its children (elements) within it in a more efficient way.
In addition to the methods inherited from Frame, Container, VisualObject and Object, Flexbox has the following methods:
| | |
|---|---|
|[setDirection](objects/BaseFrame/getOffset.md)|Sets the direction in which the children will be placed
|[getDirection](objects/BaseFrame/getOffset.md)|Returns the direction
|[setSpacing](objects/BaseFrame/setOffset.md)|Sets the space between objects
|[getSpacing](objects/BaseFrame/setOffset.md)|Returns the space
|[setJuustifyContent](objects/BaseFrame/getOffset.md)|Determines how the children are aligned along the main axis
|[getJuustifyContent](objects/BaseFrame/getOffset.md)|Returns the justify content

View File

@@ -1,334 +1,8 @@
Frames are like groups or windows. You can add objects on them and if you move the frame, all its children objects will also be moved. Frames also have
some special functionality to create very advanced programs.
Frame is a subclass of the Container class and inherits from VisualObject and Object classes. Frame objects are used for grouping and organizing other objects within a parent object, providing structure to your interface. The main difference between Frame and BaseFrame is that Frame must always have a parent.
[Object](objects/Object.md) methods also apply for frames.
In addition to the methods inherited from Container, VisualObject and Object, Frame has the following methods:
| | |
|---|---|
|[addObject](objects/Frame/addObject.md)|Adds a new object
|[setBar](objects/Frame/setBar.md)|Sets the top bar text and colors - deprecated
|[setBarTextAlign](objects/Frame/setBarTextAlign.md)|Sets the top bars text align - deprecated
|[showBar](objects/Frame/showBar.md)|Shows the top bar - deprecated
|[setMonitor](objects/Frame/setMonitor.md)|Sets the frame to be a monitor frame (only for base frames)
|[setMonitorScale](objects/Frame/setMonitorScale.md)|Sets the monitor scale (same as monitor.setTextScale)
|[setMirror](objects/Frame/setMirror.md)|Sets the frame to mirror onto a monitor (only for base frames)
|[getObject](objects/Frame/getObject.md)|Returns the object by its name (or id)
|[removeObject](objects/Frame/removeObject.md)|Removes the object by its name (or id)
|[setFocusedObject](objects/Frame/setFocusedObject.md)|Sets the currently focused object by this frame
|[removeFocusedObject](objects/Frame/removeFocusedObject.md)|Removes the currenlty focused object (it only removes beeing focused)
|[getFocusedObject](objects/Frame/getFocusedObject.md)|Returns the currently focused object
|[setMovable](objects/Frame/setMovable.md)|Makes the frame movable (only for sub frames)
|[setOffset](objects/Frame/setOffset.md)|Sets the frames offset (will be added to the childrens x and y positions)
|[getOffset](objects/Frame/getOffset.md)|Returns the current x and y offset
|[addLayout](objects/Frame/addLayout.md)|Adds a new XML Layout into the frame
|[addLayoutFromString](objects/Frame/addLayoutFromString.md)|Adds a new XML Layout via string into the frame
|[getLastLayout](objects/Frame/getLastLayout.md)|Returns a table of all objects generated by the last addLayout/FromString method
|[setTheme](objects/Frame/setTheme.md)|Sets the theme of that frame and all its childrens
|[setScrollable](objects/Frame/setScrollable.md)|Makes the frame scrollable via mousewheel (internally this uses setOffset)
|[setScrollAmount](objects/Frame/setScrollAmount.md)|Sets how far the user is allowed to scroll
This is how you would implement frames via xml:
```xml
<frame>
<frame width="parent.w * 0.5" bg="red">
<button x="2" y="2" width="17" text="Example Button!"/>
</frame>
<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>
```
## Examples
Here are some examples on how you can use frames to create very advanced programs. Because of the screen size limitation of CC:Tweaked frames can become very useful in almost every scenario. You will find some examples here on how you could implement them.
### Menubar for switching frames
This is a example on how you can create a menubar which switches your frames (without animation).
<details>
<summary>Click here to show code</summary>
```lua
local basalt = require("basalt") -- we need basalt here
local main = basalt.createFrame():setTheme({FrameBG = colors.lightGray, FrameFG = colors.black}) -- we change the default bg and fg color for frames
local sub = { -- here we create a table where we gonna add some frames
main:addFrame():setPosition(1, 2):setSize("parent.w", "parent.h - 1"), -- obviously the first one should be shown on program start
main:addFrame():setPosition(1, 2):setSize("parent.w", "parent.h - 1"):hide(),
main:addFrame():setPosition(1, 2):setSize("parent.w", "parent.h - 1"):hide(),
}
local function openSubFrame(id) -- we create a function which switches the frame for us
if(sub[id]~=nil)then
for k,v in pairs(sub)do
v:hide()
end
sub[id]:show()
end
end
local menubar = main:addMenubar():setScrollable() -- we create a menubar in our main frame.
:setSize("parent.w")
:onChange(function(self, val)
openSubFrame(self:getItemIndex()) -- here we open the sub frame based on the table index
end)
:addItem("Example 1")
:addItem("Example 2")
:addItem("Example 3")
-- Now we can change our sub frames, if you want to access a sub frame just use sub[subid], some examples:
sub[1]:addButton():setPosition(2, 2)
sub[2]:addLabel():setText("Hello World!"):setPosition(2, 2)
sub[3]:addLabel():setText("Now we're on example 3!"):setPosition(2, 2)
sub[3]:addButton():setText("No functionality"):setPosition(2, 4):setSize(18, 3)
basalt.autoUpdate()
```
</details>
<br>
<video width="600" controls autoplay loop muted>
<source src="./_media/frames-with-menubars.mp4" type="video/mp4">
</video>
### Sidebar with buttons to switch frames
Here we will find out how to create a sidebar (which are also just frames) - the sidebar should have buttons to opens the frames for us.
<details>
<summary>Click here to show code</summary>
```lua
local basalt = require("basalt") -- we need basalt here
local main = basalt.createFrame():setTheme({FrameBG = colors.lightGray, FrameFG = colors.black})
--[[
Here we create the sidebar, on focus it should change the position to parent.w - (self.w-1) which "opens the frame"
when the focus gets lost we simply change the position to "parent.w"
As you can see we add :setZIndex(25) - this makes sure the sidebar frame is always more important than our normal sub frames.
:setScrollable just makes the sidebar frame scrollable (in case you're adding more frames)
]]
local sidebar = main:addFrame():setBackground(colors.gray):setPosition("parent.w", 1):setSize(15, "parent.h"):setZIndex(25):setScrollable()
:onGetFocus(function(self)
self:setPosition("parent.w - (self.w-1)")
end)
:onLoseFocus(function(self)
self:setPosition("parent.w")
end)
-- Once again we add 3 frames, the first one should be immediatly visible
local sub = {
main:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h"),
main:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h"):hide(),
main:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h"):hide(),
}
--This part of the code adds buttons based on the sub table.
local y = 2
for k,v in pairs(sub)do
sidebar:addButton():setText("Example "..k) -- creating the button and adding a name k is just the index
:setBackground(colors.black)
:setForeground(colors.lightGray)
:setSize("parent.w - 2", 3)
:setPosition(2, y)
:onClick(function() -- here we create a on click event which hides ALL sub frames and then shows the one which is linked to the button
for a, b in pairs(sub)do
b:hide()
v:show()
end
end)
y = y + 4
end
sub[1]:addButton():setPosition(2, 2)
sub[2]:addLabel():setText("Hello World!"):setPosition(2, 2)
sub[3]:addLabel():setText("Now we're on example 3!"):setPosition(2, 2)
sub[3]:addButton():setText("No functionality"):setPosition(2, 4):setSize(18, 3)
basalt.autoUpdate()
```
</details>
<br>
<video width="600" controls autoplay loop muted>
<source src="./_media/frames-with-sidebar.mp4" type="video/mp4">
</video>
### Movable frames with a program object
In this example you will see how you can add movable frames with a program object in it. It also shows you how you dynamically add new frames.
<details>
<summary>Click here to show code</summary>
```lua
local basalt = require("basalt")
local main = basalt.createFrame():setTheme({FrameBG = colors.lightGray, FrameFG = colors.black})
local id = 1
local processes = {}
local function openProgram(path, title, x, y, w, h)
local pId = id
id = id + 1
local f = main:addFrame()
:setMovable()
:setSize(w or 30, h or 12)
:setPosition(x or math.random(2, 12), y or math.random(2, 8))
f:addLabel()
:setSize("parent.w", 1)
:setBackground(colors.black)
:setForeground(colors.lightGray)
:setText(title or "New Program")
f:addProgram()
:setSize("parent.w", "parent.h - 1")
:setPosition(1, 2)
:execute(path or "rom/programs/shell.lua")
f:addButton()
:setSize(1, 1)
:setText("X")
:setBackground(colors.black)
:setForeground(colors.red)
:setPosition("parent.w", 1)
:onClick(function()
f:remove()
processes[pId] = nil
end)
processes[pId] = f
return f
end
openProgram("rom/programs/fun/worm.lua")
main:addButton():setPosition("parent.w - 16", 2):setText("Open"):onClick(function()
openProgram()
end)
basalt.autoUpdate()
```
</details>
<br>
<video width="600" controls autoplay loop muted>
<source src="./_media/dynamic-frames.mp4" type="video/mp4">
</video>
### Resizable frames
If you want to make your frames resizeable, there is no way offered by basalt - so you would have to do it yourself. However such a implementation is very simple as you can see here.
<details>
<summary>Click here to show code</summary>
```lua
local basalt = require("basalt")
local main = basalt.createFrame():setTheme({FrameBG = colors.black, FrameFG = colors.lightGray})
local sub = main:addFrame():setSize(25, 12):setPosition(3, 3)
local function makeResizeable(frame, minW, minH, maxW, maxH)
minW = minW or 4
minH = minH or 4
maxW = maxW or 99
maxH = maxH or 99
local btn = frame:addButton()
:setPosition("parent.w", "parent.h")
:setSize(1, 1)
:setText("/")
:setForeground(colors.blue)
:setBackground(colors.black)
:onDrag(function(self, event, btn, xOffset, yOffset)
local w, h = frame:getSize()
local wOff, hOff = w, h
if(w+xOffset-1>=minW)and(w+xOffset-1<=maxW)then
wOff = w+xOffset-1
end
if(h+yOffset-1>=minH)and(h+yOffset-1<=maxH)then
hOff = h+yOffset-1
end
frame:setSize(wOff, hOff)
end)
end
makeResizeable(sub, 8, 4)
sub:addLabel():setText("Hello World")
basalt.autoUpdate()
```
</details>
<br>
<video width="600" controls autoplay loop muted>
<source src="./_media/resizable-frames.mp4" type="video/mp4">
</video>
### Scrollable frames
Another important feature of frames is the possibility to make them scrollable. Basalt only provides vertical scrolling for frames. If you want to make horizontal scrolling possible, you need to do it yourself. Also, if you're using :setScrollable() the amount to scroll is based on the object's y-position + height - you can change this by using :setScrollAmount(amount). Only count's for the basalt implementation of scrollable frames.
<details>
<summary>Click here to show code</summary>
```lua
local basalt = require("basalt")
local main = basalt.createFrame():setTheme({FrameBG = colors.black, FrameFG = colors.lightGray})
-- Vertical scrolling is pretty simple, as you can tell:
local sub1 = main:addFrame():setScrollable():setSize(20, 15):setPosition(2, 2)
sub1:addLabel():setPosition(3, 2):setText("Scrollable")
sub1:addLabel():setPosition(3, 12):setText("Inside")
sub1:addLabel():setPosition(3, 20):setText("Outside")
-- Here we create a custom scroll event as you can see we dont add a :setScrollable() method to our frame, instead we add a custom scroll event
local objects = {}
local sub2 = main:addFrame():setPosition(23, 2):setSize(25, 5):onScroll(function(self, event, dir)
local maxScroll = 0
for k,v in pairs(objects)do -- here we iterate trough every object and get their x position + width this way we can find out what's the maximum allowed value to scroll
local x = v:getX()
local w = v:getWidth()
maxScroll = x + w > maxScroll and x + w or maxScroll -- if you don't understand this line, http://lua-users.org/wiki/TernaryOperator
end
local xOffset = self:getOffset()
if(xOffset+dir>=0 and xOffset+dir<=maxScroll-self:getWidth())then
self:setOffset(xOffset+dir, 0)
end
end)
-- Because we need to iterate the objects, we add them into a table.
table.insert(objects, sub2:addButton():setPosition(2, 2):setText("Scrollable"))
table.insert(objects, sub2:addButton():setPosition(16, 2):setText("Inside"))
table.insert(objects, sub2:addButton():setPosition(30, 2):setText("Outside"))
basalt.autoUpdate()
```
</details>
<br>
<video width="600" controls autoplay loop muted>
<source src="./_media/scrollable-frames.mp4" type="video/mp4">
</video>
|[getOffset](objects/BaseFrame/getOffset.md)|Returns the current offset of the BaseFrame object
|[setOffset](objects/BaseFrame/setOffset.md)|Sets a new offset for the BaseFrame object

View File

@@ -0,0 +1,20 @@
## getOffset
### Description
Returns the current offset
### Returns
1. `x` the x coordinate
2. `y` the y coordinate
### Usage
* Returns the offset coordinates
```lua
local myFrame = basalt.createFrame():setOffset(5, 3)
basalt.debug(myFrame:getOffset())
```

View File

@@ -1,25 +1,36 @@
## setOffset
### Description
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 also be supplied with negative values
The function can also be supplied with negative values.
### Parameters
#### Parameters:
1. `number` The x direction offset (+/-)
2. `number` The y direction offset (+/-)
#### Returns:
### Returns
1. `frame` The frame being used
#### Usage:
### Usage
* Creates a new base frame with x offset of 5 and a y offset of 3
```lua
local myFrame = basalt.createFrame():setOffset(5, 3)
```
* Creates with 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 a base frame with 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
local myFrame = basalt.createFrame():setOffset(5, -5)
```
```xml
<frame xOffset="5" yOffset="-5"></frame>
```
```

17
docs/objects/Graph.md Normal file
View File

@@ -0,0 +1,17 @@
Graph is a versatile object for visualizing data in various formats such as scatter, line, or bar graphs. It inherits from the ChangeableObject, VisualObject, and Object classes, which provide it with additional properties and methods. The Graph object allows you to customize its appearance, manage data points, and define the display range.
In addition to the methods inherited from the Object, VisualObject, and ChangeableObject classes, Graph objects have the following methods:
| | |
|---|---|
|[setGraphColor](objects/Graph/setGraphColor.md)|Sets the color of the graph
|[setGraphSymbol](objects/Graph/setGraphSymbol.md)|Sets the symbol used to represent data points in the graph
|[getGraphSymbol](objects/Graph/getGraphSymbol.md)|Returns the symbol used to represent data points in the graph
|[addDataPoint](objects/Graph/addDataPoint.md)|Adds a data point to the graph
|[setMaxValue](objects/Graph/setMaxValue.md)|Sets the maximum value displayed on the graph
|[getMaxValue](objects/Graph/getMaxValue.md)|Returns the maximum value displayed on the graph
|[setMinValue](objects/Graph/setMinValue.md)|Sets the minimum value displayed on the graph
|[getMinValue](objects/Graph/getMinValue.md)|Returns the minimum value displayed on the graph
|[setGraphType](objects/Graph/setGraphType.md)|Sets the type of the graph (scatter, line, or bar)
|[setMaxEntries](objects/Graph/setMaxEntries.md)|Sets the maximum number of data points displayed on the graph
|[getMaxEntries](objects/Graph/getMaxEntries.md)|Returns the maximum number of data points displayed on the graph

View File

@@ -0,0 +1,20 @@
## getMinValue
### Description
Returns the current minimum value of the graph.
### Returns
1. `number` minValue - The current minimum value of the graph.
### Usage
* Gets the minimum value of the graph
```lua
local mainFrame = basalt.createFrame()
local aGraph = mainFrame:addGraph()
local minValue = aGraph:getMinValue()
basalt.debug("Min value:", minValue)
```

Some files were not shown because too many files have changed in this diff Show More