diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-07-15 13:18:15 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-07-15 13:18:15 +0200 |
commit | 1215c2fbdb638f4cf32dc33920cbf4cd5340285c (patch) | |
tree | ccd2c05e483662c8b0765cf328426cf8f3304316 | |
parent | 5e98019ff981053fedc5fb5807b32e3ce0373eec (diff) |
Text: fix text sometimes being outside area, fix down arrow not going to end of text when it's closest
-rw-r--r-- | src/Text.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Text.cpp b/src/Text.cpp index bf7ed6a..a1da8de 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -1085,6 +1085,9 @@ namespace QuickMedia break; } + if(vertex_ref.codepoint == '\n') + continue; + float vertex_right_side = get_text_quad_right_side(vertex_ref); if(vertex_right_side > maxWidth && maxWidth > WORD_WRAP_MIN_SIZE) { ++num_lines; @@ -1352,6 +1355,7 @@ namespace QuickMedia const int start_line = get_vertex_line(startIndex); float closest_char = 999999.9f; int closest_index = -1; + for(int i = getEndOfLine(startIndex) + 1; i < num_vertices && get_vertex_line(i) == start_line + 1; ++i) { const float left_pos = get_text_quad_left_side(vertices_linear[i]); const float pos_diff = std::abs(caret_offset_x - left_pos); @@ -1360,8 +1364,19 @@ namespace QuickMedia closest_index = i; } } + + if(!vertices_linear.empty()) { + const float right_pos_last = get_text_quad_right_side(vertices_linear.back()); + const float pos_diff = std::abs(caret_offset_x - right_pos_last); + if(pos_diff < closest_char) { + closest_char = pos_diff; + closest_index = vertices_linear.size(); + } + } + if(closest_index != -1) return closest_index; + return startIndex; } |