@@ -2539,6 +2539,9 @@ void RichTextLabel::_notification(int p_what) {
25392539 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);
25402540 from_line++;
25412541 }
2542+ if (scroll_follow_visible_characters && scroll_active) {
2543+ vscroll->set_visible (follow_vc_pos > 0 );
2544+ }
25422545 if (has_focus () && get_tree ()->is_accessibility_enabled ()) {
25432546 RID ae;
25442547 if (keyboard_focus_frame && keyboard_focus_item) {
@@ -5042,6 +5045,31 @@ bool RichTextLabel::is_scroll_following() const {
50425045 return scroll_follow;
50435046}
50445047
5048+ void RichTextLabel::_update_follow_vc () {
5049+ if (!scroll_follow_visible_characters) {
5050+ return ;
5051+ }
5052+ int vc = (visible_characters < 0 ? get_total_character_count () : MIN (visible_characters, get_total_character_count ())) - 1 ;
5053+ int voff = get_character_line (vc) + 1 ;
5054+ if (voff <= get_line_count () - 1 ) {
5055+ follow_vc_pos = get_line_offset (voff) - _get_text_rect ().size .y ;
5056+ } else {
5057+ follow_vc_pos = vscroll->get_max ();
5058+ }
5059+ vscroll->scroll_to (follow_vc_pos);
5060+ }
5061+
5062+ void RichTextLabel::set_scroll_follow_visible_characters (bool p_follow) {
5063+ if (scroll_follow_visible_characters != p_follow) {
5064+ scroll_follow_visible_characters = p_follow;
5065+ _update_follow_vc ();
5066+ }
5067+ }
5068+
5069+ bool RichTextLabel::is_scroll_following_visible_characters () const {
5070+ return scroll_follow_visible_characters;
5071+ }
5072+
50455073void RichTextLabel::parse_bbcode (const String &p_bbcode) {
50465074 clear ();
50475075 append_text (p_bbcode);
@@ -7230,6 +7258,7 @@ void RichTextLabel::set_visible_ratio(float p_ratio) {
72307258 total_height = _calculate_line_vertical_offset (main->lines [i]);
72317259 }
72327260 }
7261+ _update_follow_vc ();
72337262 queue_redraw ();
72347263 }
72357264}
@@ -7424,6 +7453,9 @@ void RichTextLabel::_bind_methods() {
74247453 ClassDB::bind_method (D_METHOD (" set_scroll_active" , " active" ), &RichTextLabel::set_scroll_active);
74257454 ClassDB::bind_method (D_METHOD (" is_scroll_active" ), &RichTextLabel::is_scroll_active);
74267455
7456+ ClassDB::bind_method (D_METHOD (" set_scroll_follow_visible_characters" , " follow" ), &RichTextLabel::set_scroll_follow_visible_characters);
7457+ ClassDB::bind_method (D_METHOD (" is_scroll_following_visible_characters" ), &RichTextLabel::is_scroll_following_visible_characters);
7458+
74277459 ClassDB::bind_method (D_METHOD (" set_scroll_follow" , " follow" ), &RichTextLabel::set_scroll_follow);
74287460 ClassDB::bind_method (D_METHOD (" is_scroll_following" ), &RichTextLabel::is_scroll_following);
74297461
@@ -7530,6 +7562,7 @@ void RichTextLabel::_bind_methods() {
75307562 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " fit_content" ), " set_fit_content" , " is_fit_content_enabled" );
75317563 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " scroll_active" ), " set_scroll_active" , " is_scroll_active" );
75327564 ADD_PROPERTY (PropertyInfo (Variant::BOOL, " scroll_following" ), " set_scroll_follow" , " is_scroll_following" );
7565+ ADD_PROPERTY (PropertyInfo (Variant::BOOL, " scroll_following_visible_characters" ), " set_scroll_follow_visible_characters" , " is_scroll_following_visible_characters" );
75337566 ADD_PROPERTY (PropertyInfo (Variant::INT, " autowrap_mode" , PROPERTY_HINT_ENUM, " Off,Arbitrary,Word,Word (Smart)" ), " set_autowrap_mode" , " get_autowrap_mode" );
75347567 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" );
75357568 ADD_PROPERTY (PropertyInfo (Variant::INT, " tab_size" , PROPERTY_HINT_RANGE, " 0,24,1" ), " set_tab_size" , " get_tab_size" );
@@ -7711,6 +7744,7 @@ void RichTextLabel::set_visible_characters(int p_visible) {
77117744 total_height = _calculate_line_vertical_offset (main->lines [i]);
77127745 }
77137746 }
7747+ _update_follow_vc ();
77147748 queue_redraw ();
77157749 }
77167750}
0 commit comments