TGUI  1.0-beta
Loading...
Searching...
No Matches
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
57 struct Blueprint
58 {
59 unsigned int characterSize;
60 unsigned int style;
61 Color color;
62 String text;
63 Vector2u gapSize;
64 };
65
71 static float getExtraHorizontalPadding(const Font& font, unsigned int characterSize);
72
73
79 static float getExtraHorizontalOffset(const Font& font, unsigned int characterSize);
80
81
85 static float getExtraVerticalPadding(unsigned int characterSize);
86
87
91 static float getLineHeight(const Font& font, unsigned int characterSize);
92
93
97 static float getLineWidth(const String &text, const Font& font, unsigned int characterSize, TextStyles textStyle = {});
98
99
109 static unsigned int findBestTextSize(const Font& font, float height, int fit = 0);
110
111
123 static String wordWrap(float maxWidth, const String& text, const Font& font, unsigned int textSize, bool bold);
124
125
137 static std::vector<std::vector<Blueprint>> wordWrap(float maxWidth, const std::vector<std::vector<Blueprint>>& lines, const Font& font);
138
139
141 public:
142
143
148
149
151 // Copy constructor
153 Text(const Text&);
154
156 // Move constructor
158 Text(Text&&) noexcept = default;
159
161 // Overload of copy assignment operator
163 Text& operator=(const Text&);
164
166 // Move assignment operator
168 Text& operator=(Text&&) noexcept = default;
169
170
176 void setPosition(Vector2f position);
177
178
184 Vector2f getPosition() const;
185
186
193 Vector2f getSize() const;
194
195
202 void setString(const String& string);
203
204
211 const String& getString() const;
212
213
220 void setCharacterSize(unsigned int size);
221
222
229 unsigned int getCharacterSize() const;
230
231
238 void setColor(Color color);
239
240
247 Color getColor() const;
248
249
256 void setOpacity(float opacity);
257
258
265 float getOpacity() const;
266
267
274 void setFont(const Font& font);
275
276
283 Font getFont() const;
284
285
296 void setStyle(TextStyles style);
297
298
305 TextStyles getStyle() const;
306
307
313 void setOutlineColor(Color color);
314
315
321 Color getOutlineColor() const;
322
323
329 void setOutlineThickness(float thickness);
330
331
337 float getOutlineThickness() const;
338
339
352 Vector2f findCharacterPos(std::size_t index) const;
353
354
360 float getExtraHorizontalPadding() const;
361
362
368 float getExtraHorizontalOffset() const;
369
370
374 float getLineHeight() const;
375
376
380 float getLineWidth() const;
381
382
387 std::shared_ptr<BackendText> getBackendText() const;
388
389
391 private:
392
393 std::shared_ptr<BackendText> m_backendText;
394 Vector2f m_position;
395 Font m_font;
396 Color m_color;
397 Color m_outlineColor;
398 float m_opacity = 1;
399 };
400
402}
403
405
406#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 float getExtraHorizontalOffset(const Font &font, unsigned int characterSize)
Returns an extra distance that text should be placed from the side of a widget as padding.
static float getLineWidth(const String &text, const Font &font, unsigned int characterSize, TextStyles textStyle={})
Returns the width of a single line of text.
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 getLineHeight(const Font &font, unsigned int characterSize)
Returns the height of a single line of text.
static std::vector< std::vector< Blueprint > > wordWrap(float maxWidth, const std::vector< std::vector< Blueprint > > &lines, const Font &font)
static String wordWrap(float maxWidth, const String &text, const Font &font, unsigned int textSize, bool bold)
static float getExtraHorizontalPadding(const Font &font, unsigned int characterSize)
Returns a small distance that text should be placed from the side of a widget as padding.
static unsigned int findBestTextSize(const Font &font, float height, int fit=0)
Finds the best character size for the text.
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Describes a text piece, before turning it into an actual Text object.
Definition: Text.hpp:58