diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-06-25 13:05:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-25 13:05:27 +0200 |
commit | 93a67dba375ef52ea4d77a5d72107330d9d23ba2 (patch) | |
tree | d4e5e3546d284f84a8774fa0a19e6184d887abfc /scene/gui | |
parent | 230eb262e239c48f20eb085424e5d45f6b785a9a (diff) | |
parent | 45f78d786a76001325bd598ec6a330117831e07f (diff) |
Merge pull request #30002 from GlaceGwyneth/master
Give LineEdit/TextEdit a custom color for font while uneditable
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/line_edit.cpp | 7 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 19 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 1 |
3 files changed, 8 insertions, 19 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index a0429fe8d1..960499c876 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -680,10 +680,8 @@ void LineEdit::_notification(int p_what) { RID ci = get_canvas_item(); Ref<StyleBox> style = get_stylebox("normal"); - float disabled_alpha = 1.0; // used to set the disabled input text color if (!is_editable()) { style = get_stylebox("read_only"); - disabled_alpha = .5; draw_caret = false; } @@ -729,7 +727,7 @@ void LineEdit::_notification(int p_what) { int font_ascent = font->get_ascent(); 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 cursor_color = get_color("cursor_color"); @@ -737,12 +735,11 @@ void LineEdit::_notification(int p_what) { // draw placeholder color if (using_placeholder) font_color.a *= placeholder_alpha; - font_color.a *= disabled_alpha; bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; if (right_icon.is_valid() || display_clear_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 (clear_button_status.press_attempt && clear_button_status.pressing_inside) { color_icon = get_color("clear_button_color_pressed"); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 4e86e4bb1e..9d457e989c 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -662,10 +662,8 @@ void TextEdit::_notification(int p_what) { int xmargin_end = size.width - cache.style_normal->get_margin(MARGIN_RIGHT); //let's do it easy for now: cache.style_normal->draw(ci, Rect2(Point2(), size)); - float readonly_alpha = 1.0; // used to set the input text color when in read-only mode if (readonly) { cache.style_readonly->draw(ci, Rect2(Point2(), size)); - readonly_alpha = .5; draw_caret = false; } if (has_focus()) @@ -675,8 +673,7 @@ void TextEdit::_notification(int p_what) { int visible_rows = get_visible_rows() + 1; - Color color = cache.font_color; - color.a *= readonly_alpha; + Color color = readonly ? cache.font_color_readonly : cache.font_color; if (syntax_coloring) { if (cache.background_color.a > 0.01) { @@ -871,10 +868,7 @@ void TextEdit::_notification(int p_what) { color_map = _get_line_syntax_highlighting(line); } // ensure we at least use the font color - Color current_color = cache.font_color; - if (readonly) { - current_color.a *= readonly_alpha; - } + Color current_color = readonly ? cache.font_color_readonly : cache.font_color; bool underlined = false; @@ -1061,10 +1055,7 @@ void TextEdit::_notification(int p_what) { if (syntax_coloring) { if (color_map.has(last_wrap_column + j)) { - current_color = color_map[last_wrap_column + j].color; - if (readonly) { - current_color.a *= readonly_alpha; - } + current_color = readonly ? cache.font_color_readonly : color_map[last_wrap_column + j].color; } color = current_color; } @@ -1252,8 +1243,7 @@ void TextEdit::_notification(int p_what) { if (cursor.column == last_wrap_column + j && cursor.line == line && cursor_wrap_index == line_wrap_index && block_caret && draw_caret && !insert_mode) { color = cache.caret_background_color; } else if (!syntax_coloring && block_caret) { - color = cache.font_color; - color.a *= readonly_alpha; + color = readonly ? cache.font_color_readonly : cache.font_color; } if (str[j] >= 32) { @@ -4555,6 +4545,7 @@ void TextEdit::_update_caches() { cache.safe_line_number_color = get_color("safe_line_number_color"); cache.font_color = get_color("font_color"); cache.font_color_selected = get_color("font_color_selected"); + cache.font_color_readonly = get_color("font_color_readonly"); cache.keyword_color = get_color("keyword_color"); cache.function_color = get_color("function_color"); cache.member_variable_color = get_color("member_variable_color"); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index c721cf992e..30956ccb23 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -185,6 +185,7 @@ private: Color safe_line_number_color; Color font_color; Color font_color_selected; + Color font_color_readonly; Color keyword_color; Color number_color; Color function_color; |