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
NumericIndicator< T > Class Template Reference

Class for a numeric indicator that is only showing a numeric variable value. More...

#include <NumericIndicator.h>

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

Public Member Functions

 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.
 
virtual void Draw (bool redraw) override
 Method used for drawing of the NumericIndicator.
 
virtual void RecalculateDimensions () override
 Recalculate the Height and Width of the UIElement.
 
- 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 bool KeyInput (Keys_t key)
 Process the given key.
 
virtual bool TouchInput (uint16_t x, uint16_t y, TouchTypes touchType)
 Process a touch input at the given point (x, y)
 
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.
 

Protected Attributes

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.
 

Private Member Functions

void calculateDisplayValue (float value)
 Calculate the _displayValue and the _unitPrefix from the given value.
 
uint8_t numNonFractionalDigits (T number)
 Calculate the number of non-fractional digits of the given number.
 

Private Attributes

const char * _unitPrefix
 Current display prefix character ("m", "k", "M")
 
char * _stringDrawBuffer
 Buffer holding the string that is drawn to the screen.
 

Additional Inherited Members

- 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).
 

Detailed Description

template<class T>
class NumericIndicator< T >

Class for a numeric indicator that is only showing a numeric variable value.

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

Constructor & Destructor Documentation

◆ NumericIndicator()

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

Parameters
valuePointerPointer to the numeric variable that is shown by this indicator.
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.
maxValueMaximum value that can be shown by this numeric indicator. It is used to determine the number of non-fractional digits.
numFractionalDigitsNumber of fractional digits that are shown by this indicator. E.g. 1.234 V has 3 fractional digits.
locXX Location of the upper left corner of the NumericIndicator
locYY Location of the upper left corner of the NumericIndicator
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

◆ Draw()

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

Method used for drawing of the NumericIndicator.

Implements UIElement.

Reimplemented in NumericControl< T >.

◆ numNonFractionalDigits()

template<class T>
uint8_t NumericIndicator< T >::numNonFractionalDigits ( T number)
private

Calculate the number of non-fractional digits of the given number.

See also
https://stackoverflow.com/questions/1489830/efficient-way-to-determine-number-of-digits-in-an-integer

◆ RecalculateDimensions()

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

Recalculate the Height and Width of the UIElement.

Implements UIElement.

Reimplemented in NumericControl< T >.

Member Data Documentation

◆ _baseUnit

template<class T>
const char* NumericIndicator< T >::_baseUnit
protected

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.

◆ _displayValue

template<class T>
float NumericIndicator< T >::_displayValue
protected

Value that is displayed by Draw().

E.g. 999.760 if control value is 999760 Hz.

◆ _lastValueDraw

template<class T>
T NumericIndicator< T >::_lastValueDraw
protected

Last drawn numeric value.

Only if the _valueDraw differs from this value, the _stringDrawBuffer is recalculated and the indicator redrawn.

◆ _maxValue

template<class T>
T NumericIndicator< T >::_maxValue
protected

Maximum value that can be shown by this numeric indicator.

It is used to determine the number of non-fractional digits.

◆ _numFractionalDigits

template<class T>
uint8_t NumericIndicator< T >::_numFractionalDigits
protected

Number of fractional digits that are shown by this indicator.

E.g. 1.234 V has 3 fractional digits.

◆ _stringDrawBuffer

template<class T>
char* NumericIndicator< T >::_stringDrawBuffer
private

Buffer holding the string that is drawn to the screen.

This is only recalculated on the firstPage and if the value has changed. char stringBufferLen = _numDigits + 1 + strlen(_unitPrefix) + strlen(_baseUnit) + 1;


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