libgui 3.00
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiText.h
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2009-2026
4 * GuiText.h
5 ***************************************************************************/
6#pragma once
7
9class GuiText : public GuiElement
10{
11 public:
16 GuiText(const char * t, int s, PixelColor c);
20 GuiText(const char * t);
22 ~GuiText();
25 void setText(const char * t);
28 void setWText(wchar_t * t);
30 int getLength();
39 static void setPresets(int sz, PixelColor c, int w, uint16_t s, ALIGN_H h, ALIGN_V v);
42 void setFontSize(int s);
45 void setMaxWidth(int w);
47 int getTextWidth();
51 void getNaturalSize(int& w, int& h) override;
54 void setScroll(SCROLL s);
58 void setWrap(bool w, int width = 0);
61 void setColor(PixelColor c);
64 void setStyle(uint16_t s);
68 void setAlignment(ALIGN_H hor, ALIGN_V vert);
72 void setNudgeY(int n) { nudgeY = n; }
75 void setLineSpacing(int px) { lineSpacing = px; }
77 void resetText();
79 void draw() override;
80 private:
81 PixelColor color;
82 wchar_t* text;
83 wchar_t *textDyn[20];
84 int textDynNum;
85 char * origText;
86 int size;
87 int maxWidth;
88 SCROLL textScroll;
89 int textScrollPos;
90 int textScrollInitialDelay;
91 int textScrollDelay;
92 uint32_t textScrollLastTick = 0;
93 uint16_t style;
94 bool wrap;
95 int nudgeY = 0;
96 int lineSpacing = 6;
97
98 // What measuring the text cost, kept so a layout pass that asks for the size every frame costs
99 // nothing. Measured at `size`, and valid while the text, the size and the font are unchanged.
100 int measuredW;
101 int measuredH;
102 int measuredSize;
103 uint32_t measuredGen;
104 // The same for the full width of the text at the size it is drawn at (which follows the
105 // element's scale), used by the scroll check every frame
106 int fullWidth;
107 int fullWidthSize;
108 uint32_t fullWidthGen;
109
110 wchar_t* getText(const char *text) const;
111 bool scrollStepDue();
112 void measure();
113 void forgetMeasurements();
114 int getFullWidth(int atSize);
115};
116
117extern GuiTextTranslator* textTranslator;
int width
Element width.
Definition GuiElement.h:273
GuiElement()
Constructor.
Definition GuiElement.cpp:9
Hashed msgid -> UTF-8 string table loaded from a single binary .lang blob (see loadLanguage()).
void setLineSpacing(int px)
Sets the pixels added to the font size to get the distance between wrapped lines (default 6; less for...
Definition GuiText.h:75
void setWrap(bool w, int width=0)
Enables/disables text wrapping.
Definition GuiText.cpp:257
void setColor(PixelColor c)
Sets the font color.
Definition GuiText.cpp:296
void resetText()
Updates the text to the selected language.
Definition GuiText.cpp:340
GuiText(const char *t, int s, PixelColor c)
Constructor.
Definition GuiText.cpp:34
~GuiText()
Destructor.
Definition GuiText.cpp:106
void setScroll(SCROLL s)
Enables/disables text scrolling.
Definition GuiText.cpp:274
static void setPresets(int sz, PixelColor c, int w, uint16_t s, ALIGN_H h, ALIGN_V v)
Sets up preset values to be used by GuiText(t) Useful when printing multiple text elements,...
Definition GuiText.cpp:186
void getNaturalSize(int &w, int &h) override
Gets the text's size for layout: its rendered width and height on one line (at most the maximum width...
Definition GuiText.cpp:505
void setNudgeY(int n)
Moves the drawn text down (or up, if negative) by this many design pixels, after it is placed.
Definition GuiText.h:72
void setFontSize(int s)
Sets the font size.
Definition GuiText.cpp:196
void setText(const char *t)
Sets the text of the GuiText element.
Definition GuiText.cpp:125
int getTextWidth()
Gets the width of the text when rendered.
Definition GuiText.cpp:248
void draw() override
Constantly called to draw the text.
Definition GuiText.cpp:384
void setWText(wchar_t *t)
Sets the text of the GuiText element.
Definition GuiText.cpp:153
void setMaxWidth(int w)
Sets the maximum width of the drawn texture image.
Definition GuiText.cpp:232
int getLength()
Gets the translated text length of the GuiText element.
Definition GuiText.cpp:178
void setStyle(uint16_t s)
Sets the GuiTextRenderer style attributes.
Definition GuiText.cpp:302
void setAlignment(ALIGN_H hor, ALIGN_V vert)
Sets the text alignment.
Definition GuiText.cpp:307
SCROLL
Scrolling mode of a GuiText (none or horizontal).
Definition Gui.h:39
ALIGN_V
Vertical alignment of a GuiElement relative to its parent.
Definition GuiElement.h:21
ALIGN_H
Horizontal alignment of a GuiElement relative to its parent.
Definition GuiElement.h:29
8-bit-per-channel RGBA color used by the video interfaces.
Definition Mesh.h:16