TGUI  1.0-alpha
Text.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2022 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25
26#ifndef TGUI_TEXT_HPP
27#define TGUI_TEXT_HPP
28
29#include <TGUI/Font.hpp>
30#include <TGUI/Color.hpp>
31#include <TGUI/Vector2.hpp>
32#include <TGUI/TextStyle.hpp>
33#include <TGUI/RenderStates.hpp>
34
36
37namespace tgui
38{
39 class BackendText;
40
42
43 constexpr unsigned int AutoTextSize = 0xFFFFFFFF;
44
46
47 class TGUI_API Text
48 {
49 public:
50
56 static float getExtraHorizontalPadding(Font font, unsigned int characterSize, TextStyles textStyle = {});
57
58
64 static float getExtraHorizontalOffset(Font font, unsigned int characterSize, TextStyles textStyle = {});
65
66
70 static float getExtraVerticalPadding(unsigned int characterSize);
71
72
76 static float getLineHeight(Font font, unsigned int characterSize, TextStyles textStyle = {});
77
78
82 static float getLineWidth(const String &text, Font font, unsigned int characterSize, TextStyles textStyle = {});
83
84
93 static unsigned int findBestTextSize(Font font, float height, int fit = 0);
94
95
101 static float calculateExtraVerticalSpace(Font font, unsigned int characterSize, TextStyles style = {});
102
103
113 static String wordWrap(float maxWidth, const String& text, Font font, unsigned int textSize, bool bold);
114
115
117 public:
118
119
124
125
127 // Copy constructor
129 Text(const Text&);
130
132 // Move constructor
134 Text(Text&&) noexcept = default;
135
137 // Overload of copy assignment operator
139 Text& operator=(const Text&);
140
142 // Move assignment operator
144 Text& operator=(Text&&) noexcept = default;
145
146
152 void setPosition(Vector2f position);
153
154
160 Vector2f getPosition() const;
161
162
169 Vector2f getSize() const;
170
171
178 void setString(const String& string);
179
180
187 const String& getString() const;
188
189
196 void setCharacterSize(unsigned int size);
197
198
205 unsigned int getCharacterSize() const;
206
207
214 void setColor(Color color);
215
216
223 Color getColor() const;
224
225
232 void setOpacity(float opacity);
233
234
241 float getOpacity() const;
242
243
250 void setFont(Font font);
251
252
259 Font getFont() const;
260
261
272 void setStyle(TextStyles style);
273
274
281 TextStyles getStyle() const;
282
283
289 void setOutlineColor(Color color);
290
291
297 Color getOutlineColor() const;
298
299
305 void setOutlineThickness(float thickness);
306
307
313 float getOutlineThickness() const;
314
315
328 Vector2f findCharacterPos(std::size_t index) const;
329
330
336 float getExtraHorizontalPadding() const;
337
338
344 float getExtraHorizontalOffset() const;
345
346
350 float getLineHeight() const;
351
352
356 float getLineWidth() const;
357
358
363 std::shared_ptr<BackendText> getBackendText() const;
364
365
367 private:
368
369 std::shared_ptr<BackendText> m_backendText;
370 Vector2f m_position;
371 Font m_font;
372 Color m_color;
373 Color m_outlineColor;
374 float m_opacity = 1;
375 };
376
378}
379
381
382#endif // TGUI_TEXT_HPP
Base class for text implementations that depend on the backend.
Definition: BackendText.hpp:41
Wrapper for colors.
Definition: Color.hpp:63
Definition: Font.hpp:57
Wrapper class to store strings.
Definition: String.hpp:79
Wrapper for text styles.
Definition: TextStyle.hpp:58
Definition: Text.hpp:48
static unsigned int findBestTextSize(Font font, float height, int fit=0)
Finds the best character size for the text.
static float getExtraHorizontalPadding(Font font, unsigned int characterSize, TextStyles textStyle={})
Returns a small distance that text should be placed from the side of a widget as padding.
static String wordWrap(float maxWidth, const String &text, Font font, unsigned int textSize, bool bold)
static float calculateExtraVerticalSpace(Font font, unsigned int characterSize, TextStyles style={})
Text()
Default constructor.
static float getExtraVerticalPadding(unsigned int characterSize)
Returns the distance that text should be placed from the bottom of the widget as padding.
static float getLineWidth(const String &text, Font font, unsigned int characterSize, TextStyles textStyle={})
Returns the width of a single line of text.
static float getLineHeight(Font font, unsigned int characterSize, TextStyles textStyle={})
Returns the height of a single line of text.
static float getExtraHorizontalOffset(Font font, unsigned int characterSize, TextStyles textStyle={})
Returns an extra distance that text should be placed from the side of a widget as padding.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36