Class List

A scrollable list

Usage:

     -- Create a list of 20 items
     local list = List(0, 0, 100, 100, 12)
     for i=1,20,1 do
       local item = list:emplaceItem("Item " .. i)
       item:addListener("selected", function() world.logInfo(item.text) end)
     end

Fields

List.backgroundColor The background color of this list.
List.borderColor The border color of this list.
List.borderSize The thickness of this list's border.
List.itemPadding Padding in between items.
List.scrollBarSize Thickness of the scroll bar

Constructor

List:_init (x, y, width, height, itemSize[, itemFactory[, horizontal=false]]) Constructs a new List.

Methods

List:addItem (item) Adds an item to this list.
List:clearItems () Removes all items from this list.
List:emplaceItem (...) Constructs and adds an item to this list.
List:filter (filter) Filters the items in this list.
List:getItem (index) Retrieve the item at a given index.
List:indexOfItem (item) Get the index of the given item.
List:removeItem (target) Removes an item from this list.
List:scroll (up) Scroll the list one item.


Fields

List.backgroundColor
The background color of this list.
List.borderColor
The border color of this list.
List.borderSize
The thickness of this list's border.
List.itemPadding
Padding in between items.
List.scrollBarSize
Thickness of the scroll bar

Constructor

List:_init (x, y, width, height, itemSize[, itemFactory[, horizontal=false]])
Constructs a new List. New lists are by default vertical.

Parameters:

  • x The x coordinate of the new component, relative to its parent.
  • y The y coordinate of the new component, relative to its parent.
  • width The width of the new component.
  • height The height of the new component.
  • itemSize The height(if vertical) or width (if horizontal) of each list item.
  • itemFactory A function to return a new item. The arguments should be x, y, width, height. Defaults to creating TextRadioButtons. (optional)
  • horizontal If true, this list will be horizontal. (default false)

Methods

List:addItem (item)
Adds an item to this list.

Parameters:

  • item The item to add to this list.

Returns:

  1. The item added to this list.
  2. The list index of the added item.
List:clearItems ()
Removes all items from this list.
List:emplaceItem (...)
Constructs and adds an item to this list.

Parameters:

  • ... Arguments to pass to the item constructor.

Returns:

  1. The newly created list item.
  2. The list index of the new list item.
List:filter (filter)
Filters the items in this list.

Parameters:

  • filter A function that should take a list item as the argument, and return true to show that item or false to hide that item. If nil, show all items.
List:getItem (index)
Retrieve the item at a given index.

Parameters:

  • index The index to retrieve the item from.

Returns:

    The item at the given index, or nil if there is none.
List:indexOfItem (item)
Get the index of the given item.

Parameters:

  • item The item to find the index of.

Returns:

    The index of the item, or -1 if the item was not found.
List:removeItem (target)
Removes an item from this list.

Parameters:

  • target Either the item to remove, or the index of the item to remove.

Returns:

  1. The removed item, or nil if the item was not removed.
  2. The index of the removed item, or -1 if the item was not removed.
List:scroll (up)
Scroll the list one item.

Parameters:

  • up Up or down.
generated by LDoc 1.4.3 Last updated 2015-02-10 07:20:59