Class Widget

Widget class.

Methods

Widget:defineAttribute (name, descriptor) Define a custom attribute for this widget.
Widget:bubbleEvent (eventName[, data]) Fire an event on this widget and each ancestor.
Widget:getPreviousSibling () Get widget's previous sibling.
Widget:getNextSibling () Get widget's next sibling.
Widget:focus () Attempt to focus the widget.
Widget:getNextNeighbor () Get the next widget, depth-first.
Widget:getPreviousNeighbor () Get the previous widget, depth-first.
Widget:addChild (data) Add a child to this widget.
Widget:getX () Get the widget's X coordinate.
Widget:getY () Get the widget's Y coordinate.
Widget:getWidth () Get the widget's calculated width.
Widget:getHeight () Get the widget's calculated height.
Widget:getContentWidth () Get the content width.
Widget:getContentHeight () Get the content height.
Widget:getRectangle (useMargin, usePadding) Get x/y/width/height values describing a rectangle within the widget.
Widget:isAt (x, y) Determine whether a point is within a widget.
Widget:eachAncestor (includeSelf) Iterate widget's ancestors.
Widget:reshape () Reshape the widget.

API Properties

Widget.focused Whether this widget has keyboard focus.
Widget.hovered Whether the pointer is within this widget.
Widget.pressed Whether the pointer was pressed on this widget and not yet released.

Internal Properties

Widget.isWidget Identifies this object as a widget.
Widget.isReshaping Whether the widget is currently being reshaped.
Widget.hasType Whether this widget has a type.
Widget.fontData The Font object associated with the widget.
Widget.textData The Text object associated with the widget.

Static Functions

Widget.register (name, decorator) Register a custom widget type.

Constructor

Luigi.Widget (layout[, data]) Widget pseudo-constructor.

Methods

Widget:defineAttribute (name, descriptor)
Define a custom attribute for this widget.

Parameters:

  • name string The name of the attribute.
  • descriptor table A table, optionally containing get and set functions (see Attribute).

Returns:

    Widget Return this widget for chaining.
Widget:bubbleEvent (eventName[, data])
Fire an event on this widget and each ancestor.

If any event handler returns non-nil, stop the event from propagating.

Parameters:

  • eventName string The name of the Event.
  • data table Information about the event to send to handlers. (optional)

Returns:

    mixed The first value returned by an event handler.
Widget:getPreviousSibling ()
Get widget's previous sibling.

Returns:

    Widget or nil The widget's previous sibling, if any.
Widget:getNextSibling ()
Get widget's next sibling.

Returns:

    Widget or nil The widget's next sibling, if any.
Widget:focus ()
Attempt to focus the widget.

Unfocus currently focused widget, and focus this widget if it's focusable.

Returns:

    boolean true if this widget was focused, else false.
Widget:getNextNeighbor ()
Get the next widget, depth-first.

If the widget has children, returns the first child. Otherwise, returns the next sibling of the nearest possible ancestor. Cycles back around to the layout root from the last widget in the tree.

Returns:

    Widget The next widget in the tree.
Widget:getPreviousNeighbor ()
Get the previous widget, depth-first.

Uses the reverse of the traversal order used by getNextNeighbor. Cycles back around to the last widget in the tree from the layout root.

Returns:

    Widget The previous widget in the tree.
Widget:addChild (data)
Add a child to this widget.

Parameters:

  • data Widget or table A widget or definition table representing a widget.

Returns:

    Widget The newly added child widget.
Widget:getX ()
Get the widget's X coordinate.

Returns:

    number The widget's X coordinate.
Widget:getY ()
Get the widget's Y coordinate.

Returns:

    number The widget's Y coordinate.
Widget:getWidth ()
Get the widget's calculated width.

Returns:

    number The widget's calculated width.
Widget:getHeight ()
Get the widget's calculated height.

Returns:

    number The widget's calculated height.
Widget:getContentWidth ()
Get the content width.

Gets the combined width of the widget's children.

Returns:

    number The content width.
Widget:getContentHeight ()
Get the content height.

Gets the combined height of the widget's children.

Returns:

    number The content height.
Widget:getRectangle (useMargin, usePadding)
Get x/y/width/height values describing a rectangle within the widget.

Parameters:

  • useMargin boolean Whether to adjust the rectangle based on the widget's margin.
  • usePadding boolean Whether to adjust the rectangle based on the widget's padding.

Returns:

  1. number The upper left corner's X position.
  2. number The upper left corner's Y position.
  3. number The rectangle's width
  4. number The rectangle's height
Widget:isAt (x, y)
Determine whether a point is within a widget.

Parameters:

  • x number The point's X coordinate.
  • y number The point's Y coordinate.

Returns:

    boolean true if the point is within the widget, else false.
Widget:eachAncestor (includeSelf)
Iterate widget's ancestors.

Parameters:

  • includeSelf boolean Whether to include this widget as the first result.

Returns:

    function Returns an iterator function that returns widgets.

Usage:

    for ancestor in myWidget:eachAncestor(true) do
        print(widget.type or 'generic')
    end
Widget:reshape ()
Reshape the widget.

Clears calculated widget dimensions, allowing them to be recalculated, and fires a Reshape event (does not bubble). Called recursively for each child.

When setting a widget's width or height, this function is automatically called on the parent widget.

API Properties

These properties may be useful when creating user interfaces, and are a formal part of the API.
Widget.focused
Whether this widget has keyboard focus.

Can be used by styles and themes. This value is automatically set by the Input class, and should generally be treated as read-only.

Widget.hovered
Whether the pointer is within this widget.

Can be used by styles and themes. This value is automatically set by the Input class, and should generally be treated as read-only.

Widget.pressed
Whether the pointer was pressed on this widget and not yet released.

Can be used by styles and themes. This value is automatically set by the Input class, and should generally be treated as read-only.

Internal Properties

These properties are used internally, but are not likely to be useful when creating user interfaces; they are not a formal part of the API and may change at any time.
Widget.isWidget
Identifies this object as a widget.

Can be used to determine whether an unknown object is a widget.

Widget.isReshaping
Whether the widget is currently being reshaped.

Used internally by reshape to prevent stack overflows when handling Reshape events.

Widget.hasType
Whether this widget has a type.

Used by the type attribute to determine whether to run the type initializer when the widget's type is set. After a type initializer has run, hasType becomes true and no other type initializers should run on the widget.

Widget.fontData
The Font object associated with the widget.
Widget.textData
The Text object associated with the widget.

Static Functions

Widget.register (name, decorator)
Register a custom widget type.

Parameters:

  • name string A unique name for this type of widget.
  • decorator function(Widget) An initialization function for this type of widget.

Constructor

Luigi.Widget (layout[, data])
Widget pseudo-constructor.

Parameters:

  • layout Layout The layout this widget belongs to.
  • data table The data definition table for this widget. This table is identical to the constructed widget. (optional)

Returns:

    Widget A Widget instance.
generated by LDoc 1.4.3 Last updated 2015-12-17 04:20:17