]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/text.h
Rework how widget ownership works in Container
[libs/gltk.git] / source / text.h
index db58b2462621aad9dcd0e66db32baa7195d1ae36..3387f362953ce87971e8dab4534ae876c922df96 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <string>
 #include <vector>
+#include "mspgltk_api.h"
+#include "state.h"
 
 namespace Msp {
 namespace GLtk {
@@ -15,20 +17,21 @@ class Style;
 /**
 Stores and renders text.  Supports multiline text.
 */
-class Text
+class MSPGLTK_API Text
 {
 private:
        struct Line
        {
-               unsigned start;
-               unsigned length;
-               unsigned width;
+               std::size_t start = 0;
+               std::size_t bytes = 0;
+               std::size_t length = 0;
+               unsigned width = 0;
        };
 
        struct RenderData;
        struct CoordsToGeomData;
 
-       const Style *style;
+       const Style *style = nullptr;
        std::string text;
        std::vector<Line> lines;
 
@@ -43,28 +46,32 @@ public:
        void autosize(const Part &, Geometry &) const;
 
        void set(const std::string &);
-       void erase(unsigned, unsigned);
-       void insert(unsigned, const std::string &);
+       void erase(std::size_t, std::size_t);
+       void insert(std::size_t, const std::string &);
        const std::string &get() const { return text; }
-       unsigned size() const { return text.size(); }
-       unsigned get_n_lines() const { return lines.size(); }
-       unsigned get_line_length(unsigned) const;
-       void offset_to_coords(unsigned, unsigned &, unsigned &) const;
-       unsigned coords_to_offset(unsigned, unsigned) const;
-       Geometry coords_to_geometry(const Part &, const Geometry &, unsigned, unsigned, unsigned) const;
-
-       void build(const Part &, const Geometry &, PartCache &) const;
-       void build(const Part &, const Geometry &, unsigned, PartCache &) const;
+       std::size_t size() const { return text.size(); }
+       std::size_t get_n_lines() const { return lines.size(); }
+       std::size_t get_visible_lines(const Part &, const Geometry &, unsigned *) const;
+       std::size_t get_line_length(std::size_t) const;
+       std::size_t move_offset(std::size_t, std::ptrdiff_t) const;
+       void offset_to_coords(std::size_t, std::size_t &, std::size_t &) const;
+       std::size_t coords_to_offset(std::size_t, std::size_t) const;
+       Geometry coords_to_geometry(const Part &, const Geometry &, std::size_t, std::size_t, std::size_t) const;
+
+       void build(const Part &, State, const Geometry &, PartCache &) const;
+       void build(const Part &, State, const Geometry &, std::size_t, PartCache &) const;
 
        Text &operator=(const std::string &);
 private:
        void find_lines();
+       std::size_t count_characters(std::size_t, std::size_t) const;
+       void check_alignment(std::size_t) const;
 
-       template<typename T, void (Text::*)(unsigned, const Geometry &, T &) const>
-       void process_lines(const Part &, const Geometry &, unsigned, T &) const;
+       template<typename T>
+       void process_lines(const Part &, const Geometry &, std::size_t, void (Text::*)(std::size_t, const Geometry &, T &) const, T &) const;
 
-       void build_line(unsigned, const Geometry &, RenderData &) const;
-       void coords_to_geom_line(unsigned, const Geometry &, CoordsToGeomData &) const;
+       void build_line(std::size_t, const Geometry &, RenderData &) const;
+       void coords_to_geom_line(std::size_t, const Geometry &, CoordsToGeomData &) const;
 };
 
 } // namespace GLtk