summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorDarren Kaste <darrenkaste@gmail.com>2020-03-19 19:06:14 -0400
committerDarren Kaste <darrenkaste@gmail.com>2020-03-19 19:06:14 -0400
commitc7c47410aaef19c6988f78722fd596f16e66db27 (patch)
tree7205747deca168a2a32004527e1428d3361c0a01 /scene
parent1a532d53ccfd11cae7efdda1d406fd26da5cdb1e (diff)
Use LineEdit secret character width everywhere
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/line_edit.cpp20
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;