Files
Basalt/docs/objects/Object.md
Robert Jelic 1d3e2018ef docs update
Updated some docs stuff
2022-10-09 12:05:30 +02:00

3.7 KiB

This is the base class for all visual objects. It covers positioning, sizing, showing/hiding and much more.

By default a freshly created object is visible and doesn't listens to any incoming events. Its default position is always 1, 1 (based on it's parent frame). The default anchor is also topLeft.

show Makes the object visible
hide Makes the object invisible
isVisible Returns if the object is currently visible
enable Listens to incoming events
disable Ignores all incoming events
setPosition Changes the position (x,y)
getPosition Returns the current position
setBackground Changes the object's background
setForeground Changes the object's text color
setSize Changes the object to a new size
getSize Returns the width and height
setFocus Changes the object to be the focused object
isFocused Returns if the object is currently focused
setZIndex Changes the z-index
setParent Changes the parent of that object
getAnchorPosition Returns the relative x and y coordinates of that object
setAnchor Sets the current anchor
getAbsolutePosition Returns the absolute x and y coordinates of that object
setValue Changes the stored value
getValue Returns the currently stored value
getName Returns the name (or in other words: id) of that object
setShadow Changes the shadow of that object
setBorder Changes the border lines

Events

This is a list of all available events for all objects:

onClick Fires as soon as the object gets clicked
onClickUp Fires as soon as the mouse button gets released on the object
onRelease Fires as soon as the mouse button gets released
onScroll Fires as soon as you scroll with the mousewheel
onDrag Fires as soon as the object is beeing dragged
onKey Fires when the object is focused and a keyboard key has been clicked
onChar Fires when the object is focused and a character has been clicked
onKeyUp Fires when the object is focused and a keyboard key has been released
onChange Fires when the object value has been changed
onResize Fires when the object got resized
onReposition Fires when the object has been repositioned
onGetFocus Fires when the object is focused
onLoseFocus Fires when the object lost it's focus
onEvent Fires on any other event

Sidenote: When you use return false this will skip the object's event handler. Here is a example for that.

This code would make it impossible to write a into the input:

local basalt = require("basalt")

local main = basalt.createFrame()
local input = main:addInput()
  :setPosition(3,3)

function checkInput(self, event, char)
  if(char=="a")then
    return false
  end
end
main:onChar(checkInput)