diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-09-29 01:13:00 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-09-29 01:13:00 +0200 |
commit | f92ac0050ffcc4b85b116602d4a45344b7e86f52 (patch) | |
tree | 8c90bfd5c90f3992319b2653be4d8793456cdb24 /include | |
parent | 4b00d02b124070064b0a8cbd3a8178c599a2a88c (diff) |
Fix caret navigation
Diffstat (limited to 'include')
-rw-r--r-- | include/Text.hpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/include/Text.hpp b/include/Text.hpp index d34fd47..0244ba1 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -46,6 +46,13 @@ namespace QuickMedia //bool ownLine; // Currently only used for emoji, to make emoji bigger when it's the only thing on a line bool is_japanese; }; + + struct VertexRef { + int vertices_index; // index to |vertices| VertexArray + int index; // index within vertices[vertices_index] + int line; + sf::Uint32 codepoint; + }; class Text { @@ -94,14 +101,9 @@ namespace QuickMedia UP, DOWN, HOME, - END - }; - - struct VertexRef { - int vertices_index; // index to |vertices| VertexArray - int index; // index within vertices[vertices_index] - int line; - sf::Uint32 codepoint; + END, + LEFT, + RIGHT }; void updateCaret(); @@ -115,6 +117,11 @@ namespace QuickMedia float get_text_quad_left_side(const VertexRef &vertex_ref) const; float get_text_quad_right_side(const VertexRef &vertex_ref) const; + // If the index is past the end, then the caret offset is the right side of the last character, rather than the left side + float get_caret_offset_by_caret_index(int index) const; + VertexRef& get_vertex_ref_clamp(int index); + // Takes into consideration if index is the last vertex and the last vertex is a newline, then it should be on its own line + int get_vertex_line(int index) const; private: sf::String str; // TODO: Remove this for non-editable text??? const sf::Font *font; @@ -138,6 +145,7 @@ namespace QuickMedia std::vector<TextElement> textElements; int caretIndex; + float caret_offset_x; sf::Vector2f caretPosition; sf::Clock lastSeenTimer; sf::Vector2u renderTargetSize; |