]> git.tdb.fi Git - libs/gltk.git/blob - source/text.h
Add Text class with multiline support
[libs/gltk.git] / source / text.h
1 #ifndef MSP_GLTK_TEXT_H_
2 #define MSP_GLTK_TEXT_H_
3
4 #include <string>
5 #include <vector>
6
7 namespace Msp {
8 namespace GLtk {
9
10 class Geometry;
11 class Part;
12 class Style;
13
14 /**
15 Stores and renders text.  Supports multiline text.
16 */
17 class Text
18 {
19 private:
20         struct Line
21         {
22                 unsigned start;
23                 unsigned length;
24                 unsigned width;
25         };
26
27         const Style *const &style;
28         std::string text;
29         std::vector<Line> lines;
30
31 public:
32         Text(const Style *const &);
33         Text(const Style *const &, const std::string &);
34
35         unsigned get_width() const;
36         unsigned get_height() const;
37
38         void set(const std::string &);
39         void erase(unsigned, unsigned);
40         void insert(unsigned, const std::string &);
41         const std::string &get() const { return text; }
42         unsigned size() const { return text.size(); }
43
44         void render(const Part &, const Geometry &) const;
45
46         Text &operator=(const std::string &);
47         //operator const std::string &() const { return text; }
48 };
49
50 } // namespace GLtk
51 } // namespace Msp
52
53 #endif