diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2020-03-24 21:27:44 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-24 21:27:44 +0100 | 
| commit | b587f98fccb080bf3d8708c0b4fff9c93e697f31 (patch) | |
| tree | 20cab717037ef611a07d1973e5ed5fb2156d4951 | |
| parent | 641c85a54f3f9edcfe6c4f7c65830c60d46dd436 (diff) | |
| parent | c7c47410aaef19c6988f78722fd596f16e66db27 (diff) | |
Merge pull request #37176 from dkaste/line-edit-secret-fix-2
Use LineEdit secret character width everywhere
| -rw-r--r-- | scene/gui/line_edit.cpp | 20 | 
1 files changed, 10 insertions, 10 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 73380c6b1b..491a981140 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -633,7 +633,7 @@ void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) {  		Ref<Font> font = get_font("font");  		if (font != NULL) {  			for (int i = selection.begin; i < selection.end; i++) -				cached_width -= font->get_char_size(text[i]).width; +				cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width;  		}  		text.erase(selection.begin, selected); @@ -1093,11 +1093,7 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {  		int char_w = 0;  		if (font != NULL) { -			if (is_secret()) { -				char_w = font->get_char_size(secret_character[0]).width; -			} else { -				char_w = font->get_char_size(text[ofs]).width; -			} +			char_w = font->get_char_size(pass ? secret_character[0] : text[ofs]).width;  		}  		pixel_ofs += char_w; @@ -1149,7 +1145,7 @@ int LineEdit::get_cursor_pixel_pos() {  	while (ofs < cursor_pos) {  		if (font != NULL) { -			pixel_ofs += font->get_char_size(text[ofs]).width; +			pixel_ofs += font->get_char_size(pass ? secret_character[0] : text[ofs]).width;  		}  		ofs++;  	} @@ -1208,7 +1204,7 @@ void LineEdit::delete_char() {  	Ref<Font> font = get_font("font");  	if (font != NULL) { -		cached_width -= font->get_char_size(text[cursor_pos - 1]).width; +		cached_width -= font->get_char_size(pass ? secret_character[0] : text[cursor_pos - 1]).width;  	}  	text.erase(cursor_pos - 1, 1); @@ -1228,7 +1224,7 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) {  		Ref<Font> font = get_font("font");  		if (font != NULL) {  			for (int i = p_from_column; i < p_to_column; i++) -				cached_width -= font->get_char_size(text[i]).width; +				cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width;  		}  	} else {  		cached_width = 0; @@ -1352,7 +1348,11 @@ void LineEdit::set_cursor_position(int p_pos) {  					// Do not do this, because if the cursor is at the end, its just fine that it takes no space.  					// accum_width = font->get_char_size(' ').width;  				} else { -					accum_width += font->get_char_size(text[i], i + 1 < text.length() ? text[i + 1] : 0).width; // Anything should do. +					if (pass) { +						accum_width += font->get_char_size(secret_character[0], i + 1 < text.length() ? secret_character[0] : 0).width; +					} 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;  |