TGUI  0.10-beta
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
115 static String wordWrap(float maxWidth, const String& text, Font font, unsigned int textSize, bool bold, bool dropLeadingSpace = true);
116
117
119 public:
120
121
126
127
129 // Copy constructor
131 Text(const Text&);
132
134 // Move constructor
136 Text(Text&&) noexcept = default;
137
139 // Overload of copy assignment operator
141 Text& operator=(const Text&);
142
144 // Move assignment operator
146 Text& operator=(Text&&) noexcept = default;
147
148
154 void setPosition(Vector2f position);
155
156
162 Vector2f getPosition() const;
163
164
171 Vector2f getSize() const;
172
173
180 void setString(const String& string);
181
182
189 const String& getString() const;
190
191
198 void setCharacterSize(unsigned int size);
199
200
207 unsigned int getCharacterSize() const;
208
209
216 void setColor(Color color);
217
218
225 Color getColor() const;
226
227
234 void setOpacity(float opacity);
235
236
243 float getOpacity() const;
244
245
252 void setFont(Font font);
253
254
261 Font getFont() const;
262
263
274 void setStyle(TextStyles style);
275
276
283 TextStyles getStyle() const;
284
285
291 void setOutlineColor(Color color);
292
293
299 Color getOutlineColor() const;
300
301
307 void setOutlineThickness(float thickness);
308
309
315 float getOutlineThickness() const;
316
317
330 Vector2f findCharacterPos(std::size_t index) const;
331
332
338 float getExtraHorizontalPadding() const;
339
340
346 float getExtraHorizontalOffset() const;
347
348
352 float getLineHeight() const;
353
354
358 float getLineWidth() const;
359
360
365 std::shared_ptr<BackendText> getBackendText() const;
366
367
369 private:
370
371 std::shared_ptr<BackendText> m_backendText;
372 Vector2f m_position;
373 Font m_font;
374 Color m_color;
375 Color m_outlineColor;
376 float m_opacity = 1;
377 };
378
380}
381
383
384#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 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.
static String wordWrap(float maxWidth, const String &text, Font font, unsigned int textSize, bool bold, bool dropLeadingSpace=true)
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36