ArduinoLibs
Public Member Functions
ListField Class Reference

Field that manages selection from a static list of items. More...

#include <ListField.h>

Inheritance diagram for ListField:
Field

List of all members.

Public Member Functions

 ListField (const String &label)
 Constructs a new list field with a specific label.
 ListField (Form &form, const String &label, ListItems items, int value=0)
 Constructs a new list field with a specific label, list of items, and value, and attaches it to a form.
int dispatch (int event)
 Dispatches event via this field.
void enterField (bool reverse)
 Enters the field due to form navigation.
ListItems items () const
 Returns the array of items in this list.
void setItems (ListItems items)
 Sets the array of items for this list.
int value () const
 Returns the value of this list; i.e. the index within items() of the selected item.
void setValue (int value)
 Sets the value of this list; i.e. the index within items() of the selected item.

Detailed Description

Field that manages selection from a static list of items.

ListField is intended for selecting an element from a list of items. Each items is represented by a string within program memory, with the list terminated by null. For example:

 const char item_Eggs[] PROGMEM = "Eggs";
 const char item_Cheese[] PROGMEM = "Cheese";
 const char item_Pumpkin[] PROGMEM = "Pumpkin";
 ListItem const ingredients[] PROGMEM = {
    item_Eggs,
    item_Cheese,
    item_Pumpkin,
    0
 };

 Form mainForm(lcd);
 ListField ingredient(mainForm, "Select ingredient", ingredients);

If there are only two items in the list, then BoolField can be used instead.

See also:
Field, BoolField

Definition at line 32 of file ListField.h.


Constructor & Destructor Documentation

ListField::ListField ( const String &  label) [explicit]

Constructs a new list field with a specific label.

The field is initially not associated with a Form. The field can be added to a form later using Form::addField().

Initially, items() is null and value() is -1.

See also:
Form::addField()

Definition at line 64 of file ListField.cpp.


Member Function Documentation

int ListField::dispatch ( int  event) [virtual]

Dispatches event via this field.

The event is usually obtained from LCD::getButton().

Returns zero if the event has been handled and no further action is required.

Returns FORM_CHANGED if the event has changed the value of this field in a manner that may require the application to take further action based on the new field value.

Returns -1 if the event is not handled by this field, and should be handled by the Form itself (particularly for Left and Right buttons). The default implementation returns -1 for all events.

See also:
Form::dispatch(), LCD::getButton()

Reimplemented from Field.

Definition at line 87 of file ListField.cpp.

void ListField::enterField ( bool  reverse) [virtual]

Enters the field due to form navigation.

This function is typically called when the user presses Left and Right buttons to navigate to the field. If reverse is true, then navigation was due to the Left button being pressed.

This function can assume that the display has been cleared and the cursor is positioned at (0, 0).

The default implementation prints the label().

See also:
exitField()

Reimplemented from Field.

Definition at line 105 of file ListField.cpp.

ListItems ListField::items ( ) const [inline]

Returns the array of items in this list.

See also:
setItems()

Definition at line 41 of file ListField.h.

void ListField::setItems ( ListItems  items)

Sets the array of items for this list.

The items must be stored within program memory and terminated by null; for example:

 const char item_Eggs[] PROGMEM = "Eggs";
 const char item_Cheese[] PROGMEM = "Cheese";
 const char item_Pumpkin[] PROGMEM = "Pumpkin";
 ListItem const ingredients[] PROGMEM = {
    item_Eggs,
    item_Cheese,
    item_Pumpkin,
    0
 };

 list.setItems(ingredients);
See also:
items()

Definition at line 141 of file ListField.cpp.

void ListField::setValue ( int  value)

Sets the value of this list; i.e. the index within items() of the selected item.

The value will be clamped to the range of items().

See also:
value(), items()

Definition at line 178 of file ListField.cpp.

int ListField::value ( ) const [inline]

Returns the value of this list; i.e. the index within items() of the selected item.

Returns -1 if the items() array is empty or null.

See also:
setValue(), items()

Definition at line 44 of file ListField.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Enumerations Enumerator