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#include <map>
6
7#define NORMAL 0
8#define MONOSPACED 1
9#define ICON 2 // old icon font, no longer used
10#define OLD_MONOSPACED 2
11#define SERIF 3
12#define SIMPLIFIED_CHINESE 4
13#define KOREAN 5
14#define JAPANESE 6
15
16namespace Chesto {
17
18std::string i18n(std::string key);
19std::string i18n_number(int number);
20std::string i18n_date(int timestamp);
21
22class TextElement : public Texture
23{
24public:
25 // constructors
27 TextElement(std::string text, int size, CST_Color* color = 0, int font_type = NORMAL, int wrapped_width = 0);
28
29 // change TextElement
30 void setText(const std::string& text);
31 void setSize(int size);
32 void setColor(const CST_Color& color);
33 void setFont(int font_type);
34 void setWrappedWidth(int wrapped_width);
35
37 void update(bool forceUpdate = false);
38 std::string text = "";
39
40 // if specified, will override any font_type setting
41 std::string customFontPath = "";
42
43 static std::map<std::string, std::string> i18nCache;
44 static std::vector<std::pair<std::string, std::string>> getAvailableLanguages();
45 static void loadI18nCache(std::string locale);
46 static std::string curLang;
47
48 // if true, replaces all NORMAL fonts with SIMPLIFIED_CHINESE
49 static bool useSimplifiedChineseFont;
50 static bool useKoreanFont;
51 static bool useJapaneseFont;
52
53 static std::map<std::string, int> forcedLangFonts;
54
55private:
56 // default values
57 int textSize = 16;
58 CST_Color textColor = (CST_Color){ 0xff, 0xff, 0xff, 0xff };
59 int textFont = NORMAL;
60 int textWrappedWidth = 0;
61
62 // font ttf files path
63 static const char *fontPaths[];
64};
65
66} // namespace Chesto
void update(bool forceUpdate=false)
update TextElement with changes