diff options
Diffstat (limited to 'scene/gui/line_edit.cpp')
-rw-r--r-- | scene/gui/line_edit.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 44cc798447..ab556ede0c 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -454,7 +454,7 @@ void LineEdit::_notification(int p_what) { } break; } - int ofs_max=width-style->get_minimum_size().width+x_ofs; + int ofs_max=width-style->get_minimum_size().width; int char_ofs=window_pos; int y_area=height-style->get_minimum_size().height; @@ -731,14 +731,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;i<cursor_pos;i++) - width_to_cursor+=font->get_char_size( text[i] ).width; + if (font.is_valid()) { + + int accum_width=0; - while (width_to_cursor >= window_width && wp < text.length()) { + for(int i=cursor_pos;i>=window_pos;i--) { - width_to_cursor -= font->get_char_size(text[wp]).width; - wp++; + 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<text.length()?text[i+1]:0).width; //anything should do + } + if (accum_width>=window_width) + break; + + wp=i; } } @@ -799,8 +806,8 @@ Size2 LineEdit::get_minimum_size() const { Ref<Font> font=get_font("font"); Size2 min=style->get_minimum_size(); - min+=font->get_string_size(this->text); - + min.height+=font->get_height(); + min.width+=get_constant("minimum_spaces")*font->get_char_size(' ').x; return min; } |