gigawidgets 0.3.55
A wxWidgets-style UI library for the Arduino Giga Display Shield.
 
Loading...
Searching...
No Matches
text.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include <Arduino.h>
5#include <gfxfont.h>
6
7#include "core/alignment.hpp"
8#include "core/color.hpp"
9#include "core/fontsize.hpp"
10#include "core/position.hpp"
11#include "core/widget.hpp"
12
13namespace ui {
14
18class Text : public Widget {
19protected:
21 const GFXfont *font;
23 String text;
29 bool wrap;
30
31public:
41 Text(const String &text, fontsize_t scale = 1, color_t color = COLOR_WHITE, const Position &pos = {0, 0}, const Alignment &align = {ALIGN_LEFT, ALIGN_TOP}, bool wrap = true);
42
52 Text(const String &text, const GFXfont &font, color_t color = COLOR_WHITE, const Position &pos = {0, 0}, const Alignment &align = {ALIGN_LEFT, ALIGN_TOP}, bool wrap = true);
53
54 void draw() const override;
55 Size size() const override;
56
61 void setText(const String &text);
62
67 const String &getText() const;
68
73 void setWrap(bool wrap);
74
79 void setFont(const GFXfont &font);
80
86
91 void setColor(color_t new_color);
92
98
104 uisize_t getWidthAtChar(unsigned int index) const;
105
106 DERIVE_EVENT_HANDLERS(Text)
107};
108
109} // namespace ui
Display text to the screen.
Definition text.hpp:18
void setWrap(bool wrap)
Set whether text wraps.
uisize_t getWidthAtChar(unsigned int index) const
Get the width (in pixels) of a substring of the total text.
String text
The text to display.
Definition text.hpp:23
bool wrap
If true, wrap the text when reaching the right side of the parent widget. If false,...
Definition text.hpp:29
Text(const String &text, const GFXfont &font, color_t color=COLOR_WHITE, const Position &pos={0, 0}, const Alignment &align={ALIGN_LEFT, ALIGN_TOP}, bool wrap=true)
Construct text with a given font.
color_t textColor
The text color.
Definition text.hpp:27
Text(const String &text, fontsize_t scale=1, color_t color=COLOR_WHITE, const Position &pos={0, 0}, const Alignment &align={ALIGN_LEFT, ALIGN_TOP}, bool wrap=true)
Construct text with the built-in font.
void setText(const String &text)
Set the text to display.
const GFXfont * font
The font to render the text in. If null, defaults to the built-in font.
Definition text.hpp:21
color_t getColor() const
Get the current widget color.
void setColor(color_t new_color)
Set the text color.
const String & getText() const
Get the currently displayed text.
fontsize_t scale
A scaling factor for the text, e.g. 2x, 3x, etc.
Definition text.hpp:25
Size size() const override
Get the size of the widget.
void setFont(const GFXfont &font)
Set the font to render text in.
void draw() const override
Render the widget to the screen.
void setScale(fontsize_t scale)
Set the scaling factor for the text.
The common interface for all UI objects.
Definition widget.hpp:27
uint16_t color_t
An RGB565 color value. 5 bits red, 6 bits green, 5 bits blue.
Definition color.hpp:13
uint16_t fontsize_t
A non-negative integer for font sizes.
Definition fontsize.hpp:12
uint16_t uisize_t
A non-negative size for UI widgets.
Definition size.hpp:12
A struct that holds a widget's vertical and horizontal alignment.
Definition alignment.hpp:22
A struct that holds the normalized position of a widget.
Definition position.hpp:15
A struct that holds the number of pixels that a widget would take up on the screen.
Definition size.hpp:17