Merge pull request #37176 from dkaste/line-edit-secret-fix-2
Use LineEdit secret character width everywhere
This commit is contained in:
commit
b587f98fcc
1 changed files with 10 additions and 10 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue