TGUI  0.8-dev
Label.hpp
1 //
3 // TGUI - Texus' Graphical User Interface
4 // Copyright (C) 2012-2017 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_LABEL_HPP
27 #define TGUI_LABEL_HPP
28 
29 
30 #include <TGUI/Widgets/ClickableWidget.hpp>
31 #include <TGUI/Renderers/LabelRenderer.hpp>
32 #include <TGUI/Text.hpp>
33 
35 
36 namespace tgui
37 {
41  class TGUI_API Label : public ClickableWidget
42  {
43  public:
44 
45  typedef std::shared_ptr<Label> Ptr;
46  typedef std::shared_ptr<const Label> ConstPtr;
47 
48 
53  {
54  Left,
55  Center,
56  Right
57  };
58 
59 
63  enum class VerticalAlignment
64  {
65  Top ,
66  Center,
67  Bottom
68  };
69 
70 
72  // Default constructor
74  Label();
75 
76 
85  static Label::Ptr create(sf::String text = "");
86 
87 
96  static Label::Ptr copy(Label::ConstPtr label);
97 
98 
103  LabelRenderer* getSharedRenderer();
104  const LabelRenderer* getSharedRenderer() const;
105 
111  LabelRenderer* getRenderer();
112  const LabelRenderer* getRenderer() const;
113 
114 
130  void setSize(const Layout2d& size) override;
131  using Widget::setSize;
132 
133 
144  void setText(const sf::String& text);
145 
146 
153  const sf::String& getText() const;
154 
155 
162  void setTextSize(unsigned int size);
163 
164 
171  unsigned int getTextSize() const;
172 
173 
182  void setHorizontalAlignment(HorizontalAlignment alignment);
183 
184 
191  HorizontalAlignment getHorizontalAlignment() const;
192 
193 
202  void setVerticalAlignment(VerticalAlignment alignment);
203 
204 
211  VerticalAlignment getVerticalAlignment() const;
212 
213 
225  void setAutoSize(bool autoSize);
226 
227 
234  bool getAutoSize() const;
235 
236 
249  void setMaximumTextWidth(float maximumWidth);
250 
251 
261  float getMaximumTextWidth() const;
262 
263 
271  void ignoreMouseEvents(bool ignore = true);
272 
273 
279  bool isIgnoringMouseEvents() const;
280 
281 
287  void setParent(Container* parent) override;
288 
289 
293  void leftMouseReleased(sf::Vector2f pos) override;
294 
295 
303  void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
304 
305 
307  protected:
308 
318  Signal& getSignal(std::string signalName) override;
319 
320 
327  void rendererChanged(const std::string& property) override;
328 
329 
331  // This function is called every frame with the time passed since the last frame.
333  void update(sf::Time elapsedTime) override;
334 
335 
337  // Rearrange the text, making use of the given size of maximum text width.
339  void rearrangeText();
340 
341 
343  // Makes a copy of the widget
345  Widget::Ptr clone() const override
346  {
347  return std::make_shared<Label>(*this);
348  }
349 
350 
352  public:
353 
354  SignalString onDoubleClick = {"DoubleClicked"};
355 
356 
358  protected:
359 
360  sf::String m_string;
361  std::vector<Text> m_lines;
362 
363  unsigned int m_textSize = 18;
364  HorizontalAlignment m_horizontalAlignment = HorizontalAlignment::Left;
365  VerticalAlignment m_verticalAlignment = VerticalAlignment::Top;
366 
367  bool m_autoSize = true;
368 
369  float m_maximumTextWidth = 0;
370 
371  bool m_ignoringMouseEvents = false;
372 
373  // Will be set to true after the first click, but gets reset to false when the second click does not occur soon after
374  bool m_possibleDoubleClick = false;
375 
376  // Cached renderer properties
377  Borders m_bordersCached;
378  Padding m_paddingCached;
379  TextStyle m_textStyleCached;
380  Color m_textColorCached;
381  Color m_borderColorCached;
382  Color m_backgroundColorCached;
383 
385  };
386 
388 }
389 
391 
392 #endif // TGUI_LABEL_HPP
Namespace that contains all TGUI functions and classes.
Definition: AbsoluteOrRelativeValue.hpp:36
Widget::Ptr clone() const override
Makes a copy of the widget if you don&#39;t know its exact type.
Definition: Label.hpp:345
Wrapper for colors.
Definition: Color.hpp:46
Wrapper for text styles.
Definition: TextStyle.hpp:46
Class to store the position or size of a widget.
Definition: Layout.hpp:243
Label widget.
Definition: Label.hpp:41
std::shared_ptr< Label > Ptr
Shared widget pointer.
Definition: Label.hpp:45
Clickable widget.
Definition: ClickableWidget.hpp:39
Definition: LabelRenderer.hpp:36
virtual void setSize(const Layout2d &size)
Changes the size of the widget.
std::shared_ptr< Widget > Ptr
Shared widget pointer.
Definition: Widget.hpp:66
Container widget.
Definition: Container.hpp:47
Signal to which the user can subscribe to get callbacks from.
Definition: Signal.hpp:59
Definition: Outline.hpp:38
VerticalAlignment
The vertical text alignment.
Definition: Label.hpp:63
HorizontalAlignment
The horizontal text alignment.
Definition: Label.hpp:52
std::shared_ptr< const Label > ConstPtr
Shared constant widget pointer.
Definition: Label.hpp:46