Draw_line()s that scroll with a VScrollBar / TextEdit?

Godot Version

4.3

Question

hey! i’m trying to make a TextEdit that resembles lined paper, but i can’t seem to figure out how to get draw_line()s to scroll with the TextEdit. i tried using the TextEdit’s VScrollBar’s value, but it doesn’t go by pixel it seems, so it’s not just a simple i + the value.

this is my current line generating code, in a _draw function:

for i in range(29, screen_size.y, 29):
  draw_line(Vector2(0, i), Vector2(screen_size.x, i), Color.hex(0x63AFFDFF))

how would i go about getting it to consistently scroll with the textedit?

I’m missing some context on your code. When is this code executed? When the textedit’s scroll bar moves? When the mouse wheel scroll is detected?

For scroll_vertical, the documentation says:

If there is a vertical scrollbar, this determines the current vertical scroll value in line numbers, starting at 0 for the top line.

Is it possible for you to use that? If the scroll value is in line numbers, you could do math using the line height and the amount of lines in your textedit.