Is there a way to get the number of lines being displayed in a RichTextLabel?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By keke
:warning: Old Version Published before Godot 3 was released.

Like the title says.
To avoid the XY problem:
I’m trying to create a text box that will normally follow any new stuff added, but the user can override by scrolling up/down one line at a time with the keyboard. The documentation has me pretty confused. get_v_scroll ( ) looks useful, but it returns an Object?

:bust_in_silhouette: Reply From: jelly

I’m 90% sure that get_v_scroll() returns the vertical scroll bar node itself.

What about the function scroll_to_line()?

I’m going to use that to do the actual scrolling, but to do so, I need to know the number of lines in the box - so I can do scroll_to_line(number_of_lines_in_the_box-user_offset), where the user can change user_offset with two keyboard keys. Or something like that. I could always count the lines as they are being added, but this doesn’t seem like a very elegant solution…

keke | 2017-02-12 21:18

:bust_in_silhouette: Reply From: YeOldeDM

Maybe you want to create your own system that does what you want, instead of trying to use a RichTextLabel.
Maybe, a VBoxContainer with a number of Labels (one for each line). That way you will have full control over how many lines you want to display, and what/where each of those lines are in your data structure.

I could definitely do something like that, in fact I am temporarily using a more complicated system like the one you describe. The reason I asked this question is because if there is a way to get the number of lines in the box, it would simplify my life a lot. If there is no way to do this, thats fine, I’d like someone to confirm that before I decide to stick with my current system.

keke | 2017-02-13 02:06

:bust_in_silhouette: Reply From: HardHead
get_v_scroll().value

This peace of code return what are you want, if you mean vertical position of grabber
(Sorry for my English)

Example:

if Input.is_action_pressed("Down"):
	get_v_scroll().value += 1
elif Input.is_action_pressed("Up"):
	get_v_scroll().value -= 1