@@ -2516,6 +2516,9 @@ void RichTextLabel::_notification(int p_what) {
25162516 ofs.y += main->lines [from_line].text_buf ->get_size ().y + (main->lines [from_line].text_buf ->get_line_count () - 1 ) * (theme_cache.line_separation + vsep) + (theme_cache.paragraph_separation + vsep);
25172517 from_line++;
25182518 }
2519+ if (scroll_follow_visible_characters && scroll_active) {
2520+ vscroll->set_visible (follow_vc_pos > 0 );
2521+ }
25192522 if (has_focus () && get_tree ()->is_accessibility_enabled ()) {
25202523 RID ae;
25212524 if (keyboard_focus_frame && keyboard_focus_item) {
@@ -5019,6 +5022,31 @@ bool RichTextLabel::is_scroll_following() const {
50195022 return scroll_follow;
50205023}
50215024
5025+ void RichTextLabel::_update_follow_vc () {
5026+ if (!scroll_follow_visible_characters) {
5027+ return ;
5028+ }
5029+ int vc = (visible_characters < 0 ? get_total_character_count () : MIN (visible_characters, get_total_character_count ())) - 1 ;
5030+ int voff = get_character_line (vc) + 1 ;
5031+ if (voff <= get_line_count () - 1 ) {
5032+ follow_vc_pos = get_line_offset (voff) - _get_text_rect ().size .y ;
5033+ } else {
5034+ follow_vc_pos = vscroll->get_max ();
5035+ }
5036+ vscroll->scroll_to (follow_vc_pos);
5037+ }
5038+
5039+ void RichTextLabel::set_scroll_follow_visible_characters (bool p_follow) {
5040+ if (scroll_follow_visible_characters != p_follow) {
5041+ scroll_follow_visible_characters = p_follow;
5042+ _update_follow_vc ();
5043+ }
5044+ }
5045+
5046+ bool RichTextLabel::is_scroll_following_visible_characters () const {
5047+ return scroll_follow_visible_characters;
5048+ }
5049+
50225050void RichTextLabel::parse_bbcode (const String &p_bbcode) {
50235051 clear ();
50245052 append_text (p_bbcode);
@@ -7207,6 +7235,7 @@ void RichTextLabel::set_visible_ratio(float p_ratio) {
72077235 total_height = _calculate_line_vertical_offset (main->lines [i]);
72087236 }
72097237 }
7238+ _update_follow_vc ();
72107239 queue_redraw ();
72117240 }
72127241}
@@ -7397,6 +7426,9 @@ void RichTextLabel::_bind_methods() {
73977426 ClassDB::bind_method (D_METHOD (" set_scroll_active" , " active" ), &RichTextLabel::set_scroll_active);
73987427 ClassDB::bind_method (D_METHOD (" is_scroll_active" ), &RichTextLabel::is_scroll_active);
73997428
7429+ ClassDB::bind_method (D_METHOD (" set_scroll_follow_visible_characters" , " follow" ), &RichTextLabel::set_scroll_follow_visible_characters);
7430+ ClassDB::bind_method (D_METHOD (" is_scroll_following_visible_characters" ), &RichTextLabel::is_scroll_following_visible_characters);
7431+
74007432 ClassDB::bind_method (D_METHOD (" set_scroll_follow" , " follow" ), &RichTextLabel::set_scroll_follow);
74017433 ClassDB::bind_method (D_METHOD (" is_scroll_following" ), &RichTextLabel::is_scroll_following);
74027434
@@ -7501,6 +7533,7 @@ void RichTextLabel::_bind_methods() {
75017533 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " fit_content" ), " set_fit_content" , " is_fit_content_enabled" );
75027534 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " scroll_active" ), " set_scroll_active" , " is_scroll_active" );
75037535 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " scroll_following" ), " set_scroll_follow" , " is_scroll_following" );
7536+ ADD_PROPERTY (PropertyInfo (Variant::BOOL, " scroll_following_visible_characters" ), " set_scroll_follow_visible_characters" , " is_scroll_following_visible_characters" );
75047537 ADD_PROPERTY (PropertyInfo (Variant::INT, " autowrap_mode" , PROPERTY_HINT_ENUM, " Off,Arbitrary,Word,Word (Smart)" ), " set_autowrap_mode" , " get_autowrap_mode" );
75057538 ADD_PROPERTY (PropertyInfo (Variant::INT, " autowrap_trim_flags" , PROPERTY_HINT_FLAGS, vformat (" Trim Spaces After Break:%d,Trim Spaces Before Break:%d" , TextServer::BREAK_TRIM_START_EDGE_SPACES, TextServer::BREAK_TRIM_END_EDGE_SPACES)), " set_autowrap_trim_flags" , " get_autowrap_trim_flags" );
75067539 ADD_PROPERTY (PropertyInfo (Variant::INT, " tab_size" , PROPERTY_HINT_RANGE, " 0,24,1" ), " set_tab_size" , " get_tab_size" );
@@ -7682,6 +7715,7 @@ void RichTextLabel::set_visible_characters(int p_visible) {
76827715 total_height = _calculate_line_vertical_offset (main->lines [i]);
76837716 }
76847717 }
7718+ _update_follow_vc ();
76857719 queue_redraw ();
76867720 }
76877721}
0 commit comments