import{_ as i,a,b as e,ag as t}from"./chunks/framework.BcrMLAmg.js";const o=JSON.parse('{"title":"Reactive System","description":"","frontmatter":{},"headers":[],"relativePath":"guides/reactive.md","filePath":"guides/reactive.md","lastUpdated":1744373216000}'),n={name:"guides/reactive.md"};function l(h,s,k,p,r,E){return e(),a("div",null,s[0]||(s[0]=[t(`
The reactive system in Basalt allows you to create dynamic property values using expressions. These expressions automatically update when related values change.
local basalt = require("basalt")
-- Create a simple label and center it horizontally
local main = basalt.getMainFrame()
:addLabel()
:setText("Hello World")
:setX("{parent.width / 2 - self.width / 2}") -- Centers the label horizontally
-- Create a progress bar that takes 80% of parent width
main:addProgressbar()
:setWidth("{parent.width * 0.8}")
:setX("{parent.width * 0.1}") -- 10% margin on both sidesIn reactive expressions, you have access to:
self - The current elementparent - The parent elementelementName - A given name of a elementlocal frame = basalt.getMainFrame()
:addFrame()
:setSize("{parent.width * 0.5}", "{parent.height * 0.5}") -- Takes half of parent size
:setPosition("{parent.width / 2 - self.width / 2}", -- Centers the frame
"{parent.height / 2 - self.height / 2}")local label = frame:addLabel()
:setText("Dynamic width based on text")
:setWidth("{#self.text}") -- Width equals text lengthlocal slider = frame:addSlider("mySlider")
:setPosition(2, 2)
:setSize(10, 1)
local progress = frame:addProgressBar()
:setPosition(2, 4)
:setSize(10, 1)
:setProgress("{mySlider.value}") -- Progress syncs with slider value{} to define a reactive expression