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

Field that manages the input of an integer value. More...

#include <IntField.h>

Inheritance diagram for IntField:
Field

Public Member Functions

 IntField (const String &label)
 Constructs a new integer field with a specific label. More...
 
 IntField (Form &form, const String &label, int minValue, int maxValue, int stepValue, int value)
 Constructs a new integer field with a specific label, minValue, maxValue, stepValue, and value, and attaches it to a form. More...
 
 IntField (Form &form, const String &label, int minValue, int maxValue, int stepValue, int value, const String &suffix)
 Constructs a new integer field with a specific label, minValue, maxValue, stepValue, value, and suffix and attaches it to a form.
 
int dispatch (int event)
 Dispatches event via this field. More...
 
void enterField (bool reverse)
 Enters the field due to form navigation. More...
 
int minValue () const
 Returns the minimum value for the input field. More...
 
void setMinValue (int value)
 Sets the minimum value for the input field. More...
 
int maxValue () const
 Returns the maximum value for the input field. More...
 
void setMaxValue (int value)
 Sets the maximum value for the input field. More...
 
int stepValue () const
 Returns the step value to use when increasing or decreasing the value() due to Up and Down button presses. More...
 
void setStepValue (int value)
 Sets the step value value to use when increasing or decreasing the value() due to Up and Down button presses. More...
 
int value () const
 Returns the current value of this field. More...
 
void setValue (int value)
 Sets the current value of this field. More...
 
const String & suffix () const
 Returns the suffix string to be displayed after the field's value. More...
 
void setSuffix (const String &suffix)
 Sets the suffix string to be displayed after the field's value. 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...
 
Formform () 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...
 

Detailed Description

Field that manages the input of an integer value.

IntField is intended for field values that are modifiable by the user. Pressing Up adds stepValue() to the current value and pressing Down subtracts stepValue() from the current value. The value is clamped to the range minValue() to maxValue().

The following example creates an integer field with the label "Iterations", that ranges between 1 and 5, with a stepValue() of 1, and an initial default value() of 2:

Form mainForm(lcd);
IntField iterField(mainForm, "Iterations", 1, 5, 1, 2);

IntField can be configured to show a suffix() on the screen after the integer value(). This is intended for communicating the units in which the value is expressed. For example:

IntField volumeField(mainForm, "Volume", 0, 100, 5, 85, "%");
IntField speedField(mainForm, "Speed", 0, 2000, 15, 450, " rpm");
FormInt.png

Use TextField for read-only fields that report integer values but which are not modifiable by the user.

See Also
Field, TextField

Definition at line 28 of file IntField.h.

Constructor & Destructor Documentation

IntField::IntField ( const String &  label)
explicit

Constructs a new integer 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, value() is 0, minValue() is 0, maxValue() is 100, stepValue() is 1, and suffix() is an empty string.

See Also
Form::addField()

Definition at line 71 of file IntField.cpp.

IntField::IntField ( Form form,
const String &  label,
int  minValue,
int  maxValue,
int  stepValue,
int  value 
)

Constructs a new integer field with a specific label, minValue, maxValue, stepValue, and value, and attaches it to a form.

The suffix() is initially set to an empty string.

Definition at line 88 of file IntField.cpp.

Member Function Documentation

int IntField::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 114 of file IntField.cpp.

void IntField::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 126 of file IntField.cpp.

int IntField::maxValue ( ) const
inline

Returns the maximum value for the input field.

See Also
setMaxValue(), minValue(), stepValue(), value()

Definition at line 41 of file IntField.h.

int IntField::minValue ( ) const
inline

Returns the minimum value for the input field.

See Also
setMinValue(), maxValue(), stepValue(), value()

Definition at line 38 of file IntField.h.

void IntField::setMaxValue ( int  value)
inline

Sets the maximum value for the input field.

The new maximum value will be used to clamp the field's value the next time setValue() is called.

See Also
maxValue(), setMinValue(), setStepValue(), setValue()

Definition at line 42 of file IntField.h.

void IntField::setMinValue ( int  value)
inline

Sets the minimum value for the input field.

The new minimum value will be used to clamp the field's value the next time setValue() is called.

See Also
minValue(), setMaxValue(), setStepValue(), setValue()

Definition at line 39 of file IntField.h.

void IntField::setStepValue ( int  value)
inline

Sets the step value value to use when increasing or decreasing the value() due to Up and Down button presses.

See Also
stepValue(), setMinValue(), setMaxValue(), setValue()

Definition at line 45 of file IntField.h.

void IntField::setSuffix ( const String &  suffix)

Sets the suffix string to be displayed after the field's value.

Suffixes are typically used to indicate the units that the value() is expressed in. For example:

field.setSuffix("%");
field.setSuffix(" rpm");
See Also
suffix()

Definition at line 231 of file IntField.cpp.

void IntField::setValue ( int  value)

Sets the current value of this field.

The value will be clamped to the range defined by minValue() and maxValue().

See Also
value(), setMinValue(), setMaxValue(), setStepValue()

Definition at line 198 of file IntField.cpp.

int IntField::stepValue ( ) const
inline

Returns the step value to use when increasing or decreasing the value() due to Up and Down button presses.

See Also
setStepValue(), minValue(), maxValue(), value()

Definition at line 44 of file IntField.h.

const String & IntField::suffix ( ) const
inline

Returns the suffix string to be displayed after the field's value.

See Also
setSuffix()

Definition at line 50 of file IntField.h.

int IntField::value ( ) const
inline

Returns the current value of this field.

See Also
setValue(), minValue(), maxValue(), stepValue()

Definition at line 47 of file IntField.h.


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