Difference between revisions of "Lua API:Interface"
(Interface methods) |
(→Button:action) |
||
Line 26: | Line 26: | ||
Sets the listener for button actions | Sets the listener for button actions | ||
'''Example:''' | '''Example:''' | ||
− | + | <syntaxhighlight lang="lua"> | |
− | + | local newButton = Button:new(10, 10, 100, 17, "Press to change text") | |
− | + | newButton:action(function(sender) sender:text("Text changed") end) | |
+ | interface.addComponent(newButton) | ||
+ | </syntaxhighlight> | ||
==== Button:text ==== | ==== Button:text ==== |
Revision as of 20:36, 1 September 2012
The Interface API includes objects for UI components such as buttons, labels and checkboxes and methods for access to the very primitive window manager and input events.
Contents
Classes
Component
Abstract class, no constructor
Component:size
number, number Component:size()
Returns the width and height of the component
nil Component:size(number width, number height)
Sets the size of the component to be width by height
Component:position
number, number Component:position()
Returns the x and y coord of the component
nil Component:position(number x, number y)
Sets the position of the component to be x, y
Button
Button Button:new(number x, number y, number width, number height, [string text = "", [string tooltip = ""]])
Extends Component, fires "action" when clicked
Button:action
nil Button:action(function(sender) actionListener)
Sets the listener for button actions Example:
local newButton = Button:new(10, 10, 100, 17, "Press to change text")
newButton:action(function(sender) sender:text("Text changed") end)
interface.addComponent(newButton)
Button:text
string Button:text()
Returns the button text
nil Button:text(string text)
Sets the text of the button
Methods
interface.addComponent
nil interface.addComponent(Component newComponent)
Add a component to master game window.
interface.removeComponent
nil interface.removeComponent(Component newComponent)
Remove a component from the master game window.