10 KiB
This is the base class of all visual objects. This means, if you create a button, label, frame or something else visual (no timers, threads or animations) the following methods apply:
show
Shows the object (only if the parent frame is already visible)
Returns:
objectThe object in use
Usage:
- Shows a frame named "myFirstFrame"
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local button = mainFrame:addButton("myFirstButton")
button:show()
hide
Hides the object
Returns:
objectThe object in use
Usage:
- Hides a frame named "myFirstFrame"
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local button = mainFrame:addButton("myFirstButton"):setText("Close"):onClick(function() mainFrame:hide() end)
button:show()
setPosition
Changes the position relative to its parent frame
Parameters:
numberx coordinatenumbery coordinatebooleanWhether it will add/remove to the current coordinates instead of setting them
Returns:
objectThe object in use
Usage:
- Sets the Buttons position to an x coordinate of 2 with a y coordinate of 3
local mainFrame = basalt.createFrame("myFirstFrame"):show()
mainFrame:addButton("myFirstButton"):setPosition(2,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:
number|colorBackground color
Returns:
objectThe object in use
Usage:
- Creates a frame, and sets its background color to
colors.gray
local mainFrame = basalt.createFrame("myFirstFrame"):setBackground(colors.gray)
setForeground
Changes the object text color
Parameters:
number|colorForeground color
Returns:
objectThe object in use
Usage:
- Creates a frame, and sets its foreground color to
colors.green
local mainFrame = basalt.createFrame("myFirstFrame"):setForeground(colors.green)
setSize
Changes the object size
Parameters:
numberwidthnumberheight
Returns:
objectThe object in use
Usage:
- Sets the frame to have a width of 15 and a height of 12
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local subFrame = mainFrame:addFrame("myFirstSubFrame"):setSize(15,12):show()
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:
objectThe object in use
Usage:
- Sets the button to the focused object
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setFocus():show()
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:
numberz-index
Returns:
objectThe object in use
Usage:
- Sets the z-index of "myFirstButton" to
1and the z-index of "myFirstLabel" to1
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setZIndex(1):setPosition(2,2):show()
local aLabel = mainFrame:addButton("myFirstLabel"):setZIndex(2):setPosition(2,2):setText("I am a label!"):show()
setParent
Sets the parent frame of the object
Parameters:
frameThe to-be parent frame
Returns:
objectThe object in use
Usage:
- Sets the parent frame of the random frame, adding it to the main frame when the button is clicked"
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aRandomFrame = basalt.createFrame("aRandomFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):onClick(
function()
aRandomFrame:setParent(mainFrame)
end
):show()
isFocused
Returns if the object is currently the focused object of the parent frame
Returns:
booleanWhether the object is focused
Usage:
- Prints whether the button is focused to the debug console
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):show()
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:
number|nilxnumber|nily, if nothing it uses the object's x, y
Returns:
numberxnumbery
Usage:
- Prints the anchor position to the debug console
local mainFrame = basalt.createFrame("myFirstFrame"):setSize(15,15):show()
local aButton = mainFrame:addButton("myFirstButton")
:setAnchor("bottomRight")
:setSize(8,1)
:setPosition(1,1)
:show()
basalt.debug(aButton:getAnchorPosition()) -- returns 7,14 (framesize - own size) instead of 1,1
setAnchor
Sets the anchor of the object
Parameters:
stringAnchor sides("topLeft" "top", "topRight", "right", "bottomRight", "bottom", "bottomLeft", "left", "center")
Returns:
objectThe object in use
Usage:
- Sets the button to have an anchor of
bottomRight
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton")
:setAnchor("bottomRight")
:setSize(8,1)
:setPosition(-8,1)
:show()
getAbsolutePosition
Converts the relative coordinates into absolute coordinates
Parameters:
number|nilxnumber|nily
Returns:
objectThe object in use
Usage:
- Creates a frame and a button and prints the button's absolute position to the debug console
local mainFrame = basalt.createFrame("myFirstFrame"):setPosition(3,3):show()
local aButton = mainFrame:addButton("myFirstButton"):setSize(8,1):setPosition(4,2):show()
basalt.debug(aButton:getAbsolutePosition()) -- returns 7,5 (frame coords + own coords) instead of 4,2
setTextAlign
Sets the text align of the object (for example buttons)
Parameters:
stringhorizontalstringvertical ("left", "center", "right")
Returns:
objectThe object in use
Usage:
- Creates a button with text aligned to
right, center
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton")
:setSize(12,3)
:setTextAlign("right", "center")
:setText("Don't...")
:show()
setValue
Sets the value of that object (input, label, checkbox, textfield, scrollbar,...)
Parameters:
anyValue to set the object to
Returns:
objectThe object in use
Usage:
- Creates a checkbox and ticks it
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):setValue(true):show()
getValue
Returns the currently saved value
Returns:
anyObject's value
Usage:
- Prints the value of the checkbox to the debug console
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aCheckbox = mainFrame:addCheckbox("myFirstCheckbox"):setValue(true):show()
basalt.debug(aCheckbox:getValue()) -- returns true
getHeight/getWidth
Returns the respective height/width of the object
Returns:
numberheight/width
Usage:
- Prints the height of the object to the debug console
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setSize(5,8):show()
basalt.debug(aButton:getHeight()) -- returns 8
isVisible
Returns if the object is currently visible
Returns:
boolean
Usage:
- Prints boolean visibility of object to debug console
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local aButton = mainFrame:addButton("myFirstButton"):setSize(5,8):show()
basalt.debug(aButton:isVisible()) -- returns true
getName
Returns the given name of the object
Returns:
stringname
Usage:
- Prints name of object to debug window
local mainFrame = basalt.createFrame("myFirstFrame"):show()
basalt.debug(mainFrame:getName()) -- returns myFirstFrame
setShadow
Sets the shadow color - default: colors.black
Parameters:
number|colorShadow color
Returns:
objectThe object in use
Usage:
- Sets the shadow to green and shows it:
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local subFrame = mainFrame:addFrame("mySubFrame")
:setMoveable()
:setSize(18,6)
:setShadow(colors.green)
:showShadow(true)
:show()
showShadow
Shows or hides the shadow
Parameters:
booleanWhether it should show or hide the shadow
Returns:
objectThe object in use
Usage:
- Shows the shadow:
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local subFrame = mainFrame:addFrame("mySubFrame")
:setMoveable()
:setSize(18,6)
:showShadow(true)
:show()
setBorder
Sets the border color - default: colors.black
Parameters:
number|colorBorder color
Returns:
objectThe object in use
Usage:
- Sets the border to green and shows it:
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local subFrame = mainFrame:addFrame("mySubFrame")
:setMoveable()
:setSize(18,6)
:setBorder(colors.green)
:showBorder("left", "top", "right", "bottom")
:show()
showBorder
Shows or hides the border
Parameters:
stringsWhether it should show or hide the border on the specific sides ("left", "top", "right", "bottom")
Returns:
objectThe object in use
Usage:
- Shows the border:
local mainFrame = basalt.createFrame("myFirstFrame"):show()
local subFrame = mainFrame:addFrame("mySubFrame")
:setMoveable()
:setSize(18,6)
:showBorder("left", "top", "right", "bottom")
:show()