From fd968157a4b9145b245e3d749e1ee7e12ae9ae8b Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Wed, 16 Mar 2022 17:40:09 +0800 Subject: [PATCH 1/3] Revert "Fixed 0 width issue of rich text label" This reverts commit a1155b86e41f80b683783222470ae84d20415750. --- scene/gui/rich_text_label.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 240afcc277c..4d2abbfe59f 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -415,7 +415,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & cw = tab_size * font->get_char_size(' ').width; } - if (end > 0 && fw + cw + begin > p_width) { + if (end > 0 && w + cw + begin > p_width) { break; //don't allow lines longer than assigned width } @@ -443,7 +443,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & end++; } CHECK_HEIGHT(fh); - ENSURE_WIDTH(fw); + ENSURE_WIDTH(w); line_ascent = MAX(line_ascent, ascent); line_descent = MAX(line_descent, descent); From c0bd05762e0398589f78f2f0c4a5f4efdce786f0 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Wed, 16 Mar 2022 17:40:14 +0800 Subject: [PATCH 2/3] Revert "Fixed underlines and striketrough not respecting visible character" This reverts commit 8bbcc624fdd86bb6edeb51d16b238264d472647d. --- scene/gui/rich_text_label.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 4d2abbfe59f..6b80c2a6674 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -438,6 +438,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & was_separatable = separatable; just_breaked_in_middle = false; + w += cw; fw += cw; end++; @@ -579,7 +580,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & if (visible) { line_is_blank = false; - w += font->get_char_size(c[i], c[i + 1]).x; } if (c[i] == '\t') { From 72837b8ecd52e1734360a83ebb129ee477cc413a Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Wed, 16 Mar 2022 17:54:07 +0800 Subject: [PATCH 3/3] Fix RichTextLabel underlining does not respect visible character --- scene/gui/rich_text_label.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 6b80c2a6674..e4461384f5d 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -468,6 +468,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } { + float line_length = 0.0f; float ofs = 0.0f - backtrack; for (int i = 0; i < end; i++) { @@ -586,11 +587,13 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & visible = false; } + const float current_char_width = font->get_char_size(fx_char, c[i + 1]).x; if (visible) { if (selected) { - cw = font->get_char_size(fx_char, c[i + 1]).x; + cw = current_char_width; draw_rect(Rect2(p_ofs.x + pofs, p_ofs.y + y, cw, lh), selection_bg); } + line_length += current_char_width; const Color char_color = selected && override_selected_font_color ? selection_fg : fx_color; const Color shadow_color = p_font_color_shadow * Color(1, 1, 1, char_color.a); @@ -612,7 +615,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, fx_char, c[i + 1], char_color); } } else if (previously_visible && c[i] != '\t') { - backtrack += font->get_char_size(fx_char, c[i + 1]).x; + backtrack += current_char_width; } p_char_count++; @@ -636,7 +639,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & 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); + const Point2 to = from + Point2(line_length + (is_at_line_wrap ? 0 : align_spacing), 0); VS::get_singleton()->canvas_item_add_line(ci, from, to, uc, line_width); } if (strikethrough) { @@ -645,7 +648,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & 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); + const Point2 to = from + Point2(line_length + (is_at_line_wrap ? 0 : align_spacing), 0); VS::get_singleton()->canvas_item_add_line(ci, from, to, uc, line_width); } }