UI_Lib
a1366e08a59cc549a65fa26081e6409aa12f26d5
This is a user interface library for graphical LCDs. It offers many different controls and indicators that can be nested depending on the element types.
|
Class for a numeric control that is showing a numeric variable value and offers the possibility to edit the value. More...
#include <NumericControl.h>
Public Member Functions | |
NumericControl (T *valuePointer, const char *baseUnit, T minValue, T maxValue, int numFractionalDigits, void *controlContext=NULL, void(*onValueChanged)(void *controlContext)=NULL, VirtualKeys *virtualKeys=NULL, uint16_t locX=0, uint16_t locY=0, uint8_t maxStringBufferLength=DEFAULT_NUMERIC_INDICATOR_STRING_LENGTH) | |
Constructor of the NumericControl. | |
virtual void | Draw (bool redraw) override |
Method used for drawing of the NumericControl. | |
virtual bool | KeyInput (Keys_t key) override |
virtual bool | TouchInput (uint16_t x, uint16_t y, TouchTypes touchType) override |
Process a touch input at the given point (x, y) | |
bool | KeyKilo () |
Kilo key is used to change the prefix to kilo. | |
bool | KeyMilli () |
Milli key is used to change the prefix to milli. | |
bool | KeyMinus () |
Minus key is used to toggle the sign of the controlled value. | |
bool | KeyX1 () |
X1 key is used to change the prefix to none. | |
bool | KeyNumeric (Keys_t key) |
Numeric keys (KEY0 . | |
bool | ValueUp () |
Up key is used to increment the digit at the current cursor position. | |
bool | ValueDown () |
Down key is used to decrement the digit at the current cursor position. | |
bool | CursorLeft () |
Left key is used to move the cursor position left. | |
bool | CursorRight () |
Right key is used to move the cursor position right. | |
void | ToggleEditMode () |
Toggle the control between display and edit mode. | |
virtual void | RecalculateDimensions () override |
Recalculate the Height and Width of the UIElement. | |
![]() | |
NumericIndicator (T *valuePointer, const char *baseUnit, T maxValue, unsigned char numFractionalDigits, uint16_t locX=0, uint16_t locY=0, uint8_t maxStringBufferLength=DEFAULT_NUMERIC_INDICATOR_STRING_LENGTH) | |
Constructor of the NumericIndicator. | |
~NumericIndicator () | |
Destructor of the NumericIndicator. | |
![]() | |
UIElement (UIElementType type) | |
Constructor of the UIElement. | |
UIElement (uint16_t locX, uint16_t locY, UIElementType type) | |
Constructor of the UIElement. | |
virtual void | RecalculateLayout () |
Recalculate the UIElement layout (containers update the X- and Y-Location of all their items, all other items can do other layout update stuff) | |
bool | HitTest (uint16_t x, uint16_t y) |
Check if the given point (x, y) is inside this UIElement. | |
Public Attributes | |
int8_t | CurrentDigitPosition |
Position of the currently controlled digit. | |
![]() | |
UIElementType | Type |
Element type (control, indicator, container) | |
uint16_t | LocX |
X Location of the upper left corner of the UIElement. | |
uint16_t | LocY |
Y Location of the upper left corner of the UIElement. | |
uint16_t | Width |
Drawing width of the UIElement. | |
uint16_t | Height |
Drawing height of the UIElement. | |
bool | Visible |
The UIElement is only drawn if the visibility is set to true. | |
bool | IsInEditMode |
Is the UIElement in edit mode? | |
UIElement * | Parent |
Parent UIElement that this UIElement belongs to. | |
UIElement * | ActiveChild |
Child element that is currently active (receiving all key inputs). | |
Private Member Functions | |
T | coerceValue (T value) |
Limit the value to be between _minValue and _maxValue. | |
uint8_t | extractDigit (T number, int8_t position) |
Extract the digit at the requested position from the number. | |
Private Attributes | |
T | _minValue |
Minimum value that can be handled by this numeric control. | |
bool | _lastDrawnEditMode |
The EditMode that was last drawn. | |
int8_t | _lastDrawnCurrentDigitPosition |
The CurrentDigitPosition that was last drawn. | |
void * | _controlContext |
Context pointer that is returned with the _onValueChanged function pointer. | |
void(* | _onValueChanged )(void *controlContext) |
Function pointer for _onValueChanged event. | |
VirtualKeys * | _virtualKeys |
Pointer to a VirtualKeys UIElement. | |
Additional Inherited Members | |
![]() | |
const char * | _baseUnit |
Base unit that is appended to the calculated prefix. | |
T * | _valuePointer |
Pointer to the numeric variable that is shown by this indicator. | |
T | _lastValueDraw |
Last drawn numeric value. | |
T | _maxValue |
Maximum value that can be shown by this numeric indicator. | |
uint8_t | _numFractionalDigits |
Number of fractional digits that are shown by this indicator. | |
uint8_t | _numDigits |
Number of digits calculated from the maxValue (_numFractionalDigits + numNonFractionalDigits). | |
float | _displayValue |
Value that is displayed by Draw(). | |
int8_t | _unitPrefixPower |
Current display prefix power (m = -3, k = 3, M = 6) | |
![]() | |
bool | _lastDrawnVisible |
The Visible value that was last drawn. | |
Class for a numeric control that is showing a numeric variable value and offers the possibility to edit the value.
T | Type of numeric variable handled by this control. This can be e.g. float or int. |
NumericControl< T >::NumericControl | ( | T * | valuePointer, |
const char * | baseUnit, | ||
T | minValue, | ||
T | maxValue, | ||
int | numFractionalDigits, | ||
void * | controlContext = NULL, | ||
void(* | onValueChanged )(void *controlContext) = NULL, | ||
VirtualKeys * | virtualKeys = NULL, | ||
uint16_t | locX = 0, | ||
uint16_t | locY = 0, | ||
uint8_t | maxStringBufferLength = DEFAULT_NUMERIC_INDICATOR_STRING_LENGTH ) |
Constructor of the NumericControl.
valuePointer | Pointer to the numeric variable that is shown and manipulated by this control. |
baseUnit | Base unit that is appended to the calculated prefix. E.g. "V" for voltage values. To use the "%" sign as unit, you have to use "%%" as string. |
minValue | Minimum value that can be handled by this numeric control. |
maxValue | Maximum value that can be shown by this numeric control. It is used to determine the number of non-fractional digits. |
numFractionalDigits | Number of fractional digits that are shown by this control. E.g. 1.234 V has 3 fractional digits. |
controlContext | Context pointer that is returned with the _onValueChanged function pointer |
onValueChanged | Function pointer for _onValueChanged event. This function is called when the value of the valuePointer is changed. |
virtualKeys | Pointer to a VirtualKeys UIElement. This can be used to edit the NumericControl via touch. |
locX | X Location of the upper left corner of the NumericControl |
locY | Y Location of the upper left corner of the NumericControl |
maxStringBufferLength | Length for the internally used _stringDrawBuffer. Make sure this is large enough to hold all character displayed by this element + 1 termination character '\0' (e.g. "1234.56mV" needs at least a length of 10; 9 characters + 1 termination character). |
|
private |
Limit the value to be between _minValue and _maxValue.
value | Value to coerce. |
bool NumericControl< T >::CursorLeft | ( | ) |
Left key is used to move the cursor position left.
bool NumericControl< T >::CursorRight | ( | ) |
Right key is used to move the cursor position right.
|
overridevirtual |
Method used for drawing of the NumericControl.
Reimplemented from NumericIndicator< T >.
|
private |
Extract the digit at the requested position from the number.
number | Number from which to extract one digit. |
position | position in the number from which to extract the digit. Position 0 is are 1er. Negative positions are fractionals. Positive positions are non-fractionals. |
|
overridevirtual |
Process the given key. If this element doesn't support the key type, the key is forwarded to the parent. This is done until the key is processed or the root of the visual tree is reached. @param key Key that should be processed. Supported keys are: KEYOK, KEYLEFT, KEYRIGHT, KEYUP, KEYDOWN, KEYKILO, KEYMILLI, KEYX1, KEYMINUS, KEY0 .. KEY9
s *
Reimplemented from UIElement.
bool NumericControl< T >::KeyKilo | ( | ) |
Kilo key is used to change the prefix to kilo.
bool NumericControl< T >::KeyMilli | ( | ) |
Milli key is used to change the prefix to milli.
bool NumericControl< T >::KeyMinus | ( | ) |
Minus key is used to toggle the sign of the controlled value.
bool NumericControl< T >::KeyNumeric | ( | Keys_t | key | ) |
Numeric keys (KEY0 .
. KEY9) change the digit at the current cursor position.
bool NumericControl< T >::KeyX1 | ( | ) |
X1 key is used to change the prefix to none.
|
overridevirtual |
Recalculate the Height and Width of the UIElement.
Reimplemented from NumericIndicator< T >.
void NumericControl< T >::ToggleEditMode | ( | ) |
Toggle the control between display and edit mode.
Some keys are only supported in edit mode.
|
overridevirtual |
Process a touch input at the given point (x, y)
x | X-Coordinate of the touched point |
y | Y-Coordinate of the touched point |
touchType | Type of the touch |
Reimplemented from UIElement.
bool NumericControl< T >::ValueDown | ( | ) |
Down key is used to decrement the digit at the current cursor position.
bool NumericControl< T >::ValueUp | ( | ) |
Up key is used to increment the digit at the current cursor position.
|
private |
The CurrentDigitPosition that was last drawn.
Used to detect changes in the current digit position.
|
private |
The EditMode that was last drawn.
Used to detect changes in the edit mode.
|
private |
Function pointer for _onValueChanged event.
This function is called when the value of the valuePointer is changed.
|
private |
Pointer to a VirtualKeys UIElement.
This can be used to edit the NumericControl via touch.
int8_t NumericControl< T >::CurrentDigitPosition |
Position of the currently controlled digit.
Range from (-_numFractionalDigits) to (_numDigits - _numFractionalDigits - 1)