Merge pull request #29979 from flomar/master
Line edit placeholders now react properly to translation changes.
This commit is contained in:
commit
b966ee49b2
2 changed files with 24 additions and 11 deletions
|
@ -650,6 +650,11 @@ void LineEdit::_notification(int p_what) {
|
||||||
set_cursor_position(get_cursor_position());
|
set_cursor_position(get_cursor_position());
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
case NOTIFICATION_TRANSLATION_CHANGED: {
|
||||||
|
placeholder_translated = tr(placeholder);
|
||||||
|
update_placeholder_width();
|
||||||
|
update();
|
||||||
|
} break;
|
||||||
case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
|
case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
|
||||||
window_has_focus = true;
|
window_has_focus = true;
|
||||||
draw_caret = true;
|
draw_caret = true;
|
||||||
|
@ -728,7 +733,7 @@ void LineEdit::_notification(int p_what) {
|
||||||
Color font_color_selected = get_color("font_color_selected");
|
Color font_color_selected = get_color("font_color_selected");
|
||||||
Color cursor_color = get_color("cursor_color");
|
Color cursor_color = get_color("cursor_color");
|
||||||
|
|
||||||
const String &t = using_placeholder ? placeholder : text;
|
const String &t = using_placeholder ? placeholder_translated : text;
|
||||||
// draw placeholder color
|
// draw placeholder color
|
||||||
if (using_placeholder)
|
if (using_placeholder)
|
||||||
font_color.a *= placeholder_alpha;
|
font_color.a *= placeholder_alpha;
|
||||||
|
@ -1148,16 +1153,9 @@ String LineEdit::get_text() const {
|
||||||
|
|
||||||
void LineEdit::set_placeholder(String p_text) {
|
void LineEdit::set_placeholder(String p_text) {
|
||||||
|
|
||||||
placeholder = tr(p_text);
|
placeholder = p_text;
|
||||||
if ((max_length <= 0) || (placeholder.length() <= max_length)) {
|
placeholder_translated = tr(placeholder);
|
||||||
Ref<Font> font = get_font("font");
|
update_placeholder_width();
|
||||||
cached_placeholder_width = 0;
|
|
||||||
if (font != NULL) {
|
|
||||||
for (int i = 0; i < placeholder.length(); i++) {
|
|
||||||
cached_placeholder_width += font->get_char_size(placeholder[i]).width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1546,6 +1544,18 @@ void LineEdit::_emit_text_change() {
|
||||||
text_changed_dirty = false;
|
text_changed_dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LineEdit::update_placeholder_width() {
|
||||||
|
if ((max_length <= 0) || (placeholder_translated.length() <= max_length)) {
|
||||||
|
Ref<Font> font = get_font("font");
|
||||||
|
cached_placeholder_width = 0;
|
||||||
|
if (font != NULL) {
|
||||||
|
for (int i = 0; i < placeholder_translated.length(); i++) {
|
||||||
|
cached_placeholder_width += font->get_char_size(placeholder_translated[i]).width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LineEdit::_clear_redo() {
|
void LineEdit::_clear_redo() {
|
||||||
_create_undo_state();
|
_create_undo_state();
|
||||||
if (undo_stack_pos == NULL) {
|
if (undo_stack_pos == NULL) {
|
||||||
|
|
|
@ -72,6 +72,7 @@ private:
|
||||||
String undo_text;
|
String undo_text;
|
||||||
String text;
|
String text;
|
||||||
String placeholder;
|
String placeholder;
|
||||||
|
String placeholder_translated;
|
||||||
String secret_character;
|
String secret_character;
|
||||||
float placeholder_alpha;
|
float placeholder_alpha;
|
||||||
String ime_text;
|
String ime_text;
|
||||||
|
@ -126,6 +127,8 @@ private:
|
||||||
void _emit_text_change();
|
void _emit_text_change();
|
||||||
bool expand_to_text_length;
|
bool expand_to_text_length;
|
||||||
|
|
||||||
|
void update_placeholder_width();
|
||||||
|
|
||||||
bool caret_blink_enabled;
|
bool caret_blink_enabled;
|
||||||
bool draw_caret;
|
bool draw_caret;
|
||||||
bool window_has_focus;
|
bool window_has_focus;
|
||||||
|
|
Loading…
Reference in a new issue