TGUI  0.9.1
Text.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2021 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 
37 namespace tgui
38 {
39  class BackendTextBase;
40 
42 
43  class TGUI_API Text
44  {
45  public:
46 
52  static float getExtraHorizontalPadding(Font font, unsigned int characterSize, TextStyles textStyle = {});
53 
54 
60  static float getExtraHorizontalOffset(Font font, unsigned int characterSize, TextStyles textStyle = {});
61 
62 
66  static float getExtraVerticalPadding(unsigned int characterSize);
67 
68 
72  static float getLineHeight(Font font, unsigned int characterSize, TextStyles textStyle = {});
73 
74 
78  static float getLineWidth(const String &text, Font font, unsigned int characterSize, TextStyles textStyle = {});
79 
80 
89  static unsigned int findBestTextSize(Font font, float height, int fit = 0);
90 
91 
97  static float calculateExtraVerticalSpace(Font font, unsigned int characterSize, TextStyles style = {});
98 
99 
111  static String wordWrap(float maxWidth, const String& text, Font font, unsigned int textSize, bool bold, bool dropLeadingSpace = true);
112 
113 
115  public:
116 
117 
121  Text();
122 
123 
125  // Copy constructor
127  Text(const Text&);
128 
130  // Move constructor
132  Text(Text&&) noexcept = default;
133 
135  // Overload of copy assignment operator
137  Text& operator=(const Text&);
138 
140  // Move assignment operator
142  Text& operator=(Text&&) noexcept = default;
143 
144 
150  void setPosition(Vector2f position);
151 
152 
158  Vector2f getPosition() const;
159 
160 
167  Vector2f getSize() const;
168 
169 
176  void setString(const String& string);
177 
178 
185  const String& getString() const;
186 
187 
194  void setCharacterSize(unsigned int size);
195 
196 
203  unsigned int getCharacterSize() const;
204 
205 
212  void setColor(Color color);
213 
214 
221  Color getColor() const;
222 
223 
230  void setOpacity(float opacity);
231 
232 
239  float getOpacity() const;
240 
241 
248  void setFont(Font font);
249 
250 
257  Font getFont() const;
258 
259 
270  void setStyle(TextStyles style);
271 
272 
279  TextStyles getStyle() const;
280 
281 
287  void setOutlineColor(Color color);
288 
289 
295  Color getOutlineColor() const;
296 
297 
303  void setOutlineThickness(float thickness);
304 
305 
311  float getOutlineThickness() const;
312 
313 
326  Vector2f findCharacterPos(std::size_t index) const;
327 
328 
334  float getExtraHorizontalPadding() const;
335 
336 
342  float getExtraHorizontalOffset() const;
343 
344 
348  float getLineHeight() const;
349 
350 
354  float getLineWidth() const;
355 
356 
361  std::shared_ptr<BackendTextBase> getBackendText() const;
362 
363 
365  private:
366 
367  std::shared_ptr<BackendTextBase> m_backendText;
368  String m_string;
369  Vector2f m_position;
370  Font m_font;
371  Color m_color;
372  Color m_outlineColor;
373  TextStyles m_textStyle = TextStyle::Regular;
374  unsigned int m_characterSize = 32;
375  float m_outlineThickness = 0;
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:39
Wrapper for colors.
Definition: Color.hpp:52
Definition: Font.hpp:56
Wrapper class to store strings.
Definition: String.hpp:74
Wrapper for text styles.
Definition: TextStyle.hpp:58
Definition: Text.hpp:44
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
TextStyle
Enumeration of the text drawing styles.
Definition: TextStyle.hpp:40
@ Regular
Regular characters, no style.
Definition: TextStyle.hpp:41