Skip to content

EmuList

Dragonite edited this page Jul 4, 2020 · 7 revisions

Lists need no introduction: they contain a series of elements, one or more of which may be selected. They are similar to EmuRadioArrays or EmuBitfields, depending on the use case, with the exception that they will automatically show a scroll bar if they become too long, making them good for collections of options that are large or have the potential to become large.

A list enumerating several ficticious locations.

Constructor

Inheritance: EmuCore / EmuCallback

EmuList(x, y, w, h, text, text_vacant, element_height, content_slots, callback, [list])
Parameter Type Description
x real The x coordinate where the list will be created
y real The y coordinate where the list will be created
w real The width of the list
h real The height of the list
text string The title of the list
content_slots real The number of entries that may be shown in the list before it scrolls
callback function The function invoked when list entries are selected or deselected

Relevant Methods

EmuList::AddEntries(entries)

Returns: N/A

Parameter Type Description
entries string or instance The entries you wish to add to the list

Add entries to a list. If you provide a single entry, it will be added by itself whereas an array of entries will add each element in the array.

Entries may be strings or instances (of a GameMaker object or a struct) which possess a name variable.

This method is only usable if you have not specified an external list to be used.

EmuList::SetList(list)

Returns: N/A

Parameter Type Description
list ds_list The index of an existing ds_list containing data to populate the list with

Lists may optionally take an index of an existing ds_list to populate its entries. If you specify one, it will not be destroyed when the EmuList is and you may not add entries to it manually.

EmuList::SetVacantText(text)

Returns: N/A

Parameter Type Description
text string The text shown if the list is empty

You may use this method to set text to be drawn in place of an empty list.

EmuList::Clear()

Returns: N/A

Removes all entries from the list. This method is only usable if you have not specified an external list to be used.

EmuList::GetSelected(index)

Returns: boolean

Parameter Type Description
index real The list index which you would like to check for selection

Find whether or not a specific index in the list is currently selected.

EmuList::ClearSelection()

Returns: N/A

Deselects all entries in the list.

EmuList::Select(index, update_position)

Returns: N/A

Parameter Type Description
index real The index in the list you would like to select
update_position boolean Whether or not the list should automatically scroll to the selected position

Select an index in the list. If update_position is true, the list will scroll to the index if it has to.

EmuList::Deselect(index)

Returns: N/A

Parameter Type Description
index real The index in the list you would like to select

Deselect an index in the list.

EmuList::SetEntryTypes(index)

Returns: N/A

Parameter Type Description
type E_ListEntryTypes The type of the entries in the list

Set the type of entries in the list. The default type is E_ListEntryTypes.STRINGS.

Note that attempting to render a list of structs or instances which do not have a name variable will throw an exception.

EmuList::SetCallbackDouble(callback)

Returns: N/A

Parameter Type Description
callback function The function invoked when an element is double-clicked

Set the callback function for when an element in the list is double-clicked. The callback function will receive the index of the entry under the cursor.

EmuList::SetCallbackMiddle(callback)

Returns: N/A

Parameter Type Description
callback function The function invoked when an element is middle-clicked

Set the callback function for when an element in the list is middle-clicked. The callback function will receive the index of the entry under the cursor.

EmuList::SetMultiSelect(multi_select, auto_select, toggle_select)

Returns: N/A

Parameter Type Description
multi_select boolean Whether or not multiple entries may be selected at once
auto_select boolean Whether or not entries should automatically be selected if multiple entries are allowed
toggle_select boolean Whether or not clicking a selected entry will deselect if if multiple entries are allowed

Define settings that affect multiple selection. If auto_select is disabled, selecting a new entry will deselect the current one unless the Control (individual selection) or Shift (select a range) keys are pressed.

Note that Control + A will select the entire list.

Example

var list = new EmuList(320, 32, 256, 32, "List of things", "no things", 24, 6, function() {
    var selected_index = GetSelection();
    if (selected_index >= 0) {
        show_debug_message("Selection: " + string(selected_index));
    }
});
list.SetMultiSelect(true, true, true);
list.AddEntries(["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]);
list.SetCallbackDouble(function(index) {
    show_debug_message("Double-click on element: " + string(index));
});
list.SetCallbackMiddle(function(index) {
    show_debug_message("Middle-click on element: " + string(index));
});

container.AddContent(list);

This will create an EmuList element and initialize it with a series of strings. Multi-selection is enabled. It will also have callbacks set for double- and middle-clicks, and then will be added to a previously created container.

Clone this wiki locally