From 1cd1df5dc3f7977a78bad20d2cecd79874e4dae3 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Sun, 30 Jan 2022 17:56:23 +0000 Subject: [PATCH] Move placeholder color to theme item --- doc/classes/CodeEdit.xml | 3 +++ doc/classes/LineEdit.xml | 6 +++--- doc/classes/TextEdit.xml | 6 +++--- editor/editor_themes.cpp | 3 +++ editor/script_create_dialog.cpp | 8 ++++++-- scene/gui/line_edit.cpp | 17 ++--------------- scene/gui/line_edit.h | 4 ---- scene/gui/text_edit.cpp | 16 ++-------------- scene/gui/text_edit.h | 6 +----- scene/resources/default_theme/default_theme.cpp | 4 ++++ 10 files changed, 27 insertions(+), 46 deletions(-) diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index b3add6cfa26..09696d4d2a3 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -607,6 +607,9 @@ The tint of text outline of the [CodeEdit]. + + Font color for [member TextEdit.placeholder_text]. + Sets the font [Color] when [member TextEdit.editable] is disabled. diff --git a/doc/classes/LineEdit.xml b/doc/classes/LineEdit.xml index 224579e8c54..0b97865770e 100644 --- a/doc/classes/LineEdit.xml +++ b/doc/classes/LineEdit.xml @@ -233,9 +233,6 @@ [b]Note:[/b] This method is only implemented on Linux. - - Opacity of the [member placeholder_text]. From [code]0[/code] to [code]1[/code]. - Text shown when the [LineEdit] is empty. It is [b]not[/b] the [LineEdit]'s default value (see [member text]). @@ -397,6 +394,9 @@ The tint of text outline of the [LineEdit]. + + Font color for [member placeholder_text]. + Font color for selected text (inside the selection rectangle). diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 6d602d58eeb..6b9eb6efc37 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -992,9 +992,6 @@ If [code]true[/code], custom [code]font_selected_color[/code] will be used for selected text. - - Opacity of the [member placeholder_text]. From [code]0[/code] to [code]1[/code]. - Text shown when the [TextEdit] is empty. It is [b]not[/b] the [TextEdit]'s default value (see [member text]). @@ -1237,6 +1234,9 @@ The tint of text outline of the [TextEdit]. + + Font color for [member placeholder_text]. + Sets the font [Color] when [member editable] is disabled. diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 238df4a8aa7..1c927db4beb 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -427,6 +427,7 @@ Ref create_editor_theme(const Ref p_theme) { const Color font_focus_color = mono_color.lerp(base_color, 0.125); const Color font_disabled_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.3); const Color font_readonly_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.65); + const Color font_placeholder_color = Color(mono_color.r, mono_color.g, mono_color.b, 0.6); const Color selection_color = accent_color * Color(1, 1, 1, 0.4); const Color disabled_color = mono_color.inverted().lerp(base_color, 0.7); const Color disabled_bg_color = mono_color.inverted().lerp(base_color, 0.9); @@ -1109,6 +1110,7 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_color("font_color", "LineEdit", font_color); theme->set_color("font_selected_color", "LineEdit", mono_color); theme->set_color("font_uneditable_color", "LineEdit", font_readonly_color); + theme->set_color("font_placeholder_color", "LineEdit", font_placeholder_color); theme->set_color("caret_color", "LineEdit", font_color); theme->set_color("selection_color", "LineEdit", selection_color); theme->set_color("clear_button_color", "LineEdit", font_color); @@ -1123,6 +1125,7 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_icon("space", "TextEdit", theme->get_icon("GuiSpace", "EditorIcons")); theme->set_color("font_color", "TextEdit", font_color); theme->set_color("font_readonly_color", "TextEdit", font_readonly_color); + theme->set_color("font_placeholder_color", "TextEdit", font_placeholder_color); theme->set_color("caret_color", "TextEdit", font_color); theme->set_color("selection_color", "TextEdit", selection_color); theme->set_constant("line_spacing", "TextEdit", 4 * EDSCALE); diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index 2098fa2c859..360ba5780c5 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -656,14 +656,18 @@ void ScriptCreateDialog::_update_dialog() { if (is_new_script_created) { class_name->set_editable(true); class_name->set_placeholder(TTR("Allowed: a-z, A-Z, 0-9, _ and .")); - class_name->set_placeholder_alpha(0.3); + Color placeholder_color = class_name->get_theme_color("font_placeholder_color"); + placeholder_color.a = 0.3; + class_name->add_theme_color_override("font_placeholder_color", placeholder_color); } else { class_name->set_editable(false); } } else { class_name->set_editable(false); class_name->set_placeholder(TTR("N/A")); - class_name->set_placeholder_alpha(1); + Color placeholder_color = class_name->get_theme_color("font_placeholder_color"); + placeholder_color.a = 1; + class_name->add_theme_color_override("font_placeholder_color", placeholder_color); class_name->set_text(""); } diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 88953fa7dbb..3aae3377bc3 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -752,7 +752,7 @@ void LineEdit::_notification(int p_what) { // Draw placeholder color. if (using_placeholder) { - font_color.a *= placeholder_alpha; + font_color = get_theme_color(SNAME("font_placeholder_color")); } bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; @@ -1476,15 +1476,6 @@ String LineEdit::get_placeholder() const { return placeholder; } -void LineEdit::set_placeholder_alpha(float p_alpha) { - placeholder_alpha = p_alpha; - update(); -} - -float LineEdit::get_placeholder_alpha() const { - return placeholder_alpha; -} - void LineEdit::set_caret_column(int p_column) { if (p_column > (int)text.length()) { p_column = text.length(); @@ -2245,8 +2236,6 @@ void LineEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override_options"), &LineEdit::get_structured_text_bidi_override_options); ClassDB::bind_method(D_METHOD("set_placeholder", "text"), &LineEdit::set_placeholder); ClassDB::bind_method(D_METHOD("get_placeholder"), &LineEdit::get_placeholder); - ClassDB::bind_method(D_METHOD("set_placeholder_alpha", "alpha"), &LineEdit::set_placeholder_alpha); - ClassDB::bind_method(D_METHOD("get_placeholder_alpha"), &LineEdit::get_placeholder_alpha); ClassDB::bind_method(D_METHOD("set_caret_column", "position"), &LineEdit::set_caret_column); ClassDB::bind_method(D_METHOD("get_caret_column"), &LineEdit::get_caret_column); ClassDB::bind_method(D_METHOD("get_scroll_offset"), &LineEdit::get_scroll_offset); @@ -2328,6 +2317,7 @@ void LineEdit::_bind_methods() { BIND_ENUM_CONSTANT(MENU_MAX); ADD_PROPERTY(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "placeholder_text"), "set_placeholder", "get_placeholder"); ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_horizontal_alignment", "get_horizontal_alignment"); ADD_PROPERTY(PropertyInfo(Variant::INT, "max_length", PROPERTY_HINT_RANGE, "0,1000,1,or_greater"), "set_max_length", "get_max_length"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable"); @@ -2349,9 +2339,6 @@ void LineEdit::_bind_methods() { ADD_GROUP("Structured Text", "structured_text_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "structured_text_bidi_override", PROPERTY_HINT_ENUM, "Default,URI,File,Email,List,None,Custom"), "set_structured_text_bidi_override", "get_structured_text_bidi_override"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "structured_text_bidi_override_options"), "set_structured_text_bidi_override_options", "get_structured_text_bidi_override_options"); - ADD_GROUP("Placeholder", "placeholder_"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "placeholder_text"), "set_placeholder", "get_placeholder"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "placeholder_alpha", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_placeholder_alpha", "get_placeholder_alpha"); ADD_GROUP("Caret", "caret_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "set_caret_blink_enabled", "is_caret_blink_enabled"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "set_caret_blink_speed", "get_caret_blink_speed"); diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 0c313f71c27..1519c09d736 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -82,7 +82,6 @@ private: String placeholder; String placeholder_translated; String secret_character = "*"; - float placeholder_alpha = 0.6; String ime_text; Point2 ime_selection; @@ -262,9 +261,6 @@ public: void set_placeholder(String p_text); String get_placeholder() const; - void set_placeholder_alpha(float p_alpha); - float get_placeholder_alpha() const; - void set_caret_column(int p_column); int get_caret_column() const; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 7db1fae2b6f..e060d3b9017 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -874,7 +874,7 @@ void TextEdit::_notification(int p_what) { // Ensure we at least use the font color. Color current_color = !editable ? font_readonly_color : font_color; if (draw_placeholder) { - current_color.a *= placeholder_alpha; + current_color = font_placeholder_color; } const Ref ldata = draw_placeholder ? placeholder_data_buf : text.get_line_data(line); @@ -2515,6 +2515,7 @@ void TextEdit::_update_caches() { font_size = get_theme_font_size(SNAME("font_size")); font_color = get_theme_color(SNAME("font_color")); font_readonly_color = get_theme_color(SNAME("font_readonly_color")); + font_placeholder_color = get_theme_color(SNAME("font_placeholder_color")); outline_size = get_theme_constant(SNAME("outline_size")); outline_color = get_theme_color(SNAME("font_outline_color")); @@ -2947,15 +2948,6 @@ String TextEdit::get_placeholder() const { return placeholder_text; } -void TextEdit::set_placeholder_alpha(float p_alpha) { - placeholder_alpha = p_alpha; - update(); -} - -float TextEdit::get_placeholder_alpha() const { - return placeholder_alpha; -} - void TextEdit::set_line(int p_line, const String &p_new_text) { if (p_line < 0 || p_line >= text.size()) { return; @@ -4944,9 +4936,6 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_placeholder", "text"), &TextEdit::set_placeholder); ClassDB::bind_method(D_METHOD("get_placeholder"), &TextEdit::get_placeholder); - ClassDB::bind_method(D_METHOD("set_placeholder_alpha", "alpha"), &TextEdit::set_placeholder_alpha); - ClassDB::bind_method(D_METHOD("get_placeholder_alpha"), &TextEdit::get_placeholder_alpha); - ClassDB::bind_method(D_METHOD("set_line", "line", "new_text"), &TextEdit::set_line); ClassDB::bind_method(D_METHOD("get_line", "line"), &TextEdit::get_line); @@ -5256,7 +5245,6 @@ void TextEdit::_bind_methods() { /* Inspector */ ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "placeholder_text", PROPERTY_HINT_MULTILINE_TEXT), "set_placeholder", "get_placeholder"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "placeholder_alpha", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_placeholder_alpha", "get_placeholder_alpha"); ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), "set_language", "get_language"); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index fdaa9285986..079890249eb 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -251,8 +251,6 @@ private: Point2 ime_selection; // Placeholder - float placeholder_alpha = 0.6; - String placeholder_text = ""; Array placeholder_bidi_override; Ref placeholder_data_buf; @@ -525,6 +523,7 @@ private: int font_size = 16; Color font_color = Color(1, 1, 1); Color font_readonly_color = Color(1, 1, 1); + Color font_placeholder_color = Color(1, 1, 1, 0.6); int outline_size = 0; Color outline_color = Color(1, 1, 1); @@ -684,9 +683,6 @@ public: void set_placeholder(const String &p_text); String get_placeholder() const; - void set_placeholder_alpha(float p_alpha); - float get_placeholder_alpha() const; - void set_line(int p_line, const String &p_new_text); String get_line(int p_line) const; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 12ea1683c80..be4dbfa64d5 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -113,6 +113,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, Ref &theme, const Ref &default_font, Refset_color("font_color", "LineEdit", control_font_color); theme->set_color("font_selected_color", "LineEdit", control_font_pressed_color); theme->set_color("font_uneditable_color", "LineEdit", control_font_disabled_color); + theme->set_color("font_placeholder_color", "LineEdit", control_font_placeholder_color); theme->set_color("font_outline_color", "LineEdit", Color(1, 1, 1)); theme->set_color("caret_color", "LineEdit", control_font_hover_color); theme->set_color("selection_color", "LineEdit", control_selection_color); @@ -427,6 +429,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, Refset_color("font_color", "TextEdit", control_font_color); theme->set_color("font_selected_color", "TextEdit", control_font_pressed_color); theme->set_color("font_readonly_color", "TextEdit", control_font_disabled_color); + theme->set_color("font_placeholder_color", "TextEdit", control_font_placeholder_color); theme->set_color("font_outline_color", "TextEdit", Color(1, 1, 1)); theme->set_color("selection_color", "TextEdit", control_selection_color); theme->set_color("current_line_color", "TextEdit", Color(0.25, 0.25, 0.26, 0.8)); @@ -468,6 +471,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, Refset_color("font_color", "CodeEdit", control_font_color); theme->set_color("font_selected_color", "CodeEdit", Color(0, 0, 0)); theme->set_color("font_readonly_color", "CodeEdit", Color(control_font_color.r, control_font_color.g, control_font_color.b, 0.5f)); + theme->set_color("font_placeholder_color", "CodeEdit", control_font_placeholder_color); theme->set_color("font_outline_color", "CodeEdit", Color(1, 1, 1)); theme->set_color("selection_color", "CodeEdit", control_selection_color); theme->set_color("bookmark_color", "CodeEdit", Color(0.5, 0.64, 1, 0.8));