From 1215c2fbdb638f4cf32dc33920cbf4cd5340285c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 15 Jul 2023 13:18:15 +0200 Subject: Text: fix text sometimes being outside area, fix down arrow not going to end of text when it's closest --- src/Text.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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; } -- cgit v1.2.3