Solo Controller Documentation 1.0
Documentation for the Solo Controller
 
Loading...
Searching...
No Matches
TextBox.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file TextBox.h
3 *
4 * @brief Defines TextBox and TextBox which are used to display dynamic
5 * text within a canvas
6 *
7 * @details This file contains a number of of type definitions that are used by
8 * TextBox and TextBox constructors. The intent here is to greatly
9 * simplify the use of TextBox by providing users with a collection of
10 * pre-set configurations to choose from.
11 ******************************************************************************/
12
13#ifndef TEXTBOX_HEADER
14#define TEXTBOX_HEADER
15
16#include <Arduino.h>
17#include "Canvas.h"
18#include "GrFont.h"
19#include "TextBox_Definitions.h"
20
21/******************************************************************************/
22/*** ***/
23/*** Class Definition: DynamicText ***/
24/*** ***/
25/******************************************************************************
26 * @brief Defines a simple text box for displaying dynamic text onto a Canvas
27 *
28 * @details Before attempting to use this class, the caller must do two things.
29 * First the caller must fully initialize the font object provided to the
30 * DynamicText constructor. This means instantiating the GrFont object followed
31 * by a call to the GrFont::begin(), which loads and colorizes the fonts. Second,
32 * the caller must call the DynamicText::begin() method after object instantiation.
33 *
34 * @code {.cpp}
35 * // Create Font
36 * #include "fonts/Monofonto-Regular-180.h"
37 * auto font = WorkSans_SemiBold_180();
38 * font.begin(Red);
39 *
40 * //Create and use DynamicText
41 * auto myDynamicText = DynamicText(myCanvas, x0, y0, width, height, baseline, font);
42 * myDynamicText.begin();
43 * myDynamicText.update(value);
44 * @endcode
45 ******************************************************************************/
47{
48public:
58
59private:
60 Canvas &_DestCanvas; // Reference to the canvas where the text box will be displayed
61 Canvas _BckgCanvas; // Canvas containing the background image upon which the text will be drawn
62 Canvas _DraftCanvas; // Canvas used to build up the text box
63 TextAlign _align; // Text alignment within the text box
64 GrFont *_Font = nullptr; // Primary font to be used
65 uint16_t _baseline; // Vertical position for the baseline of the text within DynamicText
66
67public:
68 const uint16_t X;
69 const uint16_t Y;
70 const uint16_t WIDTH;
71 const uint16_t HEIGHT;
72
85 DynamicText(Canvas &DestCanvas, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t baseline,
87 : _DestCanvas{DestCanvas}, _BckgCanvas{width, height}, _DraftCanvas{width, height},
88 _align{align}, _Font{Font}, _baseline{baseline}, X{x}, Y{y}, WIDTH{width}, HEIGHT{height} {};
89
91 DynamicText(void) = delete;
92
99 virtual void begin(void);
100
106 virtual inline void align(TextAlign align)
107 {
108 _align = align;
109 };
110
117 void update(const char *text, uint16_t textBuffSize);
118
124 void update(int value);
125
126 static void initializeFonts(void);
127
128private:
129 // Verifies that _Font has been initilized. If not, the applications is
130 // halted.
131 void _validateFont(void);
132};
133
134/******************************************************************************/
135/*** ***/
136/*** Class Definition: TextBox ***/
137/*** ***/
138/******************************************************************************
139 * @brief Composite object containing a "Value" and "Units" Text Box
140 *
141 * @details Before attempting to use this class, the caller must do two things.
142 * First the caller must fully initialize the fonts used by this class. This is
143 * accomplished by making a call to TextBox::initializeFonts(). Second,
144 * the caller must call the TextBox::begin() method after object instantiation.
145 *
146 * @code {.cpp}
147 * TextBox::initializeFonts();
148 * auto myTextBox = TextBox(myCanvas, TextBox::config.main.kettleTemp);
149 * myTextBox.begin();
150 * myTextBox.Units.update("F", 2);
151 * myTextBox.Value.update(value);
152 * @endcode
153 ******************************************************************************/
155{
156
157 static Font_List_t font; // List of fonts used by TextBox
158 static ShapeList_t shape; // Geometric shape configuration for the expected fonts
159
160public:
166
169
170 const uint16_t X; // UL x position of the text box within _DestCanvas
171 const uint16_t Y; // UL y position of the text box within _DestCanvas
172 const uint16_t WIDTH; // Full width of the text box and units
173 const uint16_t HEIGHT; // Height of the text box within _DestCanvas
174
189 TextBox(Canvas &DestCanvas, uint16_t x, uint16_t y,
190 uint16_t textWidth, uint16_t unitsWidth, uint16_t height, uint16_t baseline,
191 GrFont *TextFont, GrFont *UnitsFont)
192 : Value{DestCanvas, x, y, textWidth, height, baseline, TextFont, DynamicText::TextAlign::RIGHT},
193 Units{DestCanvas, x + textWidth, y, unitsWidth, height, baseline, UnitsFont, DynamicText::TextAlign::LEFT},
194 X{x}, Y{y}, WIDTH{textWidth + unitsWidth}, HEIGHT{height} {}
195
204 : TextBox{DestCanvas, config->x, config->y, config->textWidth,
205 config->shape->unitsWidth, config->shape->height, config->shape->baseline,
206 config->TextFont, config->UnitsFont} {}
207
215 static void initializeFonts(void);
216
225 inline void begin(void)
226 {
227 Value.begin();
228 Units.begin();
229 }
230};
231
232#endif
Definition Canvas.h:33
Definition TextBox.h:47
const uint16_t Y
UL y position of the text box within _DestCanvas.
Definition TextBox.h:69
const uint16_t WIDTH
Width of the text box within _DestCanvas.
Definition TextBox.h:70
virtual void begin(void)
Initializes the DynamicText. This method must be called before using calling DynamicText::update()
Definition TextBox.cpp:22
const uint16_t HEIGHT
Height of the text box within _DestCanvas.
Definition TextBox.h:71
const uint16_t X
UL x position of the text box within _DestCanvas.
Definition TextBox.h:68
void update(const char *text, uint16_t textBuffSize)
Updates the text inside a DynamicText.
Definition TextBox.cpp:62
DynamicText(Canvas &DestCanvas, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t baseline, GrFont *Font, TextAlign align=CENTER)
DynamicText Constructor.
Definition TextBox.h:85
virtual void align(TextAlign align)
Changes the text alignment. Takes effect after next call to DynamicText::update()
Definition TextBox.h:106
static void initializeFonts(void)
TextAlign
Enumeration used to specify text alignment within the DynamicText.
Definition TextBox.h:53
@ RIGHT
Definition TextBox.h:56
@ CENTER
Definition TextBox.h:55
@ LEFT
Definition TextBox.h:54
Definition GrFont.h:36
static void initializeFonts(void)
Iniitlizes the fonts and configuration data used by TextBox.
Definition TextBox_Config.h:8
const uint16_t Y
Definition TextBox.h:171
TextBox(Canvas &DestCanvas, const ConfigTextBox_t *config)
Simplified construct that accepts one of the pre-defined configuration structures.
Definition TextBox.h:203
const uint16_t X
Definition TextBox.h:170
DynamicText Units
Text box containing the units to be displayed.
Definition TextBox.h:168
DynamicText Value
Text box containing the value to be displayed.
Definition TextBox.h:167
static ConfigList_t config
Data structure containing a collection of TextBox configuration.
Definition TextBox.h:165
TextBox(Canvas &DestCanvas, uint16_t x, uint16_t y, uint16_t textWidth, uint16_t unitsWidth, uint16_t height, uint16_t baseline, GrFont *TextFont, GrFont *UnitsFont)
Generic Constructor.
Definition TextBox.h:189
const uint16_t WIDTH
Definition TextBox.h:172
const uint16_t HEIGHT
Definition TextBox.h:173
void begin(void)
Initiatizes a specific TectBoxUnits instance.
Definition TextBox.h:225
Data structure defining all TextBox used by all menus.
Definition TextBox_Definitions.h:84
Configuration information for a TextBox object.
Definition TextBox_Definitions.h:58
List of pointers the fonts to be used by the application.
Definition TextBox_Definitions.h:17
Definition TextBox_Definitions.h:48