TGUI  0.8-alpha
Text.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2018 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 
49  static float getExtraHorizontalPadding(const Text& text);
50 
51 
55  static float getExtraHorizontalPadding(Font font, unsigned int characterSize, TextStyle textStyle = {});
56 
57 
61  static float getExtraVerticalPadding(unsigned int characterSize);
62 
63 
67  static float getLineHeight(const Text& text);
68 
69 
73  static float getLineHeight(Font font, unsigned int characterSize, TextStyle textStyle = {});
74 
75 
84  static unsigned int findBestTextSize(Font font, float height, int fit = 0);
85 
86 
92  static float calculateExtraVerticalSpace(Font font, unsigned int characterSize, TextStyle style = {});
93 
94 
106  static sf::String wordWrap(float maxWidth, const sf::String& text, Font font, unsigned int textSize, bool bold, bool dropLeadingSpace = true);
107 
108 
110  public:
111 
118  Vector2f getSize() const;
119 
120 
127  void setString(const sf::String& string);
128 
129 
136  const sf::String& getString() const;
137 
138 
145  void setCharacterSize(unsigned int size);
146 
147 
154  unsigned int getCharacterSize() const;
155 
156 
163  void setColor(Color color);
164 
165 
172  Color getColor() const;
173 
174 
181  void setOpacity(float opacity);
182 
183 
190  float getOpacity() const;
191 
192 
199  void setFont(Font font);
200 
201 
208  Font getFont() const;
209 
210 
221  void setStyle(TextStyle style);
222 
223 
230  TextStyle getStyle() const;
231 
232 
245  Vector2f findCharacterPos(std::size_t index) const;
246 
247 
255  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
256 
257 
259  private:
260 
262  // Calculates the size of the text again after something changed.
264  void recalculateSize();
265 
266 
268  private:
269 
270  sf::Text m_text;
271  Vector2f m_size;
272  Font m_font;
273  Color m_color;
274  float m_opacity = 1;
275  };
276 
278 }
279 
281 
282 #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