Files
Basalt2/docs/guides/getting-started.md
Robert Jelic b5d57bce6f Docs
2025-02-23 13:45:44 +01:00

1.8 KiB

Getting Started with Basalt

Installation

Checkout download to learn how to get basalt on your CC:Tweaked computer.

Creating Your First UI

Here's a simple example that creates a window with a button:

local basalt = require("basalt")

-- Get the main frame (your window)
local main = basalt.getMainFrame()

-- Add a button
main:addButton()
    :setText("Click me!")
    :setPosition(4, 4)
    :onMouseClick(function()
        -- Do something when clicked
    end)

-- Start Basalt
basalt.run()

Adding More Elements

You can add various UI elements to your frame:

-- Add a label (text)
main:addLabel()
    :setText("Hello World")
    :setPosition(4, 2)

-- Add an input field
main:addInput()
    :setPosition(4, 6)
    :setSize(20, 1)

-- Add a list
main:addList()
    :setPosition(4, 8)
    :setSize(20, 6)
    :addItem("Item 1")
    :addItem("Item 2")

Basic Properties

Most elements support these common properties:

element:setPosition(x, y)        -- Set position
element:setSize(width, height)   -- Set size
element:setBackground(color)     -- Set background color
element:setForeground(color)     -- Set text color

Basic Events

Elements can respond to user interaction:

element:onMouseClick(function()
    -- Called when clicked
end)

element:onMouseEnter(function()
    -- Called when mouse enters the element (only available on CraftOS-PC)
end)

element:onChange(function(self, value)
    -- Called when value changes (inputs, lists, etc)
end)

Next Steps