Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
TextElement.hpp
1#pragma once
2
3#include "Texture.hpp"
4#include <string>
5
6#define NORMAL 0
7#define MONOSPACED 1
8#define ICON 2 // old icon font, no longer used
9#define OLD_MONOSPACED 2
10#define SERIF 3
11#define SIMPLIFIED_CHINESE 4
12
13std::string i18n(std::string key);
14std::string i18n_number(int number);
15std::string i18n_date(int timestamp);
16
17class TextElement : public Texture
18{
19public:
20 // constructors
22 TextElement(std::string text, int size, CST_Color* color = 0, int font_type = NORMAL, int wrapped_width = 0);
23
24 // change TextElement
25 void setText(const std::string& text);
26 void setSize(int size);
27 void setColor(const CST_Color& color);
28 void setFont(int font_type);
29 void setWrappedWidth(int wrapped_width);
30
32 void update(bool forceUpdate = false);
33 std::string text = "";
34
35 // if specified, will override any font_type setting
36 std::string customFontPath = "";
37
38 static std::unordered_map<std::string, std::string> i18nCache;
39 static void loadI18nCache(std::string locale);
40
41 // if true, replaces all NORMAL fonts with SIMPLIFIED_CHINESE
42 static bool useSimplifiedChineseFont;
43
44private:
45 // default values
46 int textSize = 16;
47 CST_Color textColor = (CST_Color){ 0xff, 0xff, 0xff };
48 int textFont = NORMAL;
49 int textWrappedWidth = 0;
50
51 // font ttf files path
52 static const char *fontPaths[];
53};
void update(bool forceUpdate=false)
update TextElement with changes
Definition: TextElement.cpp:90