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.
Loading...
Searching...
No Matches
NumericControl< T > Class Template Reference

Class for a numeric control that is showing a numeric variable value and offers the possibility to edit the value. More...

#include <NumericControl.h>

Inheritance diagram for NumericControl< T >:
NumericIndicator< T > UIElement

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.
 
- Public Member Functions inherited from NumericIndicator< T >
 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.
 
- Public Member Functions inherited from UIElement
 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.
 
- Public Attributes inherited from UIElement
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?
 
UIElementParent
 Parent UIElement that this UIElement belongs to.
 
UIElementActiveChild
 Child element that is currently active (receiving all key inputs).
 

Private Member Functions

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

_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

- Protected Attributes inherited from NumericIndicator< T >
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.
 
_lastValueDraw
 Last drawn numeric value.
 
_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)
 
- Protected Attributes inherited from UIElement
bool _lastDrawnVisible
 The Visible value that was last drawn.
 

Detailed Description

template<class T>
class NumericControl< T >

Class for a numeric control that is showing a numeric variable value and offers the possibility to edit the value.

Template Parameters
TType of numeric variable handled by this control. This can be e.g. float or int.

Constructor & Destructor Documentation

◆ NumericControl()

template<class T>
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.

Parameters
valuePointerPointer to the numeric variable that is shown and manipulated by this control.
baseUnitBase 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.
minValueMinimum value that can be handled by this numeric control.
maxValueMaximum value that can be shown by this numeric control. It is used to determine the number of non-fractional digits.
numFractionalDigitsNumber of fractional digits that are shown by this control. E.g. 1.234 V has 3 fractional digits.
controlContextContext pointer that is returned with the _onValueChanged function pointer
onValueChangedFunction pointer for _onValueChanged event. This function is called when the value of the valuePointer is changed.
virtualKeysPointer to a VirtualKeys UIElement. This can be used to edit the NumericControl via touch.
locXX Location of the upper left corner of the NumericControl
locYY Location of the upper left corner of the NumericControl
maxStringBufferLengthLength 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).

Member Function Documentation

◆ coerceValue()

template<class T>
T NumericControl< T >::coerceValue ( T value)
private

Limit the value to be between _minValue and _maxValue.

Parameters
valueValue to coerce.
Returns
Coerced value.

◆ CursorLeft()

template<class T>
bool NumericControl< T >::CursorLeft ( )

Left key is used to move the cursor position left.

Returns
True if the key was handled, otherwise False.

◆ CursorRight()

template<class T>
bool NumericControl< T >::CursorRight ( )

Right key is used to move the cursor position right.

Returns
True if the key was handled, otherwise False.

◆ Draw()

template<class T>
void NumericControl< T >::Draw ( bool redraw)
overridevirtual

Method used for drawing of the NumericControl.

Reimplemented from NumericIndicator< T >.

◆ extractDigit()

template<class T>
uint8_t NumericControl< T >::extractDigit ( T number,
int8_t position )
private

Extract the digit at the requested position from the number.

Parameters
numberNumber from which to extract one digit.
positionposition in the number from which to extract the digit. Position 0 is are 1er. Negative positions are fractionals. Positive positions are non-fractionals.
Returns
Extracted digit between 0 and 9
See also
https://www.quora.com/How-can-you-mathematically-extract-a-single-digit-from-a-number

◆ KeyInput()

template<class T>
bool NumericControl< T >::KeyInput ( Keys_t key)
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 *

Returns
true if the key was processed; false if not.

Reimplemented from UIElement.

◆ KeyKilo()

template<class T>
bool NumericControl< T >::KeyKilo ( )

Kilo key is used to change the prefix to kilo.

Returns
True if the key was handled, otherwise False.

◆ KeyMilli()

template<class T>
bool NumericControl< T >::KeyMilli ( )

Milli key is used to change the prefix to milli.

Returns
True if the key was handled, otherwise False.

◆ KeyMinus()

template<class T>
bool NumericControl< T >::KeyMinus ( )

Minus key is used to toggle the sign of the controlled value.

Returns
True if the key was handled, otherwise False.

◆ KeyNumeric()

template<class T>
bool NumericControl< T >::KeyNumeric ( Keys_t key)

Numeric keys (KEY0 .

. KEY9) change the digit at the current cursor position.

Returns
True if the key was handled, otherwise False.

◆ KeyX1()

template<class T>
bool NumericControl< T >::KeyX1 ( )

X1 key is used to change the prefix to none.

Returns
True if the key was handled, otherwise False.

◆ RecalculateDimensions()

template<class T>
void NumericControl< T >::RecalculateDimensions ( )
overridevirtual

Recalculate the Height and Width of the UIElement.

Reimplemented from NumericIndicator< T >.

◆ ToggleEditMode()

template<class T>
void NumericControl< T >::ToggleEditMode ( )

Toggle the control between display and edit mode.

Some keys are only supported in edit mode.

◆ TouchInput()

template<class T>
bool NumericControl< T >::TouchInput ( uint16_t x,
uint16_t y,
TouchTypes touchType )
overridevirtual

Process a touch input at the given point (x, y)

Parameters
xX-Coordinate of the touched point
yY-Coordinate of the touched point
touchTypeType of the touch
Returns
true if the touch was processed; false if not.

Reimplemented from UIElement.

◆ ValueDown()

template<class T>
bool NumericControl< T >::ValueDown ( )

Down key is used to decrement the digit at the current cursor position.

Returns
True if the key was handled, otherwise False.

◆ ValueUp()

template<class T>
bool NumericControl< T >::ValueUp ( )

Up key is used to increment the digit at the current cursor position.

Returns
True if the key was handled, otherwise False.

Member Data Documentation

◆ _lastDrawnCurrentDigitPosition

template<class T>
int8_t NumericControl< T >::_lastDrawnCurrentDigitPosition
private

The CurrentDigitPosition that was last drawn.

Used to detect changes in the current digit position.

◆ _lastDrawnEditMode

template<class T>
bool NumericControl< T >::_lastDrawnEditMode
private

The EditMode that was last drawn.

Used to detect changes in the edit mode.

◆ _onValueChanged

template<class T>
void(* NumericControl< T >::_onValueChanged) (void *controlContext)
private

Function pointer for _onValueChanged event.

This function is called when the value of the valuePointer is changed.

◆ _virtualKeys

template<class T>
VirtualKeys* NumericControl< T >::_virtualKeys
private

Pointer to a VirtualKeys UIElement.

This can be used to edit the NumericControl via touch.

◆ CurrentDigitPosition

template<class T>
int8_t NumericControl< T >::CurrentDigitPosition

Position of the currently controlled digit.

Range from (-_numFractionalDigits) to (_numDigits - _numFractionalDigits - 1)


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