ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Friends | List of all members
Form Class Reference

Manager for a form containing data input/output fields. More...

#include <Form.h>

Public Member Functions

 Form (LiquidCrystal &lcd)
 Constructs a new form and associates it with lcd. More...
 
 ~Form ()
 Detaches all remaining fields and destroys this form.
 
int dispatch (int event)
 Dispatches event to the currently active field using Field::dispatch(). More...
 
void nextField ()
 Changes to the next field in the "tab order". More...
 
void prevField ()
 Changes to the previous field in the "tab order". More...
 
void defaultField ()
 Changes to default field (i.e., the first field). More...
 
void addField (Field *field)
 Adds field to this form. More...
 
void removeField (Field *field)
 Removes field from this form. More...
 
FieldcurrentField () const
 Returns the current field that is displayed on-screen. More...
 
void setCurrentField (Field *field)
 Sets the current field that is displayed on-screen. More...
 
bool isCurrent (Field &field) const
 Returns true if field is currently displayed on-screen, false otherwise. More...
 
void show ()
 Shows the form, or does nothing if the form is already on-screen. More...
 
void hide ()
 Hides the form, or does nothing if the form is not on-screen. More...
 
bool isVisible () const
 Returns true if the form is shown; false if the form is hidden. More...
 

Friends

class Field
 

Detailed Description

Manager for a form containing data input/output fields.

See the Form example for more information on creating an application that uses forms and fields.

Definition at line 32 of file Form.h.

Constructor & Destructor Documentation

Form::Form ( LiquidCrystal &  lcd)
explicit

Constructs a new form and associates it with lcd.

This constructor is typically followed by calls to construct Field values for each of the fields on the form. For example:

Form mainForm(lcd);
TextField welcomeField(mainForm, "Form example", "v1.0");
FormText.png

Definition at line 47 of file Form.cpp.

Member Function Documentation

void Form::addField ( Field field)

Adds field to this form.

Usually this function is not required because the field's constructor will add the field to the form automatically.

See Also
removeField()

Definition at line 165 of file Form.cpp.

Field * Form::currentField ( ) const
inline

Returns the current field that is displayed on-screen.

Returns null if the form has no fields, or setCurrentField() explicitly set the current field to null.

See Also
setCurrentField(), isCurrent()

Definition at line 46 of file Form.h.

void Form::defaultField ( )

Changes to default field (i.e., the first field).

See Also
nextField(), prevField(), currentField()

Definition at line 152 of file Form.cpp.

int Form::dispatch ( int  event)

Dispatches event to the currently active field using Field::dispatch().

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 one of the fields on the form has changed value due to the event, perhaps requiring the application to take further action based on the new field value. Use currentField() or isCurrent() to determine which field has changed.

int event = lcd.getButton();
if (mainForm.dispatch(event) == FORM_CHANGED) {
if (mainForm.isCurrent(volumeField)) {
// Adjust the volume to match the field.
setVolume(volumeField.value());
}
}

This function handles the Left and Right buttons to navigate between fields.

See Also
Field::dispatch(), LCD::getButton(), currentField(), isCurrent()

Definition at line 99 of file Form.cpp.

void Form::hide ( )

Hides the form, or does nothing if the form is not on-screen.

The screen will be cleared to remove the contents of the current field.

See Also
show(), isVisible()

Definition at line 293 of file Form.cpp.

bool Form::isCurrent ( Field field) const
inline

Returns true if field is currently displayed on-screen, false otherwise.

This function is typically called after dispatch() returns FORM_CHANGED to determine which field has changed.

See Also
currentField(), setCurrentField()

Definition at line 49 of file Form.h.

bool Form::isVisible ( ) const
inline

Returns true if the form is shown; false if the form is hidden.

See Also
show(), hide()

Definition at line 53 of file Form.h.

void Form::nextField ( )

Changes to the next field in the "tab order".

See Also
prevField(), defaultField(), currentField()

Definition at line 118 of file Form.cpp.

void Form::prevField ( )

Changes to the previous field in the "tab order".

See Also
nextField(), defaultField(), currentField()

Definition at line 135 of file Form.cpp.

void Form::removeField ( Field field)

Removes field from this form.

If field is the current field on-screen, then either the next or previous field will be made current.

See Also
addField()

Definition at line 187 of file Form.cpp.

void Form::setCurrentField ( Field field)

Sets the current field that is displayed on-screen.

Use this function to programmatically force the form to display a specific field on-screen.

See Also
currentField(), isCurrent()

Definition at line 230 of file Form.cpp.

void Form::show ( )

Shows the form, or does nothing if the form is already on-screen.

When the form is shown, the screen will be cleared and the currentField() will be drawn.

If the form was previously hidden, then the field that was previously current will be shown again. Call defaultField() before show() to reset the form to show the first field instead.

See Also
hide(), isVisible(), defaultField()

Definition at line 274 of file Form.cpp.


The documentation for this class was generated from the following files: