Simple SFML GUI  0.2a
TextLabel.hpp
1 /*
2  * TextLabel.hpp
3  *
4  * Created on: 30.05.2017
5  * Author: jakub
6  */
7 
8 #ifndef SSG_TEXTLABEL_HPP_
9 #define SSG_TEXTLABEL_HPP_
10 
11 #include <cmath>
12 #include <set>
13 #include <vector>
14 
15 #include "Element.hpp"
16 #include "HaveFont.hpp"
17 #include "HaveMargin.hpp"
18 #include "HaveWordWrap.hpp"
19 #include "HaveHover.hpp"
20 #include "trim.hpp"
21 #include "TextUpdater.hpp"
22 
23 class Lang;
24 class Button;
25 
26 class TextLabel :
27  public TextLine,
28  public HaveMargin {
29 public:
30  friend Lang;
31  friend FontManager;
32  friend Button;
33  TextLabel(const sf::String& name = sf::String(), const sf::String& text = sf::String());
34  TextLabel(const sf::String& name, const sf::String& text, bool autoResize);
35  TextLabel(const sf::String& name, bool autoResize);
36  ~TextLabel();
37 
38  virtual void draw(sf::RenderTarget& target, sf::RenderStates states) override;
39  virtual bool update(sf::Vector2f mp, bool pressLeft, bool pressRight, bool aboveHover) override;
40  virtual void updateArea() override;
41  virtual bool setColor(ColorId::Type colorId, StateId::Type stateId, sf::Color color) override;
42  virtual bool setColorEnabled(ColorId::Type colorId, StateId::Type stateId, bool enabled) override;
43  virtual void setText(const sf::String& text) override;
44  virtual void fontChangeEvent() override;
45 
46  void setAlign(Align align);
47  void setVAlign(VAlign valign);
48  void setAutoResize(bool autoResize);
49  void setAutoResizeParentLimit(bool value);
50  bool autoResizeUpdate();
51  void updateLines();
52  void setMinimumVisibleLines(size_t value);
53  void revalidateTextAlign();
54  void setLinePrefix(const sf::String& value);
55  sf::String getLinePrefix() const;
56 
57 protected:
58  std::vector<TextLine> parseLines(const sf::String& lines);
59 
60  void lineToDefault(TextLine& line);
61  void lazyRevalidateTextAlign();
62 
63  TextUpdater textUpdater;
64  Align align = Align::Left;
65  VAlign valign = VAlign::Top;
66  sf::String linePrefix;
67  std::vector<TextLine> lines;
68  std::vector<TextLine> wrapped;
69  float lastAreaHeight = 0.f;
70  float lastAreaWidth = 0.f;
71  bool dirtyFlag = false;
72 
73  static std::map<std::wstring, std::function<void(TextLine&, const std::wstring& value)> > parseFunctions;
74  static void updateAllLines();
75  static std::set<TextLabel*> textLabelSet;
76 
77 private:
78  static void initParseFunctions();
79  static bool parseColor(const std::wstring& value, sf::Color& color);
80  void setDirty();
81 };
82 
83 typedef std::shared_ptr<TextLabel> TextLabelPtr;
84 
85 #endif /* SSG_TEXTLABEL_HPP_ */
Definition: TextLabel.hpp:26
Pressable button with some configuration options.
Definition: Button.hpp:41
Definition: FontManager.hpp:17
Definition: TextUpdater.hpp:14
Definition: HaveMargin.hpp:14
Definition: Lang.hpp:15
Definition: TextLine.hpp:16