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
EnumIndicator.cpp
1/*
2 * EnumIndicator.cpp
3 */
4
6#include "Core/UI_Manager.h"
7
8template <class T>
9EnumIndicator<T>::EnumIndicator(T* valuePointer, const char** enumNames, uint8_t numEnumValues, uint16_t locX, uint16_t locY) : UIElement(locX, locY, UI_INDICATOR)
10{
11 _enumNames = enumNames;
12 _numEnumValues = numEnumValues;
13 _valuePointer = valuePointer;
14}
15
16template <class T>
17void EnumIndicator<T>::Draw(bool redraw)
18{
19 if (Visible)
20 {
22 {
23 _lastDrawnVisible = true;
25
26 // If the Draw() is called on a object of the EnumIndicator, the Type is UI_INDICATOR
27 // If the Draw() is called from an EnumControl object, the Type was set to UI_CONTROL there
28 if(Type == UI_INDICATOR)
29 {
30 UiManager.Gfx->fillRect(LocX, LocY, Width, Height, UiManager.ColorBackground);
31 }
32
33 UiManager.Gfx->setCursor(LocX + UiManager.ElementMargin + UiManager.ElementPadding, LocY + Height - UiManager.ElementMargin - 2 * UiManager.ElementPadding - 1);
35 }
36 }
37 else if(!Visible && _lastDrawnVisible) // clear only when the Visible property changes from true to false
38 {
39 _lastDrawnVisible = false;
40 UiManager.Gfx->fillRect(LocX, LocY, Width, Height, UiManager.ColorBackground);
41 }
42}
43
44template <class T>
46{
47 Height = UiManager.FontHeight + 2 * UiManager.ElementPadding + 2 * UiManager.ElementMargin;
48
49 uint16_t maxWidth = 0;
50 for(int i = 0; i < _numEnumValues; i++)
51 {
52 int16_t x, y;
53 uint16_t w, h;
54 UiManager.Gfx->getTextBounds(_enumNames[i], 0, 0, &x, &y, &w, &h);
55 if(w > maxWidth) { maxWidth = w; }
56 }
57
58 Width = maxWidth + 2 * UiManager.ElementPadding + 2 * UiManager.ElementMargin + 2;
59}
Containing a class for an enum indicator that is only showing a enumeration variable value.
Containing a class that is used to handle the drawing and key handling of all UI_Elements.
UI_Manager UiManager
Access object for the singleton instance of the UI_Manager.
Definition UI_Manager.cpp:7
@ UI_INDICATOR
Indicator elements are only used to show information to the user.
Definition UIElementType.h:15
T * _valuePointer
Pointer to the enumeration variable that is shown by this indicator.
Definition EnumIndicator.h:21
const char ** _enumNames
Pointer to an array of char pointers containing the display names for all enumeration values.
Definition EnumIndicator.h:19
EnumIndicator(T *valuePointer, const char **enumNames, uint8_t numEnumValues, uint16_t locX=0, uint16_t locY=0)
Constructor of the EnumIndicator.
Definition EnumIndicator.cpp:9
uint8_t _numEnumValues
Number of enumeration values.
Definition EnumIndicator.h:20
virtual void RecalculateDimensions() override
Recalculate the Height and Width of the UIElement.
Definition EnumIndicator.cpp:45
T _lastValueDraw
Last drawn enum value.
Definition EnumIndicator.h:22
virtual void Draw(bool redraw) override
Method used for drawing of the EnumIndicator.
Definition EnumIndicator.cpp:17
bool _lastDrawnVisible
The Visible value that was last drawn.
Definition UIElement.h:26
UIElementType Type
Element type (control, indicator, container)
Definition UIElement.h:29
uint16_t Height
Drawing height of the UIElement.
Definition UIElement.h:33
uint16_t LocY
Y Location of the upper left corner of the UIElement.
Definition UIElement.h:31
bool Visible
The UIElement is only drawn if the visibility is set to true.
Definition UIElement.h:34
uint16_t Width
Drawing width of the UIElement.
Definition UIElement.h:32
UIElement(UIElementType type)
Constructor of the UIElement.
Definition UIElement.h:43
uint16_t LocX
X Location of the upper left corner of the UIElement.
Definition UIElement.h:30