From 82ddbe78788c1d478348fe285d983a23076554be Mon Sep 17 00:00:00 2001 From: Robob27 Date: Sun, 12 Oct 2025 05:41:49 -0400 Subject: [PATCH] Fix scrollbar render with RTL scroll following visible --- scene/gui/rich_text_label.cpp | 13 +++++++++++-- scene/gui/rich_text_label.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index c3cf6a55fe2..e3959681624 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -2303,6 +2303,11 @@ RID RichTextLabel::get_focused_accessibility_element() const { return get_accessibility_element(); } +void RichTextLabel::_prepare_scroll_anchor() { + scroll_w = vscroll->get_combined_minimum_size().width; + vscroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -scroll_w); +} + void RichTextLabel::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ACCESSIBILITY_INVALIDATE: { @@ -2417,6 +2422,10 @@ void RichTextLabel::_notification(int p_what) { queue_redraw(); } break; + case NOTIFICATION_READY: { + _prepare_scroll_anchor(); + } break; + case NOTIFICATION_THEME_CHANGED: { _stop_thread(); main->first_invalid_font_line.store(0); // Invalidate all lines. @@ -2588,6 +2597,7 @@ void RichTextLabel::_notification(int p_what) { from_line++; } if (scroll_follow_visible_characters && scroll_active) { + scroll_visible = follow_vc_pos > 0; vscroll->set_visible(follow_vc_pos > 0); } if (has_focus() && get_tree()->is_accessibility_enabled()) { @@ -3726,9 +3736,8 @@ _FORCE_INLINE_ float RichTextLabel::_update_scroll_exceeds(float p_total_height, if (exceeds != scroll_visible) { if (exceeds) { scroll_visible = true; - scroll_w = vscroll->get_combined_minimum_size().width; + _prepare_scroll_anchor(); vscroll->show(); - vscroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -scroll_w); } else { scroll_visible = false; scroll_w = 0; diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index d6f95fefbef..71eae46eb06 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -591,6 +591,8 @@ private: void _invalidate_accessibility(); void _invalidate_current_line(ItemFrame *p_frame); + void _prepare_scroll_anchor(); + void _thread_function(void *p_userdata); void _thread_end(); void _stop_thread();