From 09397f10c59689b3a6a3648439d287d2ac14b6fa Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Tue, 11 Jan 2022 12:53:51 +0800 Subject: [PATCH] Fix BBCode underline prevents strikethrough from rendering --- scene/gui/rich_text_label.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index c57a65126b9..2cc2483d63f 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -374,7 +374,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & font_color_shadow = _find_color(text, p_font_color_shadow); if (_find_underline(text) || (_find_meta(text, &meta) && underline_meta)) { underline = true; - } else if (_find_strikethrough(text)) { + } + if (_find_strikethrough(text)) { strikethrough = true; } @@ -620,24 +621,27 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } } - if (underline || strikethrough) { +#ifdef TOOLS_ENABLED + const float line_width = EDSCALE; +#else + const float line_width = 1.0f; +#endif + if (underline) { Color uc = color; uc.a *= 0.5; - int line_y = y + lh; - if (underline) { - line_y -= line_descent - 2; - } else { - line_y -= (line_ascent + line_descent) / 2; - } + const int line_y = y + lh - (line_descent - 2); const Point2 from = p_ofs + Point2(align_ofs + wofs, line_y); const Point2 to = from + Point2(w + (is_at_line_wrap ? 0 : align_spacing), 0); + VS::get_singleton()->canvas_item_add_line(ci, from, to, uc, line_width); + } + if (strikethrough) { + Color uc = color; + uc.a *= 0.5; - float line_width = 1.0f; -#ifdef TOOLS_ENABLED - line_width *= EDSCALE; -#endif - + const int line_y = y + lh - (line_ascent + line_descent) / 2; + const Point2 from = p_ofs + Point2(align_ofs + wofs, line_y); + const Point2 to = from + Point2(w + (is_at_line_wrap ? 0 : align_spacing), 0); VS::get_singleton()->canvas_item_add_line(ci, from, to, uc, line_width); } }