Next: ANSIMessageBoxPane, Previous: ANSILabelPane, Up: Classes [Index]
ANSIListBoxPane
ClassAn ANSIListBoxPane
object displays a list of items, and allows
the user to select one of the items in the list by using the cursor
motion keys.
Each item in the list is an ANSILabelPane
. To modify the
appearance of the items, refer to the ANSILabelPane
class.
See ANSILabelPane.
After exiting by pressing Escape or Enter, a program can retrieve the text of the selected item.
Here is a simple program that displays a list of items, then prints the selected item’s text before exiting.
int main () { ANSIListBoxPane new listBox; listBox appendLine "Item 1"; listBox appendLine "Item 2"; listBox appendLine "Item 3"; listBox appendLine "Item 4"; listBox appendLine "Item 5"; listBox show 2, 2; // Waits for the user to press Escape or Enter // before returning. printf ("\nYou selected %s.\n", listBox selectedText); listBox cleanup; }
items
A List
of ANSILabelPane
items that contain the text
of the list selections.
oldSelectedContent
An ANSILabelPane
object that contains the content of the previous
selection. Used for erasing the previous selection before drawing the
new selection.
prevSelectedLine
An Integer
that contains the index of the previously selected item.
The ANSIListBoxPane
indexes items starting with 1 for the first item.
selectedContent
An ANSILabelPane
object that contains the contents of the currently
selected item.
selectedLine
An Integer
that contains the index, counting from 1, of the currently
selected item.
totalLines
An Integer
that contains the number of items to be displayed.
appendLine (String
text)
Creates a new ANSILabelBox
object with the contents text,
then adds the ANSILabelBox
to the items
list.
cleanup (void
)
Deletes the buffers associated with the ANSIListBoxPane
object
and its items.
handleInput (void
)
Waits for input from the user and processes it. Pressing a cursor key or an Emacs or vi next/previous line key shifts the selection. Pressing Escape or Enter causes the method to return.
new (listPane1, listPane2, ...;)
The ANSIListBoxPane
constructor. The argument contains the
names of one or more new ANSIListBoxPane
objects.
refresh (void
)
Draw the list pane and items on the terminal.
refreshSelectionFirst (void
)
Highlight the initially selected item. Should only be called after
a call to refresh
.
refreshSelection (void
)
Redraw the highlightd selected item, and un-highlight the previously
selected item. Should only be called after a call to selectNext
or selectPrev
selectedText (void
)
Returns the text of the selected item as a String
object.
selectNext (void
)
selectPrev (void
)
Select the next or previous item of the list box’s contents. Also saves the index and contents of the previously selected item.
Next: ANSIMessageBoxPane, Previous: ANSILabelPane, Up: Classes [Index]