Widget

From TargetWiki

A widget is an element of a GUI. Different types of widgets do different things, but all widgets have certain common functions that can be called.

Since a widget is a Lua object, calls should use the object:function() syntax. Also, all Lua object functions can also be called on any widget.

Functions

parent()
This returns the widget that this widget is attached to.
visible()
This returns true or false depending on whether this widget is set to be visible or not. Note that this is different from whether it really is visible - a widget may be set to visible, but not actually visible because it's attached to another widget that's not visible. This defaults to true.
visiblestate()
This returns true or false based on the actual visibility of the widget.
setvisible( <boolean> )
Sets the visibility state of the widget.
enabled()
This returns true or false depending on whether the widget is set to be enabled. Like visibility, a widget attached to a disabled widget is also disabled - even if it's set to be enabled. A disabled widget usually accepts no mouseover, no focus, no input, etc. This defaults to true.
enabledstate()
Like visiblestate(), this returns the actual enabled status of the widget.
setenabled( <boolean> )
Sets the enabled state of the widget.
mouseover()
Returns true if the mouse is currently over this widget, false otherwise.
focus()
Returns true if this widget currently has the input focus, false otherwise.
align()
Returns the alignment of the widget. Alignment is where the widget positions itself relative to its parent. The possible values are:
  • gui.topleft
  • gui.top
  • gui.topright
  • gui.left
  • gui.middle
  • gui.right
  • gui.bottomleft
  • gui.bottom
  • gui.bottomright
setalign( <alignment> )
This sets the alignment of the widget. This defaults to gui.topleft.
eventhandler()
This returns a standard Targetware event handler. When the event handler's function(s) are called, the first argument indicates the type of event.
  • gui.show. The widget became visible.
  • gui.hide. The widget became invisible.
  • gui.focus. The widget received the input focus.
  • gui.losefocus. The widget lost the input focus.
  • gui.mouseover. The mouse is over the widget.
  • gui.losemouseover. The mouse is no longer over the widget.
  • gui.action. The widget has done something, such as a button press.
  • gui.cancel. Some widgets can generate a cancel event.
  • gui.select. The widget has changed an internal selection, such as selected text in an edit box.
  • gui.contents. The widget's contents have changed, such as the text in an edit box.
  • gui.offset. The scrolling offset of a widget has changed.
  • gui.move. The widget has changed position on screen.
  • gui.resize. The widget has changed size on screen.
index()
This returns the draw order of the widget amongst its siblings. Each widget that shares the same parent has a unique draw index. Lower numbers are drawn first, appearing 'underneath' higher numbers.
setindex( <number> )
This sets the the draw order for the widget. The draw order for other widgets that share the same parent may change as well to accomodate this widget's new position.
top()
This sets the widget's draw order to be the highest amongst its siblings.
bottom()
This sets the widget's draw order to be the lowest amongst its siblings.

List of Widgets

Views