]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/text.h
Add Text class with multiline support
[libs/gltk.git] / source / text.h
diff --git a/source/text.h b/source/text.h
new file mode 100644 (file)
index 0000000..46bd18f
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef MSP_GLTK_TEXT_H_
+#define MSP_GLTK_TEXT_H_
+
+#include <string>
+#include <vector>
+
+namespace Msp {
+namespace GLtk {
+
+class Geometry;
+class Part;
+class Style;
+
+/**
+Stores and renders text.  Supports multiline text.
+*/
+class Text
+{
+private:
+       struct Line
+       {
+               unsigned start;
+               unsigned length;
+               unsigned width;
+       };
+
+       const Style *const &style;
+       std::string text;
+       std::vector<Line> lines;
+
+public:
+       Text(const Style *const &);
+       Text(const Style *const &, const std::string &);
+
+       unsigned get_width() const;
+       unsigned get_height() const;
+
+       void set(const std::string &);
+       void erase(unsigned, unsigned);
+       void insert(unsigned, const std::string &);
+       const std::string &get() const { return text; }
+       unsigned size() const { return text.size(); }
+
+       void render(const Part &, const Geometry &) const;
+
+       Text &operator=(const std::string &);
+       //operator const std::string &() const { return text; }
+};
+
+} // namespace GLtk
+} // namespace Msp
+
+#endif