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.h
Go to the documentation of this file.
1
5
6#ifndef NUMERICINDICATOR_H_
7#define NUMERICINDICATOR_H_
8
9#include "../Core/UIElement.h"
10
11#define DEFAULT_NUMERIC_INDICATOR_STRING_LENGTH 15
12
17template <class T>
19{
20 private:
22 void calculateDisplayValue(float value);
23
28 uint8_t numNonFractionalDigits(T number);
29
30 const char* _unitPrefix;
32
33 protected:
34 const char* _baseUnit;
39 uint8_t _numDigits;
40
43
44 public:
45
56 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);
57
62 {
63 delete _stringDrawBuffer;
64 _stringDrawBuffer = NULL;
65 }
66
70 virtual void Draw(bool redraw) override;
71
75 virtual void RecalculateDimensions() override;
76};
77
78#endif /* NUMERICINDICATOR_H_ */
#define DEFAULT_NUMERIC_INDICATOR_STRING_LENGTH
Default max string length for a numeric indicator.
Definition NumericIndicator.h:11
Containing the abstract base class for all user interface elements (controls, indicators,...
uint8_t numNonFractionalDigits(T number)
Calculate the number of non-fractional digits of the given number.
Definition NumericIndicator.cpp:56
virtual void RecalculateDimensions() override
Recalculate the Height and Width of the UIElement.
Definition NumericIndicator.cpp:124
T _maxValue
Maximum value that can be shown by this numeric indicator.
Definition NumericIndicator.h:37
char * _stringDrawBuffer
Buffer holding the string that is drawn to the screen.
Definition NumericIndicator.h:31
uint8_t _numFractionalDigits
Number of fractional digits that are shown by this indicator.
Definition NumericIndicator.h:38
~NumericIndicator()
Destructor of the NumericIndicator.
Definition NumericIndicator.h:61
const char * _baseUnit
Base unit that is appended to the calculated prefix.
Definition NumericIndicator.h:34
uint8_t _numDigits
Number of digits calculated from the maxValue (_numFractionalDigits + numNonFractionalDigits).
Definition NumericIndicator.h:39
virtual void Draw(bool redraw) override
Method used for drawing of the NumericIndicator.
Definition NumericIndicator.cpp:81
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.
Definition NumericIndicator.cpp:69
void calculateDisplayValue(float value)
Calculate the _displayValue and the _unitPrefix from the given value.
Definition NumericIndicator.cpp:14
float _displayValue
Value that is displayed by Draw().
Definition NumericIndicator.h:41
T * _valuePointer
Pointer to the numeric variable that is shown by this indicator.
Definition NumericIndicator.h:35
const char * _unitPrefix
Current display prefix character ("m", "k", "M")
Definition NumericIndicator.h:30
int8_t _unitPrefixPower
Current display prefix power (m = -3, k = 3, M = 6)
Definition NumericIndicator.h:42
T _lastValueDraw
Last drawn numeric value.
Definition NumericIndicator.h:36
UIElement(UIElementType type)
Constructor of the UIElement.
Definition UIElement.h:43