TGUI  0.8.4
Text.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2019 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/Vector2f.hpp>
32 #include <TGUI/TextStyle.hpp>
33 #include <SFML/Graphics/Text.hpp>
34 #include <SFML/Graphics/Transformable.hpp>
35 
37 
38 namespace tgui
39 {
41 
42  class TGUI_API Text : public sf::Transformable
43  {
44  public:
45 
46 #ifndef TGUI_REMOVE_DEPRECATED_CODE
47  TGUI_DEPRECATED("Use as (non-static) member function instead") static float getExtraHorizontalPadding(const Text& text);
51 #endif
52 
58  static float getExtraHorizontalPadding(Font font, unsigned int characterSize, TextStyle textStyle = {});
59 
60 
66  static float getExtraHorizontalOffset(Font font, unsigned int characterSize, TextStyle textStyle = {});
67 
68 
72  static float getExtraVerticalPadding(unsigned int characterSize);
73 
74 #ifndef TGUI_REMOVE_DEPRECATED_CODE
75  TGUI_DEPRECATED("Use as (non-static) member function instead") static float getLineHeight(const Text& text);
79 #endif
80 
84  static float getLineHeight(Font font, unsigned int characterSize, TextStyle textStyle = {});
85 
86 #ifndef TGUI_REMOVE_DEPRECATED_CODE
87  TGUI_DEPRECATED("Use as (non-static) member function instead") static float getLineWidth(const Text& text);
91 #endif
92 
96  static float getLineWidth(const sf::String &text, Font font, unsigned int characterSize, TextStyle textStyle = {});
97 
98 
107  static unsigned int findBestTextSize(Font font, float height, int fit = 0);
108 
109 
115  static float calculateExtraVerticalSpace(Font font, unsigned int characterSize, TextStyle style = {});
116 
117 
129  static sf::String wordWrap(float maxWidth, const sf::String& text, Font font, unsigned int textSize, bool bold, bool dropLeadingSpace = true);
130 
131 
133  public:
134 
141  Vector2f getSize() const;
142 
143 
150  void setString(const sf::String& string);
151 
152 
159  const sf::String& getString() const;
160 
161 
168  void setCharacterSize(unsigned int size);
169 
170 
177  unsigned int getCharacterSize() const;
178 
179 
186  void setColor(Color color);
187 
188 
195  Color getColor() const;
196 
197 
204  void setOpacity(float opacity);
205 
206 
213  float getOpacity() const;
214 
215 
222  void setFont(Font font);
223 
224 
231  Font getFont() const;
232 
233 
244  void setStyle(TextStyle style);
245 
246 
253  TextStyle getStyle() const;
254 
255 
268  Vector2f findCharacterPos(std::size_t index) const;
269 
270 
278  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
279 
280 
286  float getExtraHorizontalPadding() const;
287 
288 
294  float getExtraHorizontalOffset() const;
295 
296 
300  float getLineHeight() const;
301 
302 
306  float getLineWidth() const;
307 
308 
310  private:
311 
313  // Calculates the size of the text again after something changed.
315  void recalculateSize();
316 
317 
319  private:
320 
321  sf::Text m_text;
322  Vector2f m_size;
323  Font m_font;
324  Color m_color;
325  float m_opacity = 1;
326  };
327 
329 }
330 
332 
333 #endif // TGUI_TEXT_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Wrapper for colors.
Definition: Color.hpp:47
Wrapper for text styles.
Definition: TextStyle.hpp:46
Definition: Font.hpp:42
Definition: Vector2f.hpp:37
Definition: Text.hpp:42