Solo Controller Documentation 1.0
Documentation for the Solo Controller
 
Loading...
Searching...
No Matches
TextBox.h
Go to the documentation of this file.
1/******************************************************************************/
12
13#ifndef TEXTBOX_HEADER
14#define TEXTBOX_HEADER
15
16#include "Common.h"
17
18/******************************************************************************/
19/*** ***/
20/*** Class Definition: DynamicText ***/
21/*** ***/
22/******************************************************************************/
46{
47public:
57
58private:
59 Canvas &_DestCanvas; // Reference to the canvas where the text box will be displayed
60 Canvas _BckgCanvas; // Canvas containing the background image upon which the text will be drawn
61 Canvas _DraftCanvas; // Canvas used to build up the text box
62 TextAlign _align; // Text alignment within the text box
63 FontList::FontID _FontID; // Primary font to be used
64 GrFont *_Font = nullptr; // Primary font to be used
65 uint16_t _baseline; // Vertical position for the baseline of the text within DynamicText
66
67 static constexpr bool addDebugBorder = false; // Adds a red border around the text box to help with debugging
68
69public:
70 const uint16_t X;
71 const uint16_t Y;
72 const uint16_t WIDTH;
73 const uint16_t HEIGHT;
74
87 DynamicText(Canvas &DestCanvas, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t baseline,
89 : _DestCanvas{DestCanvas}, _BckgCanvas{width, height}, _DraftCanvas{width, height},
90 _align{align}, _FontID{Font}, _baseline{baseline}, X{x}, Y{y}, WIDTH{width}, HEIGHT{height} {};
91
93 DynamicText(void) = delete;
94
101 virtual void begin(void);
102
108 virtual inline void align(TextAlign align)
109 {
110 _align = align;
111 };
112
119 void update(const char *text, uint16_t textBuffSize);
120
126 void update(int value);
127
128private:
129 // Verifies that _Font has been initialized. If not, the applications is
130 // halted.
131 void _validateFont(void);
132};
133
134/******************************************************************************/
135/*** ***/
136/*** Class Definition: TextBox ***/
137/*** ***/
138/******************************************************************************/
157{
158public:
159 static Shape_t shape; // Geometric shape configuration for the expected fonts
160
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 FontList::FontID TextFont, FontList::FontID 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 inline uint16_t width(void) const
232 {
233 return WIDTH;
234 }
235};
236
237#endif
Common definitions used throughout the SoloController app.
Provides higher level TFT graphic functionality used by the menu system.
Definition Canvas.h:34
Defines a simple text box for displaying dynamic text onto a Canvas.
Definition TextBox.h:46
const uint16_t Y
UL y position of the text box within _DestCanvas.
Definition TextBox.h:71
const uint16_t WIDTH
Width of the text box within _DestCanvas.
Definition TextBox.h:72
virtual void begin(void)
Initializes the DynamicText. This method must be called before using calling DynamicText::update()
Definition TextBox.cpp:16
const uint16_t HEIGHT
Height of the text box within _DestCanvas.
Definition TextBox.h:73
const uint16_t X
UL x position of the text box within _DestCanvas.
Definition TextBox.h:70
void update(const char *text, uint16_t textBuffSize)
Updates the text inside a DynamicText.
Definition TextBox.cpp:46
DynamicText(Canvas &DestCanvas, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t baseline, FontList::FontID Font, TextAlign align=CENTER)
DynamicText Constructor.
Definition TextBox.h:87
virtual void align(TextAlign align)
Changes the text alignment. Takes effect after next call to DynamicText::update()
Definition TextBox.h:108
TextAlign
Enumeration used to specify text alignment within the DynamicText.
Definition TextBox.h:52
@ RIGHT
Definition TextBox.h:55
@ CENTER
Definition TextBox.h:54
@ LEFT
Definition TextBox.h:53
FontID
Enumeration listing available fonts.
Definition FontList.h:35
Base class used by all Graphical Fonts.
Definition GrFont.h:46
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
static void initializeFonts(void)
Initializes the fonts and configuration data used by TextBox.
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
uint16_t width(void) const
Definition TextBox.h:231
static Shape_t shape
Definition TextBox.h:159
const uint16_t WIDTH
Definition TextBox.h:172
const uint16_t HEIGHT
Definition TextBox.h:173
void begin(void)
Initializes a specific TextBoxUnits instance.
Definition TextBox.h:225
TextBox(Canvas &DestCanvas, uint16_t x, uint16_t y, uint16_t textWidth, uint16_t unitsWidth, uint16_t height, uint16_t baseline, FontList::FontID TextFont, FontList::FontID UnitsFont)
Generic Constructor.
Definition TextBox.h:189
Data structure defining all TextBox used by all menus.
Definition Definitions.h:64
Configuration information for a TextBox object.
Definition Definitions.h:38
Structure defining basic geometric characteristics of fonts.
Definition Definitions.h:19