ArduinoLibs
|
Field that manages the input of a boolean value. More...
#include <BoolField.h>
Public Member Functions | |
BoolField (const String &label) | |
Constructs a new boolean field with a specific label. More... | |
BoolField (Form &form, const String &label, const String &trueLabel, const String &falseLabel, bool value) | |
Constructs a new boolean field with a specific label and attaches it to a form. More... | |
int | dispatch (int event) |
Dispatches event via this field. More... | |
void | enterField (bool reverse) |
Enters the field due to form navigation. More... | |
bool | value () const |
Returns the current value of this field, true or false. More... | |
void | setValue (bool value) |
Sets the current value of this field to value. More... | |
const String & | trueLabel () const |
Returns the string that is displayed when value() is true. More... | |
void | setTrueLabel (const String &trueLabel) |
Sets the string that is displayed when value() is true to trueLabel. More... | |
const String & | falseLabel () const |
Returns the string that is displayed when value() is false. More... | |
void | setFalseLabel (const String &falseLabel) |
Sets the string that is displayed when value() is false to falseLabel. More... | |
Public Member Functions inherited from Field | |
Field (const String &label) | |
Constructs a new field with a specific label. More... | |
Field (Form &form, const String &label) | |
Constructs a new field with a specific label and attaches it to a form. | |
~Field () | |
Destroys this field and removes it from its owning Form. More... | |
Form * | form () const |
Returns the Form that owns this field; null if not associated with a Form. | |
virtual void | exitField () |
Exits the field due to form navigation. More... | |
const String & | label () const |
Returns the label to display in the first line of this field. More... | |
void | setLabel (const String &label) |
Sets the label to display in the first line of this field. More... | |
bool | isCurrent () const |
Returns true if this field is the currently-displayed field in its owning form; false otherwise. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from Field | |
LiquidCrystal * | lcd () const |
Returns the LCD that this field is being drawn on. | |
virtual void | updateCursor () |
Updates the cursor position after the label has been drawn by setLabel(). More... | |
Field that manages the input of a boolean value.
BoolField is intended for field values that are modifiable by the user. Pressing one of Up or Down will toggle the field's current value.
The following example creates a boolean field that shows the state of the status LED on D13. When the LED is on (the default), the string "On" will be displayed on the LCD screen. When the LED is off, the string "Off" will be displayed instead.
To actually toggle the LED, the application's main loop() function should contain the following code:
Use TextField for read-only fields that report boolean values but which are not modifiable by the user.
ListField can be used to select between more than two items.
Definition at line 28 of file BoolField.h.
|
explicit |
Constructs a new boolean 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().
The initial value() will be false.
Definition at line 77 of file BoolField.cpp.
BoolField::BoolField | ( | Form & | form, |
const String & | label, | ||
const String & | trueLabel, | ||
const String & | falseLabel, | ||
bool | value | ||
) |
Constructs a new boolean field with a specific label and attaches it to a form.
The initial value() of the field is set to the parameter value. When value() is true, trueLabel will be displayed on the screen. When value() is false, falseLabel will be displayed on the screen.
Definition at line 94 of file BoolField.cpp.
|
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.
Reimplemented from Field.
Definition at line 103 of file BoolField.cpp.
|
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().
Reimplemented from Field.
Definition at line 113 of file BoolField.cpp.
|
inline |
Returns the string that is displayed when value() is false.
Definition at line 43 of file BoolField.h.
void BoolField::setFalseLabel | ( | const String & | falseLabel | ) |
Sets the string that is displayed when value() is false to falseLabel.
Definition at line 173 of file BoolField.cpp.
void BoolField::setTrueLabel | ( | const String & | trueLabel | ) |
Sets the string that is displayed when value() is true to trueLabel.
Definition at line 153 of file BoolField.cpp.
void BoolField::setValue | ( | bool | value | ) |
Sets the current value of this field to value.
Definition at line 131 of file BoolField.cpp.
|
inline |
Returns the string that is displayed when value() is true.
Definition at line 40 of file BoolField.h.
|
inline |
Returns the current value of this field, true or false.
Definition at line 37 of file BoolField.h.