TGUI  0.8-dev
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 
105  static sf::String wordWrap(float maxWidth, const sf::String& text, Font font, unsigned int textSize, bool bold, bool dropLeadingSpace = true);
106 
107 
109  public:
110 
117  Vector2f getSize() const;
118 
119 
126  void setString(const sf::String& string);
127 
128 
135  const sf::String& getString() const;
136 
137 
144  void setCharacterSize(unsigned int size);
145 
146 
153  unsigned int getCharacterSize() const;
154 
155 
162  void setColor(Color color);
163 
164 
171  Color getColor() const;
172 
173 
180  void setOpacity(float opacity);
181 
182 
189  float getOpacity() const;
190 
191 
198  void setFont(Font font);
199 
200 
207  Font getFont() const;
208 
209 
220  void setStyle(TextStyle style);
221 
222 
229  TextStyle getStyle() const;
230 
231 
244  Vector2f findCharacterPos(std::size_t index) const;
245 
246 
254  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
255 
256 
258  private:
259 
261  // Calculates the size of the text again after something changed.
263  void recalculateSize();
264 
265 
267  private:
268 
269  sf::Text m_text;
270  Vector2f m_size;
271  Font m_font;
272  Color m_color;
273  float m_opacity = 1;
274  };
275 
277 }
278 
280 
281 #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