typedef control listbox; typedef void (*scrollfn)(listbox l, int item_selected);
listbox newlistbox(char *list[], rect r, scrollfn fn); void setlistitem(listbox l, int index); int getlistitem(listbox l); void changelistbox(listobx l, char *new_list[]);
The newlistbox function creates a listbox, which displays lines of text from a NULL-terminated array of strings in a scrollable area on screen. Only one line of text can be selected at any one time.
Whenever the user clicks on one of the text strings with the mouse, that string becomes 'selected' and the call-back function fn is called with a value which is an index into the array list, specifying which string was selected. (Any previous selection is deselected first.) Hence the values will range from zero to the number of strings minus one. The value will be -1 if no string is selected.
Which string is currently selected in the list box can be changed using the setlistitem function.
The getlistitem function returns which item is selected or -1 if none are selected.
The changelistbox function sets a new array of strings to use in the list box, and redraws the box with nothing selected.