From fb88658cc8974e8d4e5c36fe18382a755c646578 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 8 Aug 2024 17:46:41 +0200 Subject: [PATCH] Draw a checkerboard behind translucent colors in CodeEdit autocompletion previews This makes translucent colors easier to interpret as such and is consistent with how they're displayed in ColorPicker. --- doc/classes/CodeEdit.xml | 3 +++ scene/gui/code_edit.cpp | 9 ++++++++- scene/gui/code_edit.h | 1 + scene/theme/default_theme.cpp | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/classes/CodeEdit.xml b/doc/classes/CodeEdit.xml index d455799c2981..136b8e5fc5d8 100644 --- a/doc/classes/CodeEdit.xml +++ b/doc/classes/CodeEdit.xml @@ -721,6 +721,9 @@ Sets a custom [Texture2D] to draw in the line folding gutter when a code region can be folded. + + Background panel for the color preview box in autocompletion (visible when the color is translucent). + Icon to draw in the executing gutter for executing lines. diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 00b9a3478a90..f032df69369a 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -211,7 +211,13 @@ void CodeEdit::_notification(int p_what) { tl->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT); } else { if (code_completion_options[l].default_value.get_type() == Variant::COLOR) { - draw_rect(Rect2(Point2(code_completion_rect.position.x + code_completion_rect.size.width - icon_area_size.x, icon_area.position.y), icon_area_size), (Color)code_completion_options[l].default_value); + const Color color = code_completion_options[l].default_value; + const Rect2 rect = Rect2(Point2(code_completion_rect.position.x + code_completion_rect.size.width - icon_area_size.x, icon_area.position.y), icon_area_size); + if (color.a < 1.0) { + draw_texture_rect(theme_cache.completion_color_bg, rect, true); + } + + draw_rect(rect, color); } tl->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT); } @@ -2771,6 +2777,7 @@ void CodeEdit::_bind_methods() { BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, CodeEdit, can_fold_code_region_icon, "can_fold_code_region"); BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, CodeEdit, folded_code_region_icon, "folded_code_region"); BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CodeEdit, folded_eol_icon); + BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, CodeEdit, completion_color_bg); BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, CodeEdit, breakpoint_color); BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, CodeEdit, breakpoint_icon, "breakpoint"); diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h index 580435f65ea4..09340be0358e 100644 --- a/scene/gui/code_edit.h +++ b/scene/gui/code_edit.h @@ -245,6 +245,7 @@ private: Ref can_fold_code_region_icon; Ref folded_code_region_icon; Ref folded_eol_icon; + Ref completion_color_bg; Color breakpoint_color = Color(1, 1, 1); Ref breakpoint_icon = Ref(); diff --git a/scene/theme/default_theme.cpp b/scene/theme/default_theme.cpp index b2a3843b026e..366c1863a5a4 100644 --- a/scene/theme/default_theme.cpp +++ b/scene/theme/default_theme.cpp @@ -504,6 +504,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const theme->set_icon("can_fold_code_region", "CodeEdit", icons["region_unfolded"]); theme->set_icon("folded_code_region", "CodeEdit", icons["region_folded"]); theme->set_icon("folded_eol_icon", "CodeEdit", icons["text_edit_ellipsis"]); + theme->set_icon("completion_color_bg", "CodeEdit", icons["mini_checkerboard"]); theme->set_font(SceneStringName(font), "CodeEdit", Ref()); theme->set_font_size(SceneStringName(font_size), "CodeEdit", -1);