Give LineEdit a custom font color when un-editable

By default the LineEdit's text when editable is unchecked had some transparency hardcoded.
This change adds a custom color to LineEdit for adjusting the font when editable is off.
Addresses issue 29814
This commit is contained in:
Gwyneth Lowe 2019-06-21 18:16:38 -05:00
parent 25022a1d89
commit f07e5ac153
2 changed files with 3 additions and 5 deletions

View file

@ -675,10 +675,8 @@ void LineEdit::_notification(int p_what) {
RID ci = get_canvas_item(); RID ci = get_canvas_item();
Ref<StyleBox> style = get_stylebox("normal"); Ref<StyleBox> style = get_stylebox("normal");
float disabled_alpha = 1.0; // used to set the disabled input text color
if (!is_editable()) { if (!is_editable()) {
style = get_stylebox("read_only"); style = get_stylebox("read_only");
disabled_alpha = .5;
draw_caret = false; draw_caret = false;
} }
@ -724,7 +722,7 @@ void LineEdit::_notification(int p_what) {
int font_ascent = font->get_ascent(); int font_ascent = font->get_ascent();
Color selection_color = get_color("selection_color"); Color selection_color = get_color("selection_color");
Color font_color = get_color("font_color"); Color font_color = is_editable() ? get_color("font_color") : get_color("font_color_uneditable");
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");
@ -732,12 +730,11 @@ void LineEdit::_notification(int p_what) {
// draw placeholder color // draw placeholder color
if (using_placeholder) if (using_placeholder)
font_color.a *= placeholder_alpha; font_color.a *= placeholder_alpha;
font_color.a *= disabled_alpha;
bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled;
if (right_icon.is_valid() || display_clear_icon) { if (right_icon.is_valid() || display_clear_icon) {
Ref<Texture> r_icon = display_clear_icon ? Control::get_icon("clear") : right_icon; Ref<Texture> r_icon = display_clear_icon ? Control::get_icon("clear") : right_icon;
Color color_icon(1, 1, 1, disabled_alpha * .9); Color color_icon(1, 1, 1, !is_editable() ? .5 * .9 : .9);
if (display_clear_icon) { if (display_clear_icon) {
if (clear_button_status.press_attempt && clear_button_status.pressing_inside) { if (clear_button_status.press_attempt && clear_button_status.pressing_inside) {
color_icon = get_color("clear_button_color_pressed"); color_icon = get_color("clear_button_color_pressed");

View file

@ -398,6 +398,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_color("font_color", "LineEdit", control_font_color); theme->set_color("font_color", "LineEdit", control_font_color);
theme->set_color("font_color_selected", "LineEdit", Color(0, 0, 0)); theme->set_color("font_color_selected", "LineEdit", Color(0, 0, 0));
theme->set_color("font_color_uneditable", "LineEdit", Color(control_font_color.r, control_font_color.g, control_font_color.b, 0.5f));
theme->set_color("cursor_color", "LineEdit", control_font_color_hover); theme->set_color("cursor_color", "LineEdit", control_font_color_hover);
theme->set_color("selection_color", "LineEdit", font_color_selection); theme->set_color("selection_color", "LineEdit", font_color_selection);
theme->set_color("clear_button_color", "LineEdit", control_font_color); theme->set_color("clear_button_color", "LineEdit", control_font_color);