diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-08-13 21:33:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-13 21:33:02 +0200 |
commit | 84461a5c91f6534d2ecd3d5b3e5209fa135c1a75 (patch) | |
tree | 613a93061c3d89359d84334d13cb11f7e912764a | |
parent | 4c3ece8c4bdb6d4927e69dce1c9b716ebc93d4ee (diff) | |
parent | 00381db2e756705d98ee9a9466a2671c97b45053 (diff) |
Merge pull request #50609 from bruvzg/te_block_caret
[TextEdit] Improve block/insert caret drawing.
-rw-r--r-- | scene/gui/text_edit.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 443eb68bc5..ab387f02e7 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1110,20 +1110,37 @@ void TextEdit::_notification(int p_what) { t_caret.size.y = h; } t_caret.position += Vector2(char_margin + ofs_x, ofs_y); + draw_rect(t_caret, caret_color, overtype_mode); - draw_rect(t_caret, caret_color, false); + if (l_caret != Rect2() && l_dir != t_dir) { + l_caret.position += Vector2(char_margin + ofs_x, ofs_y); + l_caret.size.x = caret_width; + draw_rect(l_caret, caret_color * Color(1, 1, 1, 0.5)); + } } else { // End of the line. - if (overtype_mode) { - l_caret.position.y = TS->shaped_text_get_descent(rid); + if (gl_size > 0) { + // Adjust for actual line dimensions. + if (overtype_mode) { + l_caret.position.y = TS->shaped_text_get_descent(rid); + l_caret.size.y = caret_width; + } else { + l_caret.position.y = -TS->shaped_text_get_ascent(rid); + l_caret.size.y = h; + } + } else if (overtype_mode) { + l_caret.position.y += l_caret.size.y; l_caret.size.y = caret_width; + } + if (l_caret.position.x >= TS->shaped_text_get_size(rid).x) { + l_caret.size.x = font->get_char_size('m', 0, font_size).x; } else { - l_caret.position.y = -TS->shaped_text_get_ascent(rid); - l_caret.size.y = h; + l_caret.size.x = 3 * caret_width; } l_caret.position += Vector2(char_margin + ofs_x, ofs_y); - l_caret.size.x = font->get_char_size('M', 0, font_size).x; - - draw_rect(l_caret, caret_color, false); + if (l_dir == TextServer::DIRECTION_RTL) { + l_caret.position.x -= l_caret.size.x; + } + draw_rect(l_caret, caret_color, overtype_mode); } } else { // Normal caret. |