From d411cbe1d99c6491476c5b479fcda1dabab043f2 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 12 Jun 2016 12:05:21 -0300 Subject: [PATCH] rewrote LineEdit window repositioning code so it does not eat the last character, closes #4992 (cherry picked from commit 83bf8036def06e8038891b1f143ac86c1d9b0c0c) --- scene/gui/line_edit.cpp | 19 +++++++++++++------ tools/editor/plugins/theme_editor_plugin.cpp | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 21dee62b38d..a71b4ba4032 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -713,14 +713,21 @@ void LineEdit::set_cursor_pos(int p_pos) { int width_to_cursor=0; int wp=window_pos; - if (font != NULL) { - for (int i=window_pos;iget_char_size( text[i] ).width; + if (font.is_valid()) { - while (width_to_cursor >= window_width && wp < text.length()) { + int accum_width=0; - width_to_cursor -= font->get_char_size(text[wp]).width; - wp++; + for(int i=cursor_pos;i>=window_pos;i--) { + + if (i>=text.length()) { + accum_width=font->get_char_size(' ').width; //anything should do + } else { + accum_width+=font->get_char_size(text[i],i+1=window_width) + break; + + wp=i; } } diff --git a/tools/editor/plugins/theme_editor_plugin.cpp b/tools/editor/plugins/theme_editor_plugin.cpp index 938b8344ba9..561357f0c90 100644 --- a/tools/editor/plugins/theme_editor_plugin.cpp +++ b/tools/editor/plugins/theme_editor_plugin.cpp @@ -522,6 +522,7 @@ ThemeEditor::ThemeEditor() { add_child(panel); panel->set_area_as_parent_rect(0); panel->set_margin(MARGIN_TOP,25); + panel->set_theme(Theme::get_default()); main_vb= memnew( VBoxContainer ); panel->add_child(main_vb);