TGUI  0.9-dev
Text.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2020 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 <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 
51  static float getExtraHorizontalPadding(Font font, unsigned int characterSize, TextStyle textStyle = {});
52 
53 
59  static float getExtraHorizontalOffset(Font font, unsigned int characterSize, TextStyle textStyle = {});
60 
61 
65  static float getExtraVerticalPadding(unsigned int characterSize);
66 
67 
71  static float getLineHeight(Font font, unsigned int characterSize, TextStyle textStyle = {});
72 
73 
77  static float getLineWidth(const String &text, Font font, unsigned int characterSize, TextStyle textStyle = {});
78 
79 
88  static unsigned int findBestTextSize(Font font, float height, int fit = 0);
89 
90 
96  static float calculateExtraVerticalSpace(Font font, unsigned int characterSize, TextStyle style = {});
97 
98 
110  static String wordWrap(float maxWidth, const String& text, Font font, unsigned int textSize, bool bold, bool dropLeadingSpace = true);
111 
112 
114  public:
115 
122  Vector2f getSize() const;
123 
124 
131  void setString(const String& string);
132 
133 
140  const String& getString() const;
141 
142 
149  void setCharacterSize(unsigned int size);
150 
151 
158  unsigned int getCharacterSize() const;
159 
160 
167  void setColor(Color color);
168 
169 
176  Color getColor() const;
177 
178 
185  void setOpacity(float opacity);
186 
187 
194  float getOpacity() const;
195 
196 
203  void setFont(Font font);
204 
205 
212  Font getFont() const;
213 
214 
225  void setStyle(TextStyle style);
226 
227 
234  TextStyle getStyle() const;
235 
236 
242  void setOutlineColor(Color color);
243 
244 
250  Color getOutlineColor() const;
251 
252 
258  void setOutlineThickness(float thickness);
259 
260 
266  float getOutlineThickness() const;
267 
268 
281  Vector2f findCharacterPos(std::size_t index) const;
282 
283 
291  void draw(sf::RenderTarget& target, sf::RenderStates states) const;
292 
293 
299  float getExtraHorizontalPadding() const;
300 
301 
307  float getExtraHorizontalOffset() const;
308 
309 
313  float getLineHeight() const;
314 
315 
319  float getLineWidth() const;
320 
321 
323  private:
324 
326  // Calculates the size of the text again after something changed.
328  void recalculateSize();
329 
330 
332  private:
333 
334  sf::Text m_text;
335  String m_string;
336  Vector2f m_size;
337  Font m_font;
338  Color m_color;
339  Color m_outlineColor;
340  float m_opacity = 1;
341  };
342 
344 }
345 
347 
348 #endif // TGUI_TEXT_HPP
Definition: Font.hpp:42
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:35
Definition: Text.hpp:42
Wrapper for colors.
Definition: Color.hpp:47
Wrapper class to store strings.
Definition: String.hpp:70
Wrapper for text styles.
Definition: TextStyle.hpp:44